Trait glam::FloatExt

source ·
pub trait FloatExt {
    // Required methods
    fn lerp(self, rhs: Self, s: Self) -> Self;
    fn inverse_lerp(a: Self, b: Self, v: Self) -> Self;
    fn remap(
        self,
        in_start: Self,
        in_end: Self,
        out_start: Self,
        out_end: Self
    ) -> Self;
}
Expand description

A trait for extending f32 and f64 with extra methods.

Required Methods§

source

fn lerp(self, rhs: Self, s: Self) -> Self

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.

source

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.

source

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.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl FloatExt for f32

source§

fn lerp(self, rhs: f32, t: f32) -> f32

source§

fn inverse_lerp(a: f32, b: f32, v: f32) -> f32

source§

fn remap(self, in_start: f32, in_end: f32, out_start: f32, out_end: f32) -> f32

source§

impl FloatExt for f64

source§

fn lerp(self, rhs: f64, t: f64) -> f64

source§

fn inverse_lerp(a: f64, b: f64, v: f64) -> f64

source§

fn remap(self, in_start: f64, in_end: f64, out_start: f64, out_end: f64) -> f64

Implementors§