Struct godot::prelude::Vector2i

#[repr(C)]
pub struct Vector2i { pub x: i32, pub y: i32, }
Expand description

Vector used for 2D math using integer coordinates.

2-element structure that can be used to represent positions in 2D space or any other pair of numeric values.

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

Fields§

§x: i32

The vector’s X component.

§y: i32

The vector’s Y component.

Implementations§

§

impl Vector2i

pub const ZERO: Vector2i = _

Vector with all components set to 0.

pub const ONE: Vector2i = _

Vector with all components set to 1.

pub const LEFT: Vector2i = _

Unit vector in -X direction (right in 2D coordinate system).

pub const RIGHT: Vector2i = _

Unit vector in +X direction (right in 2D coordinate system).

pub const UP: Vector2i = _

Unit vector in -Y direction (up in 2D coordinate system).

pub const DOWN: Vector2i = _

Unit vector in +Y direction (down in 2D coordinate system).

pub const fn new(x: i32, y: i32) -> Vector2i

Constructs a new Vector2i from the given x and y.

pub fn aspect(self) -> f32

Aspect ratio: x / y, as a real value.

pub fn max_axis(self) -> Option<Vector2Axis>

Axis of the vector’s highest value. None if components are equal.

pub fn min_axis(self) -> Option<Vector2Axis>

Axis of the vector’s highest value. None if components are equal.

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

Constructs a new Vector2i with both components set to v.

pub const fn from_vector2(v: Vector2) -> Vector2i

Constructs a new Vector2i from a Vector2. The floating point coordinates will be truncated.

pub fn coords(&self) -> (i32, i32)

§

impl Vector2i

pub fn abs(self) -> Vector2i

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

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

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

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

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

§

impl Vector2i

pub fn length(self) -> f32

Length (magnitude) of this vector.

pub fn sign(self) -> Vector2i

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 Vector2i

pub fn length_squared(self) -> i64

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.

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

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

Trait Implementations§

§

impl Add for Vector2i

§

type Output = Vector2i

The resulting type after applying the + operator.
§

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

Performs the + operation. Read more
§

impl AddAssign for Vector2i

§

fn add_assign(&mut self, rhs: Vector2i)

Performs the += operation. Read more
§

impl Clone for Vector2i

§

fn clone(&self) -> Vector2i

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 Vector2i

§

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

Formats the value using the given formatter. Read more
§

impl Default for Vector2i

§

fn default() -> Vector2i

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

impl Display for Vector2i

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

§

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

Formats the value using the given formatter. Read more
§

impl Div<i32> for Vector2i

§

type Output = Vector2i

The resulting type after applying the / operator.
§

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

Performs the / operation. Read more
§

impl Div for Vector2i

§

type Output = Vector2i

The resulting type after applying the / operator.
§

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

Performs the / operation. Read more
§

impl DivAssign<i32> for Vector2i

§

fn div_assign(&mut self, rhs: i32)

Performs the /= operation. Read more
§

impl DivAssign for Vector2i

§

fn div_assign(&mut self, rhs: Vector2i)

Performs the /= operation. Read more
§

impl Export for Vector2i

§

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 FromGodot for Vector2i

§

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

Performs the conversion.
§

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

⚠️ Performs the conversion. Read more
§

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

Performs the conversion from a Variant.
§

fn from_variant(variant: &Variant) -> Self

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

impl GodotConvert for Vector2i

§

type Via = Vector2i

The type through which Self is represented in Godot.
§

impl Hash for Vector2i

§

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
§

impl Index<Vector2Axis> for Vector2i

§

type Output = i32

The returned type after indexing.
§

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

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

impl IndexMut<Vector2Axis> for Vector2i

§

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

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

impl Mul<i32> for Vector2i

§

type Output = Vector2i

The resulting type after applying the * operator.
§

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

Performs the * operation. Read more
§

impl Mul for Vector2i

§

type Output = Vector2i

The resulting type after applying the * operator.
§

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

Performs the * operation. Read more
§

impl MulAssign<i32> for Vector2i

§

fn mul_assign(&mut self, rhs: i32)

Performs the *= operation. Read more
§

impl MulAssign for Vector2i

§

fn mul_assign(&mut self, rhs: Vector2i)

Performs the *= operation. Read more
§

impl Neg for Vector2i

§

type Output = Vector2i

The resulting type after applying the - operator.
§

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

Performs the unary - operation. Read more
§

impl Ord for Vector2i

§

fn cmp(&self, other: &Vector2i) -> 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 + PartialOrd,

Restrict a value to a certain interval. Read more
§

impl PartialEq for Vector2i

§

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

§

fn partial_cmp(&self, other: &Vector2i) -> 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

This method 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

This method 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

This method 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

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

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

§

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

Element-wise product of all vectors in the iterator.

§

impl Product for Vector2i

§

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

Element-wise product of all vectors in the iterator.

§

impl Sub for Vector2i

§

type Output = Vector2i

The resulting type after applying the - operator.
§

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

Performs the - operation. Read more
§

impl SubAssign for Vector2i

§

fn sub_assign(&mut self, rhs: Vector2i)

Performs the -= operation. Read more
§

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

§

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

Element-wise sum of all vectors in the iterator.

§

impl Sum for Vector2i

§

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

Element-wise sum of all vectors in the iterator.

§

impl ToGodot for Vector2i

§

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

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

fn into_godot(self) -> <Vector2i 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 Vector2i

§

fn type_string() -> String

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

impl Var for Vector2i

§

impl ArrayElement for Vector2i

§

impl Copy for Vector2i

§

impl Eq for Vector2i

§

impl GodotType for Vector2i

§

impl StructuralPartialEq for Vector2i

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