1 /// A trait for extending [`prim@f32`] and [`prim@f64`] with extra methods. 2 pub trait FloatExt { 3 /// Performs a linear interpolation between `self` and `rhs` based on the value `t`. 4 /// 5 /// When `t` is `0`, the result will be `self`. When `t` is `1`, the result 6 /// will be `rhs`. When `t` is outside of the range `[0, 1]`, the result is linearly 7 /// extrapolated. 8 #[must_use] lerp(self, rhs: Self, s: Self) -> Self9 fn lerp(self, rhs: Self, s: Self) -> Self; 10 11 /// Returns `v` normalized to the range `[a, b]`. 12 /// 13 /// When `v` is equal to `a` the result will be `0`. When `v` is equal to `b` will be `1`. 14 /// 15 /// When `v` is outside of the range `[a, b]`, the result is linearly extrapolated. 16 /// 17 /// `a` and `b` must not be equal, otherwise the result will be either infinite or `NAN`. inverse_lerp(a: Self, b: Self, v: Self) -> Self18 fn inverse_lerp(a: Self, b: Self, v: Self) -> Self; 19 20 /// Remap `self` from the input range to the output range. 21 /// 22 /// When `self` is equal to `in_start` this returns `out_start`. 23 /// When `self` is equal to `in_end` this returns `out_end`. 24 /// 25 /// When `self` is outside of the range `[in_start, in_end]`, the result is linearly extrapolated. 26 /// 27 /// `in_start` and `in_end` must not be equal, otherwise the result will be either infinite or `NAN`. 28 #[must_use] remap(self, in_start: Self, in_end: Self, out_start: Self, out_end: Self) -> Self29 fn remap(self, in_start: Self, in_end: Self, out_start: Self, out_end: Self) -> Self; 30 } 31