#[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§
§impl Vector4
impl Vector4
pub 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.
pub fn abs(self) -> Vector4
pub fn abs(self) -> Vector4
Returns a new vector with all components in absolute values (i.e. positive or zero).
pub 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.
pub 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.
pub 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.
§impl Vector4
impl Vector4
pub fn ceil(self) -> Vector4
pub fn ceil(self) -> Vector4
Returns a new vector with all components rounded up (towards positive infinity).
pub 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.
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
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.
pub fn try_direction_to(self, to: Vector4) -> Option<Vector4>
pub fn try_direction_to(self, to: Vector4) -> Option<Vector4>
Returns the normalized vector pointing from this vector to to
or None
, if self
and to
are equal.
This is equivalent to using (b - a).try_normalized()
. See also direction_to()
.
pub 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()
. See also try_direction_to()
.
§Panics
If self
and to
are equal.
pub 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.
pub fn distance_to(self, to: Vector4) -> f32
pub fn distance_to(self, to: Vector4) -> f32
Returns the distance between this vector and to
.
pub fn floor(self) -> Vector4
pub fn floor(self) -> Vector4
Returns a new vector with all components rounded down (towards negative infinity).
pub 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.
pub 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.
pub 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.
pub fn try_normalized(self) -> Option<Vector4>
pub fn try_normalized(self) -> Option<Vector4>
Returns the vector scaled to unit length or None
, if called on a zero vector.
Computes self / self.length()
. See also normalized()
and is_normalized()
.
pub fn normalized(self) -> Vector4
pub fn normalized(self) -> Vector4
⚠️ Returns the vector scaled to unit length.
Computes self / self.length()
. See also try_normalized()
and is_normalized()
.
§Panics
If called on a zero vector.
pub fn normalized_or_zero(self) -> Vector4
pub fn normalized_or_zero(self) -> Vector4
Returns the vector scaled to unit length or Self::ZERO
, if called on a zero vector.
Computes self / self.length()
. See also try_normalized()
and is_normalized()
.
pub 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
.
pub 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.
§impl Vector4
impl Vector4
pub 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)
.
pub 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§
§impl AddAssign for Vector4
impl AddAssign for Vector4
§fn add_assign(&mut self, rhs: Vector4)
fn add_assign(&mut self, rhs: Vector4)
+=
operation. Read more§impl DivAssign<f32> for Vector4
impl DivAssign<f32> for Vector4
§fn div_assign(&mut self, rhs: f32)
fn div_assign(&mut self, rhs: f32)
/=
operation. Read more§impl DivAssign for Vector4
impl DivAssign for Vector4
§fn div_assign(&mut self, rhs: Vector4)
fn div_assign(&mut self, rhs: Vector4)
/=
operation. Read more§impl Export for Vector4
impl Export for Vector4
§fn default_export_info() -> PropertyHintInfo
fn default_export_info() -> PropertyHintInfo
§impl Extend<Vector4> for PackedVector4Array
impl Extend<Vector4> for PackedVector4Array
Extends aPackedVector4Array
with the contents of an iterator
§fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = Vector4>,
fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = Vector4>,
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)§impl FromGodot for Vector4
impl FromGodot for Vector4
§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.§fn from_godot(via: Self::Via) -> Self
fn from_godot(via: Self::Via) -> Self
§fn try_from_variant(variant: &Variant) -> Result<Self, ConvertError>
fn try_from_variant(variant: &Variant) -> Result<Self, ConvertError>
Variant
, returning Err
on failure.§fn from_variant(variant: &Variant) -> Self
fn from_variant(variant: &Variant) -> Self
§impl FromIterator<Vector4> for PackedVector4Array
impl FromIterator<Vector4> for PackedVector4Array
Creates a PackedVector4Array
from an iterator.
§fn from_iter<I>(iter: I) -> PackedVector4Arraywhere
I: IntoIterator<Item = Vector4>,
fn from_iter<I>(iter: I) -> PackedVector4Arraywhere
I: IntoIterator<Item = Vector4>,
§impl GodotConvert for Vector4
impl GodotConvert for Vector4
§impl Index<Vector4Axis> for Vector4
impl Index<Vector4Axis> for Vector4
§impl IndexMut<Vector4Axis> for Vector4
impl IndexMut<Vector4Axis> for Vector4
§fn index_mut(&mut self, axis: Vector4Axis) -> &mut f32
fn index_mut(&mut self, axis: Vector4Axis) -> &mut f32
container[index]
) operation. Read more§impl Mul<Vector4> for Projection
impl Mul<Vector4> for Projection
§impl MulAssign<f32> for Vector4
impl MulAssign<f32> for Vector4
§fn mul_assign(&mut self, rhs: f32)
fn mul_assign(&mut self, rhs: f32)
*=
operation. Read more§impl MulAssign for Vector4
impl MulAssign for Vector4
§fn mul_assign(&mut self, rhs: Vector4)
fn mul_assign(&mut self, rhs: Vector4)
*=
operation. Read more§impl SubAssign for Vector4
impl SubAssign for Vector4
§fn sub_assign(&mut self, rhs: Vector4)
fn sub_assign(&mut self, rhs: Vector4)
-=
operation. Read more§impl ToGodot for Vector4
impl ToGodot for Vector4
§fn to_godot(&self) -> <Vector4 as GodotConvert>::Via
fn to_godot(&self) -> <Vector4 as GodotConvert>::Via
§fn into_godot(self) -> <Vector4 as GodotConvert>::Via
fn into_godot(self) -> <Vector4 as GodotConvert>::Via
§fn to_variant(&self) -> Variant
fn to_variant(&self) -> Variant
§impl TypeStringHint for Vector4
impl TypeStringHint for Vector4
§fn type_string() -> String
fn type_string() -> String
§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
)