#[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 discrete positions or directions in 2D space, as well as any other pair of numeric values.
Vector2i 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.
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.
§Navigation to impl blocks within this page
- Constants
- Constructors and general vector functions
- Specialized
Vector2ifunctions - 2D functions
- Trait impls + operators
§All vector types
You can convert to Vector2 using cast_float().
§Godot docs
Fields§
§x: i32The vector’s X component.
y: i32The vector’s Y component.
Implementations§
Source§impl Vector2i
§Constants
impl Vector2i
§Constants
Source§impl Vector2i
§Specialized Vector2i functions
impl Vector2i
§Specialized Vector2i functions
Sourcepub fn snapped(self, step: Vector2i) -> Vector2i
pub fn snapped(self, step: Vector2i) -> Vector2i
A new vector with each component snapped to the closest multiple of the corresponding
component in step.
§Panics
On under- or overflow:
Sourcepub const fn cast_float(self) -> Vector2
pub const fn cast_float(self) -> Vector2
Converts to a vector with floating-point real components, using as casts.
Source§impl Vector2i
§Constructors and general vector functions
The following associated functions and methods are available on all vectors (2D, 3D, 4D; float and int).
impl Vector2i
§Constructors and general vector functions
The following associated functions and methods are available on all vectors (2D, 3D, 4D; float and int).
Sourcepub const fn from_tuple(tuple: (i32, i32)) -> Vector2i
pub const fn from_tuple(tuple: (i32, i32)) -> Vector2i
Creates a vector from the given tuple.
Sourcepub const fn from_array(array: [i32; 2]) -> Vector2i
pub const fn from_array(array: [i32; 2]) -> Vector2i
Creates a vector from the given array.
Sourcepub fn abs(self) -> Vector2i
pub fn abs(self) -> Vector2i
Returns a new vector with all components in absolute values (i.e. positive or zero).
Sourcepub fn clamp(self, min: Vector2i, max: Vector2i) -> Vector2i
pub fn clamp(self, min: Vector2i, max: Vector2i) -> Vector2i
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.
Sourcepub fn length_squared(self) -> i32
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.
Sourcepub fn coord_min(self, other: Vector2i) -> Vector2i
pub fn coord_min(self, other: Vector2i) -> Vector2i
Returns a new vector containing the minimum of the two vectors, component-wise.
You may consider using the fully-qualified syntax Vector2i::coord_min(a, b) for symmetry.
Source§impl Vector2i
§2D functions
The following methods are only available on 2D vectors (for both float and int).
impl Vector2i
§2D functions
The following methods are only available on 2D vectors (for both float and int).
Sourcepub fn max_axis(self) -> Option<Vector2Axis>
pub fn max_axis(self) -> Option<Vector2Axis>
Returns the axis of the vector’s highest value. See Vector2Axis enum. If all components are equal, this method returns None.
To mimic Godot’s behavior, unwrap this function’s result with unwrap_or(Vector2Axis::X).
Godot equivalent: Vector2i.max_axis_index
Sourcepub fn min_axis(self) -> Option<Vector2Axis>
pub fn min_axis(self) -> Option<Vector2Axis>
Returns the axis of the vector’s lowest value. See Vector2Axis enum. If all components are equal, this method returns None.
To mimic Godot’s behavior, unwrap this function’s result with unwrap_or(Vector2Axis::Y).
Godot equivalent: Vector2i.min_axis_index
Source§impl Vector2i
impl Vector2i
pub fn distance_to(&self, to: Vector2i) -> f64
pub fn distance_squared_to(&self, to: Vector2i) -> i64
pub fn clampi(&self, min: i64, max: i64) -> Vector2i
pub fn snappedi(&self, step: i64) -> Vector2i
pub fn mini(&self, with: i64) -> Vector2i
pub fn maxi(&self, with: i64) -> Vector2i
Trait Implementations§
Source§impl AddAssign for Vector2i
impl AddAssign for Vector2i
Source§fn add_assign(&mut self, rhs: Vector2i)
fn add_assign(&mut self, rhs: Vector2i)
+= operation. Read moreSource§impl DivAssign<i32> for Vector2i
impl DivAssign<i32> for Vector2i
Source§fn div_assign(&mut self, rhs: i32)
fn div_assign(&mut self, rhs: i32)
/= operation. Read moreSource§impl DivAssign for Vector2i
impl DivAssign for Vector2i
Source§fn div_assign(&mut self, rhs: Vector2i)
fn div_assign(&mut self, rhs: Vector2i)
/= operation. Read moreSource§impl DynamicSend for Vector2i
impl DynamicSend for Vector2i
Source§impl Export for Vector2i
impl Export for Vector2i
Source§fn export_hint() -> PropertyHintInfo
fn export_hint() -> PropertyHintInfo
Source§impl FromGodot for Vector2i
impl FromGodot for Vector2i
Source§fn try_from_godot(
via: <Vector2i as GodotConvert>::Via,
) -> Result<Vector2i, ConvertError>
fn try_from_godot( via: <Vector2i as GodotConvert>::Via, ) -> Result<Vector2i, ConvertError>
Err on failure.Source§fn from_godot(via: Self::Via) -> Self
fn from_godot(via: Self::Via) -> Self
Source§fn try_from_variant(variant: &Variant) -> Result<Self, ConvertError>
fn try_from_variant(variant: &Variant) -> Result<Self, ConvertError>
Variant, returning Err on failure.Source§impl GodotConvert for Vector2i
impl GodotConvert for Vector2i
Source§impl Index<Vector2Axis> for Vector2i
impl Index<Vector2Axis> for Vector2i
Source§impl IndexMut<Vector2Axis> for Vector2i
impl IndexMut<Vector2Axis> for Vector2i
Source§impl IntoDynamicSend for Vector2i
impl IntoDynamicSend for Vector2i
type Target = Vector2i
fn into_dynamic_send(self) -> <Vector2i as IntoDynamicSend>::Target
Source§impl MulAssign<i32> for Vector2i
impl MulAssign<i32> for Vector2i
Source§fn mul_assign(&mut self, rhs: i32)
fn mul_assign(&mut self, rhs: i32)
*= operation. Read moreSource§impl MulAssign for Vector2i
impl MulAssign for Vector2i
Source§fn mul_assign(&mut self, rhs: Vector2i)
fn mul_assign(&mut self, rhs: Vector2i)
*= operation. Read moreSource§impl Ord for Vector2i
impl Ord for Vector2i
Source§impl PartialOrd for Vector2i
impl PartialOrd for Vector2i
Source§impl SubAssign for Vector2i
impl SubAssign for Vector2i
Source§fn sub_assign(&mut self, rhs: Vector2i)
fn sub_assign(&mut self, rhs: Vector2i)
-= operation. Read moreSource§impl ToGodot for Vector2i
impl ToGodot for Vector2i
Source§type Pass = ByValue
type Pass = ByValue
Source§fn to_godot(&self) -> <Vector2i as GodotConvert>::Via
fn to_godot(&self) -> <Vector2i as GodotConvert>::Via
Source§fn to_godot_owned(&self) -> Self::Via
fn to_godot_owned(&self) -> Self::Via
Source§fn to_variant(&self) -> Variant
fn to_variant(&self) -> Variant
Source§impl Var for Vector2i
impl Var for Vector2i
fn get_property(&self) -> <Vector2i as GodotConvert>::Via
fn set_property(&mut self, value: <Vector2i as GodotConvert>::Via)
Source§fn var_hint() -> PropertyHintInfo
fn var_hint() -> PropertyHintInfo
GodotType::property_info, e.g. for enums/newtypes.