#[repr(C)]pub struct Vector4 {
pub x: f32,
pub y: f32,
pub z: f32,
pub w: f32,
}
Expand description
Vector used for 4D math using floating point coordinates.
4-element structure that can be used to represent any quadruplet of numeric values.
It uses floating-point coordinates of 32-bit precision, unlike the engine’s float
type which
is always 64-bit. The engine can be compiled with the option precision=double
to use 64-bit
vectors; use the gdext library with the double-precision
feature in that case.
See Vector4i
for its integer counterpart.
Fields§
§x: f32
The vector’s X component.
y: f32
The vector’s Y component.
z: f32
The vector’s Z component.
w: f32
The vector’s W component.
Implementations§
source§impl Vector4
impl Vector4
sourcepub const fn new(x: f32, y: f32, z: f32, w: f32) -> Vector4
pub const fn new(x: f32, y: f32, z: f32, w: f32) -> Vector4
Returns a vector with the given components.
sourcepub fn abs(self) -> Vector4
pub fn abs(self) -> Vector4
Returns a new vector with all components in absolute values (i.e. positive or zero).
sourcepub fn clamp(self, min: Vector4, max: Vector4) -> Vector4
pub fn clamp(self, min: Vector4, max: Vector4) -> Vector4
Returns a new vector with all components clamped between the components of min
and max
.
§Panics
If min
> max
, min
is NaN, or max
is NaN.
sourcepub fn length_squared(self) -> f32
pub fn length_squared(self) -> f32
Squared length (squared magnitude) of this vector.
Runs faster than Self::length
, so prefer it if you need to compare vectors or need the
squared distance for some formula.
sourcepub fn coord_min(self, other: Vector4) -> Vector4
pub fn coord_min(self, other: Vector4) -> Vector4
Returns a new vector containing the minimum of the two vectors, component-wise.
source§impl Vector4
impl Vector4
sourcepub fn ceil(self) -> Vector4
pub fn ceil(self) -> Vector4
Returns a new vector with all components rounded up (towards positive infinity).
sourcepub fn cubic_interpolate(
self,
b: Vector4,
pre_a: Vector4,
post_b: Vector4,
weight: f32,
) -> Vector4
pub fn cubic_interpolate( self, b: Vector4, pre_a: Vector4, post_b: Vector4, weight: f32, ) -> Vector4
Performs a cubic interpolation between this vector and b
using pre_a
and post_b
as handles,
and returns the result at position weight
.
weight
is on the range of 0.0 to 1.0, representing the amount of interpolation.
sourcepub fn cubic_interpolate_in_time(
self,
b: Vector4,
pre_a: Vector4,
post_b: Vector4,
weight: f32,
b_t: f32,
pre_a_t: f32,
post_b_t: f32,
) -> Vector4
pub fn cubic_interpolate_in_time( self, b: Vector4, pre_a: Vector4, post_b: Vector4, weight: f32, b_t: f32, pre_a_t: f32, post_b_t: f32, ) -> Vector4
Performs a cubic interpolation between this vector and b
using pre_a
and post_b
as handles,
and returns the result at position weight
.
weight
is on the range of 0.0 to 1.0, representing the amount of interpolation.
It can perform smoother interpolation than Self::cubic_interpolate
by the time values.
sourcepub fn direction_to(self, to: Vector4) -> Vector4
pub fn direction_to(self, to: Vector4) -> Vector4
Returns the normalized vector pointing from this vector to to
.
This is equivalent to using (b - a).normalized()
.
sourcepub fn distance_squared_to(self, to: Vector4) -> f32
pub fn distance_squared_to(self, to: Vector4) -> f32
Returns the squared distance between this vector and to
.
This method runs faster than Self::distance_to
, so prefer it if you need to compare vectors or need the squared distance for some formula.
sourcepub fn distance_to(self, to: Vector4) -> f32
pub fn distance_to(self, to: Vector4) -> f32
Returns the distance between this vector and to
.
sourcepub fn floor(self) -> Vector4
pub fn floor(self) -> Vector4
Returns a new vector with all components rounded down (towards negative infinity).
sourcepub fn is_normalized(self) -> bool
pub fn is_normalized(self) -> bool
Returns true
if the vector is normalized, i.e. its length is approximately equal to 1.
sourcepub fn is_zero_approx(self) -> bool
pub fn is_zero_approx(self) -> bool
Returns true
if this vector’s values are approximately zero.
This method is faster than using approx_eq()
with one value as a zero vector.
sourcepub fn lerp(self, other: Vector4, weight: f32) -> Vector4
pub fn lerp(self, other: Vector4, weight: f32) -> Vector4
Returns the result of the linear interpolation between this vector and to
by amount weight
.
weight
is on the range of 0.0
to 1.0
, representing the amount of interpolation.
sourcepub fn normalized(self) -> Vector4
pub fn normalized(self) -> Vector4
Returns the vector scaled to unit length. Equivalent to self / self.length()
. See
also is_normalized()
.
§Panics
If called on a zero vector.
sourcepub fn posmod(self, pmod: f32) -> Vector4
pub fn posmod(self, pmod: f32) -> Vector4
Returns a vector composed of the FloatExt::fposmod
of this vector’s components and pmod
.
sourcepub fn posmodv(self, modv: Vector4) -> Vector4
pub fn posmodv(self, modv: Vector4) -> Vector4
Returns a vector composed of the FloatExt::fposmod
of this vector’s components and modv
’s components.
source§impl Vector4
impl Vector4
sourcepub fn max_axis(self) -> Option<Vector4Axis>
pub fn max_axis(self) -> Option<Vector4Axis>
Returns the axis of the vector’s highest value. See Vector4Axis
enum. If all components are equal, this method returns None
.
To mimic Godot’s behavior, unwrap this function’s result with unwrap_or(Vector4Axis::X)
.
sourcepub fn min_axis(self) -> Option<Vector4Axis>
pub fn min_axis(self) -> Option<Vector4Axis>
Returns the axis of the vector’s lowest value. See Vector4Axis
enum. If all components are equal, this method returns None
.
To mimic Godot’s behavior, unwrap this function’s result with unwrap_or(Vector4Axis::W)
.
Trait Implementations§
source§impl AddAssign for Vector4
impl AddAssign for Vector4
source§fn add_assign(&mut self, rhs: Vector4)
fn add_assign(&mut self, rhs: Vector4)
+=
operation. Read moresource§impl DivAssign<f32> for Vector4
impl DivAssign<f32> for Vector4
source§fn div_assign(&mut self, rhs: f32)
fn div_assign(&mut self, rhs: f32)
/=
operation. Read moresource§impl DivAssign for Vector4
impl DivAssign for Vector4
source§fn div_assign(&mut self, rhs: Vector4)
fn div_assign(&mut self, rhs: Vector4)
/=
operation. Read moresource§impl Export for Vector4
impl Export for Vector4
source§fn default_export_info() -> PropertyHintInfo
fn default_export_info() -> PropertyHintInfo
source§impl FromGodot for Vector4
impl FromGodot for Vector4
source§fn try_from_godot(
via: <Vector4 as GodotConvert>::Via,
) -> Result<Vector4, ConvertError>
fn try_from_godot( via: <Vector4 as GodotConvert>::Via, ) -> Result<Vector4, ConvertError>
Err
on failure.source§fn from_godot(via: Self::Via) -> Self
fn from_godot(via: Self::Via) -> Self
source§fn try_from_variant(variant: &Variant) -> Result<Self, ConvertError>
fn try_from_variant(variant: &Variant) -> Result<Self, ConvertError>
Variant
, returning Err
on failure.source§impl GodotConvert for Vector4
impl GodotConvert for Vector4
source§impl Index<Vector4Axis> for Vector4
impl Index<Vector4Axis> for Vector4
source§impl IndexMut<Vector4Axis> for Vector4
impl IndexMut<Vector4Axis> for Vector4
source§impl Mul<Vector4> for Projection
impl Mul<Vector4> for Projection
source§impl MulAssign<f32> for Vector4
impl MulAssign<f32> for Vector4
source§fn mul_assign(&mut self, rhs: f32)
fn mul_assign(&mut self, rhs: f32)
*=
operation. Read moresource§impl MulAssign for Vector4
impl MulAssign for Vector4
source§fn mul_assign(&mut self, rhs: Vector4)
fn mul_assign(&mut self, rhs: Vector4)
*=
operation. Read moresource§impl PartialEq for Vector4
impl PartialEq for Vector4
source§impl SubAssign for Vector4
impl SubAssign for Vector4
source§fn sub_assign(&mut self, rhs: Vector4)
fn sub_assign(&mut self, rhs: Vector4)
-=
operation. Read moresource§impl ToGodot for Vector4
impl ToGodot for Vector4
source§fn to_godot(&self) -> <Vector4 as GodotConvert>::Via
fn to_godot(&self) -> <Vector4 as GodotConvert>::Via
source§fn into_godot(self) -> <Vector4 as GodotConvert>::Via
fn into_godot(self) -> <Vector4 as GodotConvert>::Via
source§fn to_variant(&self) -> Variant
fn to_variant(&self) -> Variant
source§impl TypeStringHint for Vector4
impl TypeStringHint for Vector4
source§fn type_string() -> String
fn type_string() -> String
source§impl Var for Vector4
impl Var for Vector4
fn get_property(&self) -> <Vector4 as GodotConvert>::Via
fn set_property(&mut self, value: <Vector4 as GodotConvert>::Via)
fn property_hint() -> PropertyHintInfo
impl ArrayElement for Vector4
impl Copy for Vector4
impl GodotType for Vector4
impl StructuralPartialEq for Vector4
Auto Trait Implementations§
impl Freeze for Vector4
impl RefUnwindSafe for Vector4
impl Send for Vector4
impl Sync for Vector4
impl Unpin for Vector4
impl UnwindSafe for Vector4
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> CloneToUninit for Twhere
T: Copy,
impl<T> CloneToUninit for Twhere
T: Copy,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)