Trait 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
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
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
fn is_zero_approx(self) -> bool
Check if self
is within Self::CMP_EPSILON
of 0.0
.
fn fposmod(self, pmod: Self) -> Self
fn fposmod(self, pmod: Self) -> Self
Returns the floating-point modulus of self
divided by pmod
, wrapping equally in positive and negative.
fn snapped(self, step: Self) -> Self
fn snapped(self, step: Self) -> Self
Returns the multiple of step
that is closest to self
.
fn sign(self) -> 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
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
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
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
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
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.