rosu_pp/util/
float_ext.rs1pub trait FloatExt: Sized {
2 const EPS: Self;
3
4 fn eq(self, other: Self) -> bool {
6 self.almost_eq(other, Self::EPS)
7 }
8
9 fn almost_eq(self, other: Self, acceptable_difference: Self) -> bool;
11
12 fn not_eq(self, other: Self) -> bool;
14
15 fn lerp(value1: Self, value2: Self, amount: Self) -> Self;
17}
18
19macro_rules! impl_float_ext {
20 ( $ty:ty ) => {
21 impl FloatExt for $ty {
22 const EPS: Self = <$ty>::EPSILON;
23
24 fn almost_eq(self, other: Self, acceptable_difference: Self) -> bool {
25 (self - other).abs() <= acceptable_difference
26 }
27
28 fn not_eq(self, other: Self) -> bool {
29 (self - other).abs() >= Self::EPS
30 }
31
32 fn lerp(value1: Self, value2: Self, amount: Self) -> Self {
34 (value1 * (1.0 - amount)) + (value2 * amount)
35 }
36 }
37 };
38}
39
40impl_float_ext!(f32);
41impl_float_ext!(f64);