aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/animation/mod.rs14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/animation/mod.rs b/src/animation/mod.rs
index efdc8955..7ab0c585 100644
--- a/src/animation/mod.rs
+++ b/src/animation/mod.rs
@@ -294,7 +294,19 @@ impl Animation {
let x = (passed / total).clamp(0., 1.);
curve.y(x) * (self.to - self.from) + self.from
}
- Kind::Spring(spring) => spring.value_at(passed),
+ Kind::Spring(spring) => {
+ let value = spring.value_at(passed);
+
+ // Protect against numerical instability.
+ let range = (self.to - self.from) * 10.;
+ let a = self.from - range;
+ let b = self.to + range;
+ if self.from <= self.to {
+ value.clamp(a, b)
+ } else {
+ value.clamp(b, a)
+ }
+ }
Kind::Deceleration {
initial_velocity,
deceleration_rate,