mirror of
https://github.com/danbulant/cushy
synced 2026-07-06 11:40:37 +00:00
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:
parent
e70e92726c
commit
276ba97bf7
1 changed files with 4 additions and 1 deletions
|
|
@ -1153,7 +1153,7 @@ impl ZeroToOne {
|
||||||
assert!(!rhs.is_nan());
|
assert!(!rhs.is_nan());
|
||||||
}
|
}
|
||||||
if rhs > 0. {
|
if rhs > 0. {
|
||||||
self.0 /= rhs;
|
self.0 = (self.0 / rhs).clamp(0., 1.);
|
||||||
} else if *self > 0. {
|
} else if *self > 0. {
|
||||||
// The limit of f(x) -> x/0 is infinity, but the highest value we
|
// The limit of f(x) -> x/0 is infinity, but the highest value we
|
||||||
// can represent is 1.0.
|
// 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::new(0.5) / ZeroToOne::ZERO, ZeroToOne::ONE);
|
||||||
assert_eq!(ZeroToOne::ZERO / 0., ZeroToOne::ZERO);
|
assert_eq!(ZeroToOne::ZERO / 0., ZeroToOne::ZERO);
|
||||||
assert_eq!(ZeroToOne::new(0.5) / 0., ZeroToOne::ONE);
|
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.
|
/// An easing function for customizing animations.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue