aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/animation/spring.rs19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/animation/spring.rs b/src/animation/spring.rs
index f7bcb1e4..499ec891 100644
--- a/src/animation/spring.rs
+++ b/src/animation/spring.rs
@@ -94,6 +94,12 @@ impl Spring {
x1 = (self.to - y0 + m * x0) / m;
y1 = self.oscillate(x1);
+
+ // Overdamped springs have some numerical stability issues...
+ if !y1.is_finite() {
+ return Duration::from_secs_f64(x0);
+ }
+
i += 1;
}
@@ -187,4 +193,17 @@ mod tests {
let _ = spring.clamped_duration();
let _ = spring.value_at(Duration::ZERO);
}
+
+ #[test]
+ fn overdamped_spring_duration_panic() {
+ let spring = Spring {
+ from: 0.,
+ to: 1.,
+ initial_velocity: 0.,
+ params: SpringParams::new(6., 1200., 0.0001),
+ };
+ let _ = spring.duration();
+ let _ = spring.clamped_duration();
+ let _ = spring.value_at(Duration::ZERO);
+ }
}