pub trait FloatExt {
// Required methods
fn lerp(self, rhs: Self, s: Self) -> Self;
fn inverse_lerp(a: Self, b: Self, v: Self) -> Self;
fn smoothstep(self, edge0: Self, edge1: Self) -> Self;
fn remap(
self,
in_start: Self,
in_end: Self,
out_start: Self,
out_end: Self,
) -> Self;
fn fract_gl(self) -> Self;
fn step(self, value: Self) -> Self;
fn saturate(self) -> Self;
fn move_towards(self, rhs: Self, d: Self) -> Self;
}Required Methods§
Sourcefn lerp(self, rhs: Self, s: Self) -> Self
fn lerp(self, rhs: Self, s: Self) -> Self
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. The float vector types provide a monotonic
lerp_monotonic method for interpolating between values that may be equal or nearly equal.
Sourcefn inverse_lerp(a: Self, b: Self, v: Self) -> Self
fn inverse_lerp(a: Self, b: Self, v: 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.
Sourcefn smoothstep(self, edge0: Self, edge1: Self) -> Self
fn smoothstep(self, edge0: Self, edge1: 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.
Sourcefn remap(
self,
in_start: Self,
in_end: Self,
out_start: Self,
out_end: Self,
) -> Self
fn remap( self, in_start: Self, in_end: Self, out_start: Self, out_end: 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.
Sourcefn fract_gl(self) -> Self
fn fract_gl(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.
Sourcefn step(self, value: Self) -> Self
fn step(self, value: 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)
Sourcefn move_towards(self, rhs: Self, d: Self) -> Self
fn move_towards(self, rhs: Self, d: 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.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".