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
This commit is contained in:
Jonathan Johnson 2024-01-02 09:16:21 -08:00
parent e70e92726c
commit 276ba97bf7
No known key found for this signature in database
GPG key ID: A66D6A34D6620579

View file

@ -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.