[wpimath] ExponentialProfile: Return copy of input state (#6370)

As State is mutable, this avoids accidental modification of the passed-in object by the caller modifying the return value.
This commit is contained in:
shueja
2024-02-15 16:32:51 -08:00
committed by GitHub
parent d4d0545dc1
commit 6afff99640

View File

@@ -191,7 +191,7 @@ public class ExponentialProfile {
var timing = calculateProfileTiming(current, inflectionPoint, goal, u);
if (t < 0) {
return current;
return new State(current.position, current.velocity);
} else if (t < timing.inflectionTime) {
return new State(
computeDistanceFromTime(t, u, current), computeVelocityFromTime(t, u, current));
@@ -200,7 +200,7 @@ public class ExponentialProfile {
computeDistanceFromTime(t - timing.totalTime, -u, goal),
computeVelocityFromTime(t - timing.totalTime, -u, goal));
} else {
return goal;
return new State(goal.position, goal.velocity);
}
}