From 6afff996401343c3bfcc46a40a40abda429e5077 Mon Sep 17 00:00:00 2001 From: shueja <32416547+shueja@users.noreply.github.com> Date: Thu, 15 Feb 2024 16:32:51 -0800 Subject: [PATCH] [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. --- .../edu/wpi/first/math/trajectory/ExponentialProfile.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wpimath/src/main/java/edu/wpi/first/math/trajectory/ExponentialProfile.java b/wpimath/src/main/java/edu/wpi/first/math/trajectory/ExponentialProfile.java index e2dae9322a..76b7d6e764 100644 --- a/wpimath/src/main/java/edu/wpi/first/math/trajectory/ExponentialProfile.java +++ b/wpimath/src/main/java/edu/wpi/first/math/trajectory/ExponentialProfile.java @@ -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); } }