trajectory/ballistics/calculators/BCResult: Make into a record class
This commit is contained in:
parent
800940c2d7
commit
138dfc5d7f
|
|
@ -2,19 +2,15 @@ package org.fairportrobotics.frc.robolib.trajectory.ballistics.calculators;
|
|||
|
||||
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)
|
||||
public final BCEvalParams evalParams; /// The BCEvalParams instance that produced the best penalty
|
||||
|
||||
|
||||
public BCResult(
|
||||
Double penalty,
|
||||
BCEvalParams evalParams
|
||||
) {
|
||||
this.penalty = penalty;
|
||||
this.evalParams = evalParams;
|
||||
}
|
||||
/**
|
||||
* Record type for ballistic calculator results
|
||||
*/
|
||||
public record BCResult(Double penalty, BCEvalParams 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() {
|
||||
return this.penalty != null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ public class HillDescentBallisticCalculator extends BallisticCalculator {
|
|||
if(model.paramComputed(param)) continue;
|
||||
|
||||
BCResult result = this.evalSingleCandidate(model, param, robotVelocity, robotAngle, shooterVelocity);
|
||||
if(result.penalty < bestResult.penalty) {
|
||||
if(result.isValid() && result.penalty() < bestResult.penalty()) {
|
||||
bestParam = param;
|
||||
bestResult = result;
|
||||
foundImprovement = true;
|
||||
|
|
|
|||
Loading…
Reference in New Issue