trajectory/ballistics/calculators/BCResult: Make into a record class

This commit is contained in:
Ray Healy 2026-03-14 09:53:06 -04:00
parent 800940c2d7
commit 138dfc5d7f
2 changed files with 9 additions and 13 deletions

View File

@ -2,19 +2,15 @@ package org.fairportrobotics.frc.robolib.trajectory.ballistics.calculators;
import org.fairportrobotics.frc.robolib.trajectory.ballistics.constraints.BCEvalParams; import org.fairportrobotics.frc.robolib.trajectory.ballistics.constraints.BCEvalParams;
public class BCResult { /**
public final Double penalty; /// The penalty for the computed launcher velocity (null if invalid) * Record type for ballistic calculator results
public final BCEvalParams evalParams; /// The BCEvalParams instance that produced the best penalty */
public record BCResult(Double penalty, BCEvalParams evalParams) {
public BCResult(
Double penalty,
BCEvalParams evalParams
) {
this.penalty = penalty;
this.evalParams = evalParams;
}
/**
* Checks if the result is valid (i.e. checks if penalty != null)
* @return True if the evalParams evaluates as valid, false otherwise
*/
public boolean isValid() { public boolean isValid() {
return this.penalty != null; return this.penalty != null;
} }

View File

@ -45,7 +45,7 @@ public class HillDescentBallisticCalculator extends BallisticCalculator {
if(model.paramComputed(param)) continue; if(model.paramComputed(param)) continue;
BCResult result = this.evalSingleCandidate(model, param, robotVelocity, robotAngle, shooterVelocity); BCResult result = this.evalSingleCandidate(model, param, robotVelocity, robotAngle, shooterVelocity);
if(result.penalty < bestResult.penalty) { if(result.isValid() && result.penalty() < bestResult.penalty()) {
bestParam = param; bestParam = param;
bestResult = result; bestResult = result;
foundImprovement = true; foundImprovement = true;