aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/animation/spring.rs22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/animation/spring.rs b/src/animation/spring.rs
index 226d7cc2..f7bcb1e4 100644
--- a/src/animation/spring.rs
+++ b/src/animation/spring.rs
@@ -54,6 +54,10 @@ impl Spring {
return Duration::MAX;
}
+ if (self.to - self.from).abs() <= f64::EPSILON {
+ return Duration::ZERO;
+ }
+
let omega0 = (self.params.stiffness / self.params.mass).sqrt();
// As first ansatz for the overdamped solution,
@@ -166,3 +170,21 @@ impl Spring {
}
}
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn overdamped_spring_equal_from_to_nan() {
+ let spring = Spring {
+ from: 0.,
+ to: 0.,
+ initial_velocity: 0.,
+ params: SpringParams::new(1.15, 850., 0.0001),
+ };
+ let _ = spring.duration();
+ let _ = spring.clamped_duration();
+ let _ = spring.value_at(Duration::ZERO);
+ }
+}