Skip to content

Commit

Permalink
[wpimath] ExponentialProfile: Return copy of input state (wpilibsuite…
Browse files Browse the repository at this point in the history
…#6370)

As State is mutable, this avoids accidental modification of the passed-in object by the caller modifying the return value.
  • Loading branch information
shueja authored Feb 16, 2024
1 parent d4d0545 commit 6afff99
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public State calculate(double t, State current, State goal) {
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));
Expand All @@ -200,7 +200,7 @@ public State calculate(double t, State current, State goal) {
computeDistanceFromTime(t - timing.totalTime, -u, goal),
computeVelocityFromTime(t - timing.totalTime, -u, goal));
} else {
return goal;
return new State(goal.position, goal.velocity);
}
}

Expand Down

0 comments on commit 6afff99

Please sign in to comment.