1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/// A trait for extending [`prim@f32`] and [`prim@f64`] with extra methods.
///
/// This trait is sealed and cannot be implemented for types outside of `glam`.
pub trait FloatExt: crate::sealed::Sealed {
/// Performs a linear interpolation between `self` and `rhs` based on the value `s`, using the
/// form `self * (1.0 - s) + rhs * s`.
///
/// When `s` is `0.0`, the result will be equal to `self`. When `s` is `1.0`, the result will
/// be equal to `rhs`. When `s` is outside of the range `[0, 1]`, the result is linearly
/// extrapolated.
///
/// The result is guaranteed to be `self` at `s == 0.0` and `rhs` at `s == 1.0`, even when the
/// values differ greatly in magnitude, but it is not monotonic in `s` for nearly equal inputs
/// and may not preserve equal inputs exactly. Consider [`lerp_monotonic`](Self::lerp_monotonic)
/// instead when interpolating between values that may be equal or nearly equal.
#[must_use]
fn lerp(self, rhs: Self, s: Self) -> Self;
/// Performs a linear interpolation between `self` and `rhs` based on the value `s`, using the
/// monotonic form `self + (rhs - self) * s`.
///
/// When `s` is `0.0`, the result will be equal to `self`. When `s` is `1.0`, the result will
/// be equal to `rhs`. When `s` is outside of the range `[0, 1]`, the result is linearly
/// extrapolated.
///
/// Prefer this over [`lerp`](Self::lerp) when interpolating between values that may be equal or
/// nearly equal: the result is monotonic in `s` and equal inputs are preserved exactly, avoiding
/// the rounding jitter that [`lerp`](Self::lerp) can introduce. The tradeoff is that
/// `rhs - self` is evaluated first, so this is less accurate than [`lerp`](Self::lerp) when
/// `self` and `rhs` differ greatly in magnitude, and overflows to infinity when they have
/// opposite signs and large magnitudes.
#[must_use]
fn lerp_monotonic(self, rhs: Self, s: Self) -> Self;
/// Returns `v` normalized to the range `[a, b]`.
///
/// When `v` is equal to `a` the result will be `0`. When `v` is equal to `b` will be `1`.
///
/// When `v` is outside of the range `[a, b]`, the result is linearly extrapolated.
///
/// `a` and `b` must not be equal, otherwise the result will be either infinite or `NAN`.
fn inverse_lerp(a: Self, b: Self, v: Self) -> Self;
/// Performs Hermite interpolation between `0.0` and `1.0` using `x` normalized to `[edge0, edge1]`.
///
/// This is equivalent to `t * t * (3.0 - 2.0 * t)`, where `t` is clamped to `[0.0, 1.0]`.
/// Results are undefined if `edge0` is greater than or equal to `edge1`.
#[must_use]
fn smoothstep(self, edge0: Self, edge1: Self) -> Self;
/// Remap `self` from the input range to the output range.
///
/// When `self` is equal to `in_start` this returns `out_start`.
/// When `self` is equal to `in_end` this returns `out_end`.
///
/// When `self` is outside of the range `[in_start, in_end]`, the result is linearly extrapolated.
///
/// `in_start` and `in_end` must not be equal, otherwise the result will be either infinite or `NAN`.
#[must_use]
fn remap(self, in_start: Self, in_end: Self, out_start: Self, out_end: Self) -> Self;
/// Returns the fractional part of the input as `self - self.floor()`.
///
/// Note that this differs from the Rust implementation of `fract` which returns
/// `self - self.trunc()`.
///
/// Note that this is fast but not precise for large numbers.
fn fract_gl(self) -> Self;
/// Returns `0.0` if `value < self` and 1.0 otherwise.
///
/// Similar to glsl's step(edge, x), which translates into edge.step(x)
#[must_use]
fn step(self, value: Self) -> Self;
/// Returns `self` clamped within the range `[0.0, 1.0]`
#[must_use]
fn saturate(self) -> Self;
/// Moves `self` towards `rhs` by at most the distance `d`.
///
/// When `d` is `0.0`, the result will be equal to `self`. When `d` is greater than or
/// equal to the distance between `self` and `rhs`, the result will be equal to `rhs`.
/// Will not go past `rhs`.
#[must_use]
fn move_towards(self, rhs: Self, d: Self) -> Self;
}