Trait FloatExt

Source
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;
}
Expand description

Trait that provides Godot math functions as extensions on f32 and f64.

Required Associated Constants§

Source

const CMP_EPSILON: Self

Required Methods§

Source

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.

Source

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.

Source

fn is_zero_approx(self) -> bool

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

Source

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

Returns the floating-point modulus of self divided by pmod, wrapping equally in positive and negative.

Source

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

Returns the multiple of step that is closest to self.

Source

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).

Source

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.

Source

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.

Source

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.

Source

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.

Source

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()

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl FloatExt for f32

Source§

const CMP_EPSILON: Self = 9.99999974E-6f32

Source§

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

Source§

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

Source§

fn is_zero_approx(self) -> bool

Source§

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

Source§

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

Source§

fn sign(self) -> Self

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

impl FloatExt for f64

Source§

const CMP_EPSILON: Self = 1.0000000000000001E-5f64

Source§

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

Source§

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

Source§

fn is_zero_approx(self) -> bool

Source§

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

Source§

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

Source§

fn sign(self) -> Self

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Implementors§