From 276ba97bf71500c4191b9f17229c02888b232b8a Mon Sep 17 00:00:00 2001 From: Jonathan Johnson Date: Tue, 2 Jan 2024 09:16:21 -0800 Subject: [PATCH] Actually clamping on f32 div For some reason I forgot about 1.0 being an edge case, but I also didn't think about negatives either. Applying a clamp is the right move here. Refs #120 --- src/animation.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/animation.rs b/src/animation.rs index be7e974..428e424 100644 --- a/src/animation.rs +++ b/src/animation.rs @@ -1153,7 +1153,7 @@ impl ZeroToOne { assert!(!rhs.is_nan()); } if rhs > 0. { - self.0 /= rhs; + self.0 = (self.0 / rhs).clamp(0., 1.); } else if *self > 0. { // The limit of f(x) -> x/0 is infinity, but the highest value we // can represent is 1.0. @@ -1386,6 +1386,9 @@ fn zero_to_one_div() { assert_eq!(ZeroToOne::new(0.5) / ZeroToOne::ZERO, ZeroToOne::ONE); assert_eq!(ZeroToOne::ZERO / 0., ZeroToOne::ZERO); assert_eq!(ZeroToOne::new(0.5) / 0., ZeroToOne::ONE); + + assert_eq!(ZeroToOne::ONE / 0.5, ZeroToOne::ONE); + assert_eq!(ZeroToOne::ONE / -0.5, ZeroToOne::ONE); } /// An easing function for customizing animations.