Vector4

Struct Vector4 

Source
#[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.

Conversions are provided via various from_* and to_* functions, not via the From trait. This encourages new() as the main way to construct vectors, is explicit about the conversion taking place, needs no type inference, and works in const contexts.

§All vector types

DimensionFloating-pointInteger
2DVector2Vector2i
3DVector3Vector3i
4DVector4Vector4i

§Godot docs

Vector4 (stable)

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

§Constants

Source

pub const ZERO: Vector4

Zero vector, a vector with all components set to 0.

Source

pub const ONE: Vector4

One vector, a vector with all components set to 1.

Source

pub const INF: Vector4

Infinity vector, a vector with all components set to real::INFINITY.

Source§

impl Vector4

§Constructors and general vector functions

The following associated functions and methods are available on all vectors (2D, 3D, 4D; float and int).

Source

pub const fn new(x: f32, y: f32, z: f32, w: f32) -> Vector4

Creates a vector with the given components.

Source

pub const fn splat(v: f32) -> Vector4

Creates a vector with all components set to v.

Source

pub const fn from_tuple(tuple: (f32, f32, f32, f32)) -> Vector4

Creates a vector from the given tuple.

Source

pub const fn from_array(array: [f32; 4]) -> Vector4

Creates a vector from the given array.

Source

pub const fn to_tuple(&self) -> (f32, f32, f32, f32)

Returns a tuple with the components of the vector.

Source

pub const fn to_array(&self) -> [f32; 4]

Returns an array with the components of the vector.

Source

pub fn abs(self) -> Vector4

Returns a new vector with all components in absolute values (i.e. positive or zero).

Source

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.

Source

pub fn length(self) -> f32

Returns the length (magnitude) of this vector.

Source

pub fn length_squared(self) -> f32

Squared length (squared magnitude) of this vector.

Runs faster than length(), so prefer it if you need to compare vectors or need the squared distance for some formula.

Source

pub fn coord_min(self, other: Vector4) -> Vector4

Returns a new vector containing the minimum of the two vectors, component-wise.

You may consider using the fully-qualified syntax Vector4::coord_min(a, b) for symmetry.

Source

pub fn coord_max(self, other: Vector4) -> Vector4

Returns a new vector containing the maximum of the two vectors, component-wise.

You may consider using the fully-qualified syntax Vector4::coord_max(a, b) for symmetry.

Source

pub fn sign(self) -> Vector4

Returns a new vector with each component set to 1 if the component is positive, -1 if negative, and 0 if zero.

Source§

impl Vector4

This impl block contains no items.

§Specialized Vector4 functions

Source§

impl Vector4

§Float-specific functions

The following methods are only available on floating-point vectors.

Source

pub const fn cast_int(self) -> Vector4i

Converts to a vector with integer components, using as casts.

Source

pub fn floor(self) -> Vector4

Returns a new vector with all components rounded down (towards negative infinity).

Source

pub fn ceil(self) -> Vector4

Returns a new vector with all components rounded up (towards positive infinity).

Source

pub fn cubic_interpolate( self, b: Vector4, pre_a: Vector4, post_b: Vector4, weight: f32, ) -> Vector4

Cubic interpolation between self 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.

Source

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

Cubic interpolation between self 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 cubic_interpolate() by the time values.

Source

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

Source

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.

Source

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.

Source

pub fn distance_to(self, to: Vector4) -> f32

Returns the distance between this vector and to.

Source

pub fn dot(self, with: Vector4) -> f32

Returns the dot product of this vector and with.

Source

pub fn is_finite(self) -> bool

Returns true if each component of this vector is finite.

Source

pub fn is_normalized(self) -> bool

Returns true if the vector is normalized, i.e. its length is approximately equal to 1.

Source

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.

Source

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.

Source

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

Source

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.

Source

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

Source

pub fn posmod(self, pmod: f32) -> Vector4

Returns a vector composed of the FloatExt::fposmod() of this vector’s components and pmod.

Source

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

pub fn round(self) -> Vector4

Returns a new vector with all components rounded to the nearest integer, with halfway cases rounded away from zero.

Source

pub fn snapped(self, step: Vector4) -> Vector4

A new vector with each component snapped to the closest multiple of the corresponding component in step.

Source§

impl Vector4

§4D functions

The following methods are only available on 4D vectors (for both float and int).

Source

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

Source

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

Source§

impl Vector4

§3D and 4D functions

The following methods are available on both 3D and 4D float vectors.

Source

pub fn recip(self) -> Vector4

Returns the reciprocal (inverse) of the vector. This is the same as 1.0/n for each component.

Trait Implementations§

Source§

impl Add for Vector4

Source§

type Output = Vector4

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Vector4) -> <Vector4 as Add>::Output

Performs the + operation. Read more
Source§

impl AddAssign for Vector4

Source§

fn add_assign(&mut self, rhs: Vector4)

Performs the += operation. Read more
Source§

impl ApproxEq for Vector4

Source§

fn approx_eq(&self, other: &Vector4) -> bool

Returns true if this vector and to are approximately equal.

Source§

impl Clone for Vector4

Source§

fn clone(&self) -> Vector4

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Vector4

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for Vector4

Source§

fn default() -> Vector4

Returns the “default value” for a type. Read more
Source§

impl Display for Vector4

Formats the vector like Godot: (x, y, z, w).

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Div<f32> for Vector4

Source§

type Output = Vector4

The resulting type after applying the / operator.
Source§

