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
/// A trait for extending [`prim@f32`] and [`prim@f64`] with extra methods.
pub trait FloatExt {
/// Performs a linear interpolation between `self` and `rhs` based on the value `s`.
///
/// When `s` is `0`, the result will be `self`. When `s` is `1`, the result
/// will be `rhs`. When `s` is outside of the range `[0, 1]`, the result is linearly
/// extrapolated.
#[must_use]
fn lerp(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;
}