Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Vector2I

struct in Math

Description

(code of this item is picked from Godot Engine in compliance with MIT license).

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

Constructors

SignatureDescription
( int x, int y )Constructs a new Vector2I with the given components.

Methods

Return TypeSignatureDescription
voidDeconstruct ( int x, int y )Helper method for deconstruction into a tuple.
Vector2IAbs ( )Returns a new vector with all components in absolute values (i.e. positive).
floatAspect ( )Returns the aspect ratio of this vector, the ratio of X to Y .
Vector2IClamp ( Vector2I min, Vector2I max )Returns a new vector with all components clamped between the components of name and name using Mathf.Clamp(int, int, int) .
Vector2IClamp ( int min, int max )Returns a new vector with all components clamped between the name and name using Mathf.Clamp(int, int, int) .
intDistanceSquaredTo ( Vector2I to )Returns the squared distance between this vector and name . This method runs faster than DistanceTo , so prefer it if you need to compare vectors or need the squared distance for some formula.
floatDistanceTo ( Vector2I to )Returns the distance between this vector and name .
floatLength ( )Returns the length (magnitude) of this vector.
intLengthSquared ( )Returns the squared length (squared magnitude) of this vector. This method runs faster than Length , so prefer it if you need to compare vectors or need the squared length for some formula.
Vector2IMax ( Vector2I with )Returns the result of the component-wise maximum between this vector and name . Equivalent to new Vector2I(Mathf.Max(X, with.X), Mathf.Max(Y, with.Y)) .
Vector2IMax ( int with )Returns the result of the component-wise maximum between this vector and name . Equivalent to new Vector2I(Mathf.Max(X, with), Mathf.Max(Y, with)) .
Vector2IMin ( Vector2I with )Returns the result of the component-wise minimum between this vector and name . Equivalent to new Vector2I(Mathf.Min(X, with.X), Mathf.Min(Y, with.Y)) .
Vector2IMin ( int with )Returns the result of the component-wise minimum between this vector and name . Equivalent to new Vector2I(Mathf.Min(X, with), Mathf.Min(Y, with)) .
AxisMaxAxisIndex ( )Returns the axis of the vector's highest value. See Axis . If both components are equal, this method returns Axis.X .
AxisMinAxisIndex ( )Returns the axis of the vector's lowest value. See Axis . If both components are equal, this method returns Axis.Y .
Vector2ISign ( )Returns a vector with each component set to one or negative one, depending on the signs of this vector's components, or zero if the component is zero, by calling Mathf.Sign(int) on each component.
Vector2ISnapped ( Vector2I step )Returns a new vector with each component snapped to the closest multiple of the corresponding component in name .
Vector2ISnapped ( int step )Returns a new vector with each component snapped to the closest multiple of name .
boolEquals ( object? obj )Returns true if the vector is equal to the given object ( name ).
boolEquals ( Vector2I other )Returns true if the vectors are equal.
intGetHashCode ( )Serves as the hash function for Vector2I .
stringToString ( )Converts this Vector2I to a string.
stringToString ( string? format )Converts this Vector2I to a string with the given name .

Constants

NameTypeDescriptionInitializer
MinValueVector2IMin vector, a vector with all components equal to int.MinValue . Can be used as a negative integer equivalent of Vector2.Inf . Equivalent to new Vector2I(int.MinValue, int.MinValue) .new(int.MinValue, int.MinValue)
MaxValueVector2IMax vector, a vector with all components equal to int.MaxValue . Can be used as an integer equivalent of Vector2.Inf . Equivalent to new Vector2I(int.MaxValue, int.MaxValue) .new(int.MaxValue, int.MaxValue)
ZeroVector2IZero vector, a vector with all components set to 0 . Equivalent to new Vector2I(0, 0) .new(0, 0)
OneVector2IOne vector, a vector with all components set to 1 . Equivalent to new Vector2I(1, 1) .new(1, 1)
UpVector2IUp unit vector. Y is down in 2D, so this vector points -Y. Equivalent to new Vector2I(0, -1) .new(0, -1)
DownVector2IDown unit vector. Y is down in 2D, so this vector points +Y. Equivalent to new Vector2I(0, 1) .new(0, 1)
RightVector2IRight unit vector. Represents the direction of right. Equivalent to new Vector2I(1, 0) .new(1, 0)
LeftVector2ILeft unit vector. Represents the direction of left. Equivalent to new Vector2I(-1, 0) .new(-1, 0)

Operators

Return TypeSignatureDescription
Vector2I+ ( Vector2I left, Vector2I right )Adds each component of the Vector2I with the components of the given Vector2I .
Vector2I- ( Vector2I left, Vector2I right )Subtracts each component of the Vector2I by the components of the given Vector2I .
Vector2I- ( Vector2I vec )Returns the negative value of the Vector2I . This is the same as writing new Vector2I(-v.X, -v.Y) . This operation flips the direction of the vector while keeping the same magnitude.
Vector2I* ( Vector2I vec, int scale )Multiplies each component of the Vector2I by the given int .
Vector2I* ( int scale, Vector2I vec )Multiplies each component of the Vector2I by the given int .
Vector2I* ( Vector2I left, Vector2I right )Multiplies each component of the Vector2I by the components of the given Vector2I .
Vector2I/ ( Vector2I vec, int divisor )Divides each component of the Vector2I by the given int .
Vector2I/ ( Vector2I vec, Vector2I divisorv )Divides each component of the Vector2I by the components of the given Vector2I .
Vector2I% ( Vector2I vec, int divisor )Gets the remainder of each component of the Vector2I with the components of the given int . This operation uses truncated division, which is often not desired as it does not work well with negative numbers. Consider using Mathf.PosMod(int, int) instead if you want to handle negative numbers.
Vector2I% ( Vector2I vec, Vector2I divisorv )Gets the remainder of each component of the Vector2I with the components of the given Vector2I . This operation uses truncated division, which is often not desired as it does not work well with negative numbers. Consider using Mathf.PosMod(int, int) instead if you want to handle negative numbers.
bool== ( Vector2I left, Vector2I right )Returns true if the vectors are equal.
bool!= ( Vector2I left, Vector2I right )Returns true if the vectors are not equal.
bool< ( Vector2I left, Vector2I right )Compares two Vector2I vectors by first checking if the X value of the name vector is less than the X value of the name vector. If the X values are exactly equal, then it repeats this check with the Y values of the two vectors. This operator is useful for sorting vectors.
bool> ( Vector2I left, Vector2I right )Compares two Vector2I vectors by first checking if the X value of the name vector is greater than the X value of the name vector. If the X values are exactly equal, then it repeats this check with the Y values of the two vectors. This operator is useful for sorting vectors.
bool<= ( Vector2I left, Vector2I right )Compares two Vector2I vectors by first checking if the X value of the name vector is less than or equal to the X value of the name vector. If the X values are exactly equal, then it repeats this check with the Y values of the two vectors. This operator is useful for sorting vectors.
bool>= ( Vector2I left, Vector2I right )Compares two Vector2I vectors by first checking if the X value of the name vector is greater than or equal to the X value of the name vector. If the X values are exactly equal, then it repeats this check with the Y values of the two vectors. This operator is useful for sorting vectors.