Trait godot::builtin::math::FloatExt

pub trait FloatExt: Sealed + Copy {
    const CMP_EPSILON: Self;

    // Required methods
    fn lerp(self, to: Self, weight: Self) -> Self;
    fn is_angle_equal_approx(self, other: Self) -> bool;
    fn is_zero_approx(self) -> bool;
    fn fposmod(self, pmod: Self) -> Self;
    fn snapped(self, step: Self) -> Self;
    fn sign(self) -> Self;
    fn bezier_derivative(
        self,
        control_1: Self,
        control_2: Self,
        end: Self,
        t: Self
    ) -> Self;
    fn bezier_interpolate(
        self,
        control_1: Self,
        control_2: Self,
        end: Self,
        t: Self
    ) -> Self;
    fn cubic_interpolate(
        self,
        to: Self,
        pre: Self,
        post: Self,
        weight: Self
    ) -> Self;
    fn cubic_interpolate_in_time(
        self,
        to: Self,
        pre: Self,
        post: Self,
        weight: Self,
        to_t: Self,
        pre_t: Self,
        post_t: Self
    ) -> Self;
    fn lerp_angle(self, to: Self, weight: Self) -> Self;
}

Required Associated Constants§

const CMP_EPSILON: Self

Required Methods§

fn lerp(self, to: Self, weight: Self) -> Self

Linearly interpolates from self to to by weight.

weight should be in the range 0.0 ..= 1.0, but values outside this are allowed and will perform linear extrapolation.

fn is_angle_equal_approx(self, other: Self) -> bool

Check if two angles are approximately equal, by comparing the distance between the points on the unit circle with 0 using real::approx_eq.

fn is_zero_approx(self) -> bool

Check if self is within Self::CMP_EPSILON of 0.0.

fn fposmod(self, pmod: Self) -> Self

fn snapped(self, step: Self) -> Self

Returns the multiple of step that is closest to self.

fn sign(self) -> Self

Godot’s sign function, returns 0.0 when self is 0.0.

See also f32::signum and f64::signum, which always return -1.0 or 1.0 (or NaN).

fn bezier_derivative( self, control_1: Self, control_2: Self, end: Self, t: Self ) -> Self

Returns the derivative at the given t on a one-dimensional Bézier curve defined by the given control_1, control_2, and end points.

fn bezier_interpolate( self, control_1: Self, control_2: Self, end: Self, t: Self ) -> Self

Returns the point at the given t on a one-dimensional Bézier curve defined by the given control_1, control_2, and end points.

fn cubic_interpolate( self, to: Self, pre: Self, post: Self, weight: Self ) -> Self

Cubic interpolates between two values by the factor defined in weight with pre and post values.

fn cubic_interpolate_in_time( self, to: Self, pre: Self, post: Self, weight: Self, to_t: Self, pre_t: Self, post_t: Self ) -> Self

Cubic interpolates between two values by the factor defined in weight with pre and post values. It can perform smoother interpolation than cubic_interpolate by the time values.

fn lerp_angle(self, to: Self, weight: Self) -> Self

Linearly interpolates between two angles (in radians) by a weight value between 0.0 and 1.0.

Similar to lerp, but interpolates correctly when the angles wrap around TAU.

The resulting angle is not normalized.

Note: This function lerps through the shortest path between from and to. However, when these two angles are approximately PI + k * TAU apart for any integer k, it’s not obvious which way they lerp due to floating-point precision errors. For example, with single-precision floats lerp_angle(0.0, PI, weight) lerps clockwise, while lerp_angle(0.0, PI + 3.0 * TAU, weight) lerps counter-clockwise.

Godot equivalent: @GlobalScope.lerp_angle()

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

§

impl FloatExt for f32

§

const CMP_EPSILON: f32 = 9.99999974E-6f32

§

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

§

fn is_angle_equal_approx(self, other: f32) -> bool

§

fn is_zero_approx(self) -> bool

§

fn fposmod(self, pmod: f32) -> f32

§

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

§

fn sign(self) -> f32

§

fn bezier_derivative( self, control_1: f32, control_2: f32, end: f32, t: f32 ) -> f32

§

fn bezier_interpolate( self, control_1: f32, control_2: f32, end: f32, t: f32 ) -> f32

§

fn cubic_interpolate(self, to: f32, pre: f32, post: f32, weight: f32) -> f32

§

fn cubic_interpolate_in_time( self, to: f32, pre: f32, post: f32, weight: f32, to_t: f32, pre_t: f32, post_t: f32 ) -> f32

§

fn lerp_angle(self, to: f32, weight: f32) -> f32

§

impl FloatExt for f64

§

const CMP_EPSILON: f64 = 1.0000000000000001E-5f64

§

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

§

fn is_angle_equal_approx(self, other: f64) -> bool

§

fn is_zero_approx(self) -> bool

§

fn fposmod(self, pmod: f64) -> f64

§

fn snapped(self, step: f64) -> f64

§

fn sign(self) -> f64

§

fn bezier_derivative( self, control_1: f64, control_2: f64, end: f64, t: f64 ) -> f64

§

fn bezier_interpolate( self, control_1: f64, control_2: f64, end: f64, t: f64 ) -> f64

§

fn cubic_interpolate(self, to: f64, pre: f64, post: f64, weight: f64) -> f64

§

fn cubic_interpolate_in_time( self, to: f64, pre: f64, post: f64, weight: f64, to_t: f64, pre_t: f64, post_t: f64 ) -> f64

§

fn lerp_angle(self, to: f64, weight: f64) -> f64

Implementors§