Struct godot::builtin::Vector4

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

pub const ZERO: Vector4 = _

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

pub const ONE: Vector4 = _

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

§

impl Vector4

pub const INF: Vector4 = _

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

§

impl Vector4

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

Returns a vector with the given components.

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

Returns a new vector with all components set to v.

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

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

Returns the length (magnitude) of this vector.

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

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

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

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

pub fn sign(self) -> Vector4

Returns a new vector with each component set to 1 if it’s positive, -1 if it’s negative, and 0 if it’s zero.

§

impl 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

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

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>

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

⚠️ 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

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

Returns the distance between this vector and to.

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

Returns the dot product of this vector and with.

pub fn floor(self) -> Vector4

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

pub fn is_finite(self) -> bool

Returns true if each component of this vector is finite.

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

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

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>

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

⚠️ 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

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

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

pub fn posmodv(self, modv: Vector4) -> Vector4

Returns a vector composed of the FloatExt::fposmod of this vector’s components and modv’s components.

pub fn round(self) -> Vector4

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

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

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

§

impl Vector4

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>

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

§

impl Vector4

pub fn recip(self) -> Vector4

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

§

impl Vector4

pub const fn from_vector4i(v: Vector4i) -> Vector4

Constructs a new Vector4 from a Vector4i.

Trait Implementations§

§

impl Add for Vector4

§

type Output = Vector4

The resulting type after applying the + operator.
§

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

Performs the + operation. Read more
§

impl AddAssign for Vector4

§

fn add_assign(&mut self, rhs: Vector4)

Performs the += operation. Read more
§

impl ApproxEq for Vector4

§

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

Returns true if this vector and to are approximately equal.

§

impl Clone for Vector4

§

fn clone(&self) -> Vector4

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
§

impl Debug for Vector4

§

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

Formats the value using the given formatter. Read more
§

impl Default for Vector4

§

fn default() -> Vector4

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

impl Display for Vector4

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

§

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

Formats the value using the given formatter. Read more
§

impl Div<f32> for Vector4

§

type Output = Vector4

The resulting type after applying the / operator.
§

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

Performs the / operation. Read more
§

impl Div for Vector4

§

type Output = Vector4

The resulting type after applying the / operator.
§

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

Performs the / operation. Read more
§

impl DivAssign<f32> for Vector4

§

fn div_assign(&mut self, rhs: f32)

Performs the /= operation. Read more
§

impl DivAssign for Vector4

§

fn div_assign(&mut self, rhs: Vector4)

Performs the /= operation. Read more
§

impl Export for Vector4

§

fn default_export_info() -> PropertyHintInfo

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

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>,

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
§

impl FromGodot for Vector4

§

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

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

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

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

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

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

fn from_variant(variant: &Variant) -> Self

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

impl FromIterator<Vector4> for PackedVector4Array

Creates a PackedVector4Array from an iterator.

§

fn from_iter<I>(iter: I) -> PackedVector4Array
where I: IntoIterator<Item = Vector4>,

Creates a value from an iterator. Read more
§

impl GodotConvert for Vector4

§

type Via = Vector4

The type through which Self is represented in Godot.
§

impl Index<Vector4Axis> for Vector4

§

type Output = f32

The returned type after indexing.
§

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

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

impl IndexMut<Vector4Axis> for Vector4

§

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

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

impl Mul<Vector4> for Projection

§

type Output = Vector4

The resulting type after applying the * operator.
§

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

Performs the * operation. Read more
§

impl Mul<f32> for Vector4

§

type Output = Vector4

The resulting type after applying the * operator.
§

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

Performs the * operation. Read more
§

impl Mul for Vector4

§

type Output = Vector4

The resulting type after applying the * operator.
§

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

Performs the * operation. Read more
§

impl MulAssign<f32> for Vector4

§

fn mul_assign(&mut self, rhs: f32)

Performs the *= operation. Read more
§

impl MulAssign for Vector4

§

fn mul_assign(&mut self, rhs: Vector4)

Performs the *= operation. Read more
§

impl Neg for Vector4

§

type Output = Vector4

The resulting type after applying the - operator.
§

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

Performs the unary - operation. Read more
§

impl PartialEq for Vector4

§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

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

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

§

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

Element-wise product of all vectors in the iterator.

§

impl Product for Vector4

§

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

Element-wise product of all vectors in the iterator.

§

impl Sub for Vector4

§

type Output = Vector4

The resulting type after applying the - operator.
§

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

Performs the - operation. Read more
§

impl SubAssign for Vector4

§

fn sub_assign(&mut self, rhs: Vector4)

Performs the -= operation. Read more
§

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

§

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

Element-wise sum of all vectors in the iterator.

§

impl Sum for Vector4

§

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

Element-wise sum of all vectors in the iterator.

§

impl ToGodot for Vector4

§

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

Converts this type to the Godot type by reference, usually by cloning.
§

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

Converts this type to the Godot type. Read more
§

fn to_variant(&self) -> Variant

Converts this type to a Variant.
§

impl TypeStringHint for Vector4

§

fn type_string() -> String

Returns the representation of this type as a type string. Read more
§

impl Var for Vector4

§

impl ArrayElement for Vector4

§

impl Copy for Vector4

§

impl GodotType for Vector4

§

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> 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: Copy,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

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

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

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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,

§

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§

default 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>,

§

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>,

§

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.