Struct Vector4i

Source
#[repr(C)]
pub struct Vector4i { pub x: i32, pub y: i32, pub z: i32, pub w: i32, }
Expand description

Vector used for 4D math using integer coordinates.

4-element structure that can be used to represent 4D grid coordinates or sets of integers.

Vector4i uses integer coordinates and is therefore preferable to Vector4 when exact precision is required. Note that the values are limited to 32 bits, and unlike Vector4 this cannot be configured with an engine build option. Use i64 or PackedInt64Array if 64-bit values are needed.

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

Vector4i (stable)

Fields§

§x: i32

The vector’s X component.

§y: i32

The vector’s Y component.

§z: i32

The vector’s Z component.

§w: i32

The vector’s W component.

Implementations§

Source§

impl Vector4i

§Constants

Source

pub const ZERO: Vector4i

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

Source

pub const ONE: Vector4i

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

Source

pub const MIN: Vector4i

Min vector, a vector with all components equal to i32::MIN. Can be used as a negative integer equivalent of real::INF.

Source

pub const MAX: Vector4i

Max vector, a vector with all components equal to i32::MAX. Can be used as an integer equivalent of real::INF.

Source§

impl Vector4i

§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: i32, y: i32, z: i32, w: i32) -> Vector4i

Creates a vector with the given components.

Source

pub const fn splat(v: i32) -> Vector4i

Creates a vector with all components set to v.

Source

pub const fn from_tuple(tuple: (i32, i32, i32, i32)) -> Vector4i

Creates a vector from the given tuple.

Source

pub const fn from_array(array: [i32; 4]) -> Vector4i

Creates a vector from the given array.

Source

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

Returns a tuple with the components of the vector.

Source

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

Returns an array with the components of the vector.

Source

pub fn abs(self) -> Vector4i

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

Source

pub fn clamp(self, min: Vector4i, max: Vector4i) -> Vector4i

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

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: Vector4i) -> Vector4i

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

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

Source

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

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

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

Source

pub fn sign(self) -> Vector4i

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

Source§

impl Vector4i

§Specialized Vector4i functions

Source

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

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

§Panics

On under- or overflow:

  • If any component of self is i32::MIN while the same component on step is -1.
  • If any component of self plus half of the same component of step is not in range on i32.
Source

pub const fn cast_float(self) -> Vector4

Converts to a vector with floating-point real components, using as casts.

Source§

impl Vector4i

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

Trait Implementations§

Source§

impl Add for Vector4i

Source§

type Output = Vector4i

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl AddAssign for Vector4i

Source§

fn add_assign(&mut self, rhs: Vector4i)

Performs the += operation. Read more
Source§

impl Clone for Vector4i

Source§

fn clone(&self) -> Vector4i

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 Vector4i

Source§

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

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

impl Default for Vector4i

Source§

fn default() -> Vector4i

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

impl Display for Vector4i

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<i32> for Vector4i

Source§

type Output = Vector4i

The resulting type after applying the / operator.
Source§

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

Performs the / operation. Read more
Source§

impl Div for Vector4i

Source§

type Output = Vector4i

The resulting type after applying the / operator.
Source§

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

Performs the / operation. Read more
Source§

impl DivAssign<i32> for Vector4i

Source§

fn div_assign(&mut self, rhs: i32)

Performs the /= operation. Read more
Source§

impl DivAssign for Vector4i

Source§

fn div_assign(&mut self, rhs: Vector4i)

Performs the /= operation. Read more
Source§

impl DynamicSend for Vector4i

Source§

impl Export for Vector4i

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 Vector4i

Source§

fn try_from_godot( via: <Vector4i as GodotConvert>::Via, ) -> Result<Vector4i, 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 Vector4i

Source§

type Via = Vector4i

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

impl Hash for Vector4i

Source§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Index<Vector4Axis> for Vector4i

Source§

type Output = i32

The returned type after indexing.
Source§

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

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

impl IndexMut<Vector4Axis> for Vector4i

Source§

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

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

impl IntoDynamicSend for Vector4i

Source§

impl Mul<i32> for Vector4i

Source§

type Output = Vector4i

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl Mul for Vector4i

Source§

type Output = Vector4i

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl MulAssign<i32> for Vector4i

Source§

fn mul_assign(&mut self, rhs: i32)

Performs the *= operation. Read more
Source§

impl MulAssign for Vector4i

Source§

fn mul_assign(&mut self, rhs: Vector4i)

Performs the *= operation. Read more
Source§

impl Neg for Vector4i

Source§

type Output = Vector4i

The resulting type after applying the - operator.
Source§

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

Performs the unary - operation. Read more
Source§

impl Ord for Vector4i

Source§

fn cmp(&self, other: &Vector4i) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl ParamType for Vector4i

Source§

type ArgPassing = ByValue

Source§

fn owned_to_arg(self) -> impl AsArg<Self>

👎Deprecated since 0.3.2: This method is no longer needed and will be removed in 0.4
Source§

impl PartialEq for Vector4i

Source§

fn eq(&self, other: &Vector4i) -> 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 PartialOrd for Vector4i

Source§

fn partial_cmp(&self, other: &Vector4i) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

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

Source§

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

Element-wise product of all vectors in the iterator.

Source§

impl Product for Vector4i

Source§

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

Element-wise product of all vectors in the iterator.

Source§

impl Sub for Vector4i

Source§

type Output = Vector4i

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl SubAssign for Vector4i

Source§

fn sub_assign(&mut self, rhs: Vector4i)

Performs the -= operation. Read more
Source§

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

Source§

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

Element-wise sum of all vectors in the iterator.

Source§

impl Sum for Vector4i

Source§

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

Element-wise sum of all vectors in the iterator.

Source§

impl ToGodot for Vector4i

Source§

type ToVia<'v> = <Vector4i as GodotConvert>::Via

Target type of to_godot(), which can differ from Via for pass-by-reference types. Read more
Source§

fn to_godot(&self) -> <Vector4i as ToGodot>::ToVia<'_>

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

fn to_variant(&self) -> Variant

Converts this type to a Variant.
Source§

impl Var for Vector4i

Source§

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

Source§

fn set_property(&mut self, value: <Vector4i 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 Vector4i

Source§

impl BuiltinExport for Vector4i

Source§

impl Copy for Vector4i

Source§

impl Eq for Vector4i

Source§

impl GodotType for Vector4i

Source§

impl StructuralPartialEq for Vector4i

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 + ParamType<ArgPassing = ByValue>,

Source§

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

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.