Skip to main content

FloatExt

Trait FloatExt 

Source
pub trait FloatExt {
    // Required methods
    fn lerp(self, other: f32, t: f32) -> f32;
    fn clamp(self, min: f32, max: f32) -> f32;
    fn map_range(
        self,
        in_min: f32,
        in_max: f32,
        out_min: f32,
        out_max: f32,
    ) -> f32;
    fn deadzone(self, deadzone: f32) -> f32;
    fn snap(self, step: f32) -> f32;
}
Expand description

Extension trait for f32 with game-oriented helpers.

Required Methods§

Source

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

Linear interpolation between self and other by t (clamped 0..1).

Source

fn clamp(self, min: f32, max: f32) -> f32

Clamp value between min and max.

Source

fn map_range(self, in_min: f32, in_max: f32, out_min: f32, out_max: f32) -> f32

Map value from in_min..=in_max to out_min..=out_max.

Source

fn deadzone(self, deadzone: f32) -> f32

Deadzone filter — returns 0.0 if within deadzone of zero.

Source

fn snap(self, step: f32) -> f32

Snap to nearest increment of step.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl FloatExt for f32

Source§

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

Source§

fn clamp(self, min: f32, max: f32) -> f32

Source§

fn map_range(self, in_min: f32, in_max: f32, out_min: f32, out_max: f32) -> f32

Source§

fn deadzone(self, deadzone: f32) -> f32

Source§

fn snap(self, step: f32) -> f32

Implementors§