aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvan Molodetskikh <yalterz@gmail.com>2024-04-18 20:42:01 +0400
committerIvan Molodetskikh <yalterz@gmail.com>2024-04-18 20:45:37 +0400
commit4d010b794305d4f94af449ef8fff7f01defd16c9 (patch)
tree75adec201c970342e252794c1f602ce3e3e9a1ec
parent65c342f2cb814df4fb6e15123c919084d5465240 (diff)
downloadniri-4d010b794305d4f94af449ef8fff7f01defd16c9.tar.gz
niri-4d010b794305d4f94af449ef8fff7f01defd16c9.tar.bz2
niri-4d010b794305d4f94af449ef8fff7f01defd16c9.zip
animation: Clamp spring value
I've had an overdamped spring return an extreme value and trip up an integer overflow check.
-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,