fn div(self, rhs: f32) -> <Vector4 as Div<f32>>::Output

Performs the / operation. Read more
Source§

impl Div for Vector4

Source§

type Output = Vector4

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Vector4) -> <Vector4 as Div>::Output

Performs the / operation. Read more
Source§

impl DivAssign<f32> for Vector4

Source§

fn div_assign(&mut self, rhs: f32)

Performs the /= operation. Read more
Source§

impl DivAssign for Vector4

Source§

fn div_assign(&mut self, rhs: Vector4)

Performs the /= operation. Read more
Source§

impl DynamicSend for Vector4

Source§

impl Export for Vector4

Source§

fn export_hint() -> PropertyHintInfo

The export info to use for an exported field of this type, if no other export info is specified.
Source§

impl FromGodot for Vector4

Source§

fn try_from_godot( via: <Vector4 as GodotConvert>::Via, ) -> Result<Vector4, ConvertError>

Converts the Godot representation to this type, returning Err on failure.
Source§

fn from_godot(via: Self::Via) -> Self

⚠️ Converts the Godot representation to this type. Read more
Source§

fn try_from_variant(variant: &Variant) -> Result<Self, ConvertError>

Performs the conversion from a Variant, returning Err on failure.
Source§

fn from_variant(variant: &Variant) -> Self

⚠️ Performs the conversion from a Variant. Read more
Source§

impl GodotConvert for Vector4

Source§

type Via = Vector4

The type through which Self is represented in Godot.
Source§

impl Index<Vector4Axis> for Vector4

Source§

type Output = f32

The returned type after indexing.
Source§

fn index(&self, axis: Vector4Axis) -> &f32

Performs the indexing (container[index]) operation. Read more
Source§

impl IndexMut<Vector4Axis> for Vector4

Source§

fn index_mut(&mut self, axis: Vector4Axis) -> &mut f32

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl IntoDynamicSend for Vector4

Source§

impl Mul<Vector4> for Projection

Source§

type Output = Vector4

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Vector4) -> <Projection as Mul<Vector4>>::Output

Performs the * operation. Read more
Source§

impl Mul<f32> for Vector4

Source§

type Output = Vector4

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: f32) -> <Vector4 as Mul<f32>>::Output

Performs the * operation. Read more
Source§

impl Mul for Vector4

Source§

type Output = Vector4

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Vector4) -> <Vector4 as Mul>::Output

Performs the * operation. Read more
Source§

impl MulAssign<f32> for Vector4

Source§

fn mul_assign(&mut self, rhs: f32)

Performs the *= operation. Read more
Source§

impl MulAssign for Vector4

Source§

fn mul_assign(&mut self, rhs: Vector4)

Performs the *= operation. Read more
Source§

impl Neg for Vector4

Source§

type Output = Vector4

The resulting type after applying the - operator.
Source§

fn neg(self) -> <Vector4 as Neg>::Output

Performs the unary - operation. Read more
Source§

impl PartialEq for Vector4

Source§

fn eq(&self, other: &Vector4) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a> Product<&'a Vector4> for Vector4

Source§

fn product<I>(iter: I) -> Vector4
where I: Iterator<Item = &'a Vector4>,

Element-wise product of all vectors in the iterator.

Source§

impl Product for Vector4

Source§

fn product<I>(iter: I) -> Vector4
where I: Iterator<Item = Vector4>,

Element-wise product of all vectors in the iterator.

Source§

impl Sub for Vector4

Source§

type Output = Vector4

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Vector4) -> <Vector4 as Sub>::Output

Performs the - operation. Read more
Source§

impl SubAssign for Vector4

Source§

fn sub_assign(&mut self, rhs: Vector4)

Performs the -= operation. Read more
Source§

impl<'a> Sum<&'a Vector4> for Vector4

Source§

fn sum<I>(iter: I) -> Vector4
where I: Iterator<Item = &'a Vector4>,

Element-wise sum of all vectors in the iterator.

Source§

impl Sum for Vector4

Source§

fn sum<I>(iter: I) -> Vector4
where I: Iterator<Item = Vector4>,

Element-wise sum of all vectors in the iterator.

Source§

impl ToGodot for Vector4

Source§

type Pass = ByValue

Whether arguments of this type are passed by value or by reference. Read more
Source§

fn to_godot(&self) -> <Vector4 as GodotConvert>::Via

Converts this type to Godot representation, optimizing for zero-copy when possible. Read more
Source§

fn to_godot_owned(&self) -> Self::Via
where Self::Via: Clone,

Converts this type to owned Godot representation. Read more
Source§

fn to_variant(&self) -> Variant

Converts this type to a Variant.
Source§

impl Var for Vector4

Source§

fn get_property(&self) -> <Vector4 as GodotConvert>::Via

Source§

fn set_property(&mut self, value: <Vector4 as GodotConvert>::Via)

Source§

fn var_hint() -> PropertyHintInfo

Specific property hints, only override if they deviate from GodotType::property_info, e.g. for enums/newtypes.
Source§

impl ArrayElement for Vector4

Source§

impl BuiltinExport for Vector4

Source§

impl Copy for Vector4

Source§

impl GodotType for Vector4

Source§

impl PackedArrayElement for Vector4

Source§

impl StructuralPartialEq for Vector4

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> AsArg<T> for T
where T: ToGodot<Pass = ByValue>,

Source§

fn into_arg<'arg>(self) -> CowArg<'arg, T>
where T: 'arg,

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.