Vector4i
A 4D vector using integer coordinates.
Description
A 4-element structure that can be used to represent 4D grid coordinates or any other quadruplet of integers.
It uses integer coordinates and is therefore preferable toVector4 when exact precision is required. Note that the values are limited to 32 bits, and unlikeVector4 this cannot be configured with an engine build option. Useint orPackedInt64Array if 64-bit values are needed.
Note: In a boolean context, a Vector4i will evaluate tofalse
if it's equal toVector4i(0,0,0,0)
. Otherwise, a Vector4i will always evaluate totrue
.
Properties
| ||
| ||
| ||
|
Constructors
Vector4i() | |
Methods
Operators
operator !=(right:Vector4i) | |
operator %(right:Vector4i) | |
operator %(right:int) | |
operator *(right:Vector4i) | |
operator *(right:float) | |
operator *(right:int) | |
operator +(right:Vector4i) | |
operator -(right:Vector4i) | |
operator /(right:Vector4i) | |
operator /(right:float) | |
operator /(right:int) | |
operator <(right:Vector4i) | |
operator <=(right:Vector4i) | |
operator ==(right:Vector4i) | |
operator >(right:Vector4i) | |
operator >=(right:Vector4i) | |
operator [](index:int) | |
Enumerations
enumAxis:🔗
AxisAXIS_X =0
Enumerated value for the X axis. Returned bymax_axis_index() andmin_axis_index().
AxisAXIS_Y =1
Enumerated value for the Y axis. Returned bymax_axis_index() andmin_axis_index().
AxisAXIS_Z =2
Enumerated value for the Z axis. Returned bymax_axis_index() andmin_axis_index().
AxisAXIS_W =3
Enumerated value for the W axis. Returned bymax_axis_index() andmin_axis_index().
Constants
ZERO =Vector4i(0,0,0,0)
🔗
Zero vector, a vector with all components set to0
.
ONE =Vector4i(1,1,1,1)
🔗
One vector, a vector with all components set to1
.
MIN =Vector4i(-2147483648,-2147483648,-2147483648,-2147483648)
🔗
Min vector, a vector with all components equal toINT32_MIN
. Can be used as a negative integer equivalent ofVector4.INF.
MAX =Vector4i(2147483647,2147483647,2147483647,2147483647)
🔗
Max vector, a vector with all components equal toINT32_MAX
. Can be used as an integer equivalent ofVector4.INF.
Property Descriptions
The vector's W component. Also accessible by using the index position[3]
.
The vector's X component. Also accessible by using the index position[0]
.
The vector's Y component. Also accessible by using the index position[1]
.
The vector's Z component. Also accessible by using the index position[2]
.
Constructor Descriptions
Constructs a default-initializedVector4i with all components set to0
.
Vector4iVector4i(from:Vector4i)
Constructs aVector4i as a copy of the givenVector4i.
Vector4iVector4i(from:Vector4)
Constructs a newVector4i from the givenVector4 by truncating components' fractional parts (rounding towards zero). For a different behavior consider passing the result ofVector4.ceil(),Vector4.floor() orVector4.round() to this constructor instead.
Vector4iVector4i(x:int, y:int, z:int, w:int)
Returns aVector4i with the given components.
Method Descriptions
Returns a new vector with all components in absolute values (i.e. positive).
Vector4iclamp(min:Vector4i, max:Vector4i)const🔗
Returns a new vector with all components clamped between the components ofmin
andmax
, by running@GlobalScope.clamp() on each component.
Vector4iclampi(min:int, max:int)const🔗
Returns a new vector with all components clamped betweenmin
andmax
, by running@GlobalScope.clamp() on each component.
intdistance_squared_to(to:Vector4i)const🔗
Returns the squared distance between this vector andto
.
This method runs faster thandistance_to(), so prefer it if you need to compare vectors or need the squared distance for some formula.
floatdistance_to(to:Vector4i)const🔗
Returns the distance between this vector andto
.
Returns the length (magnitude) of this vector.
Returns the squared length (squared magnitude) of this vector.
This method runs faster thanlength(), so prefer it if you need to compare vectors or need the squared distance for some formula.
Vector4imax(with:Vector4i)const🔗
Returns the component-wise maximum of this andwith
, equivalent toVector4i(maxi(x,with.x),maxi(y,with.y),maxi(z,with.z),maxi(w,with.w))
.
Returns the axis of the vector's highest value. SeeAXIS_*
constants. If all components are equal, this method returnsAXIS_X.
Returns the component-wise maximum of this andwith
, equivalent toVector4i(maxi(x,with),maxi(y,with),maxi(z,with),maxi(w,with))
.
Vector4imin(with:Vector4i)const🔗
Returns the component-wise minimum of this andwith
, equivalent toVector4i(mini(x,with.x),mini(y,with.y),mini(z,with.z),mini(w,with.w))
.
Returns the axis of the vector's lowest value. SeeAXIS_*
constants. If all components are equal, this method returnsAXIS_W.
Returns the component-wise minimum of this andwith
, equivalent toVector4i(mini(x,with),mini(y,with),mini(z,with),mini(w,with))
.
Returns a new vector with each component set to1
if it's positive,-1
if it's negative, and0
if it's zero. The result is identical to calling@GlobalScope.sign() on each component.
Vector4isnapped(step:Vector4i)const🔗
Returns a new vector with each component snapped to the closest multiple of the corresponding component instep
.
Vector4isnappedi(step:int)const🔗
Returns a new vector with each component snapped to the closest multiple ofstep
.
Operator Descriptions
booloperator !=(right:Vector4i)🔗
Returnstrue
if the vectors are not equal.
Vector4ioperator %(right:Vector4i)🔗
Gets the remainder of each component of theVector4i with the components of the givenVector4i. This operation uses truncated division, which is often not desired as it does not work well with negative numbers. Consider using@GlobalScope.posmod() instead if you want to handle negative numbers.
print(Vector4i(10,-20,30,-40)%Vector4i(7,8,9,10))# Prints (3, -4, 3, 0)
Vector4ioperator %(right:int)🔗
Gets the remainder of each component of theVector4i with the givenint. This operation uses truncated division, which is often not desired as it does not work well with negative numbers. Consider using@GlobalScope.posmod() instead if you want to handle negative numbers.
print(Vector4i(10,-20,30,-40)%7)# Prints (3, -6, 2, -5)
Vector4ioperator *(right:Vector4i)🔗
Multiplies each component of theVector4i by the components of the givenVector4i.
print(Vector4i(10,20,30,40)*Vector4i(3,4,5,6))# Prints (30, 80, 150, 240)
Vector4operator *(right:float)🔗
Multiplies each component of theVector4i by the givenfloat.
Returns a Vector4 value due to floating-point operations.
print(Vector4i(10,20,30,40)*2)# Prints (20.0, 40.0, 60.0, 80.0)
Vector4ioperator *(right:int)🔗
Multiplies each component of theVector4i by the givenint.
Vector4ioperator +(right:Vector4i)🔗
Adds each component of theVector4i by the components of the givenVector4i.
print(Vector4i(10,20,30,40)+Vector4i(3,4,5,6))# Prints (13, 24, 35, 46)
Vector4ioperator -(right:Vector4i)🔗
Subtracts each component of theVector4i by the components of the givenVector4i.
print(Vector4i(10,20,30,40)-Vector4i(3,4,5,6))# Prints (7, 16, 25, 34)
Vector4ioperator /(right:Vector4i)🔗
Divides each component of theVector4i by the components of the givenVector4i.
print(Vector4i(10,20,30,40)/Vector4i(2,5,3,4))# Prints (5, 4, 10, 10)
Vector4operator /(right:float)🔗
Divides each component of theVector4i by the givenfloat.
Returns a Vector4 value due to floating-point operations.
print(Vector4i(10,20,30,40)/2)# Prints (5.0, 10.0, 15.0, 20.0)
Vector4ioperator /(right:int)🔗
Divides each component of theVector4i by the givenint.
booloperator <(right:Vector4i)🔗
Compares twoVector4i vectors by first checking if the X value of the left vector is less than the X value of theright
vector. If the X values are exactly equal, then it repeats this check with the Y values of the two vectors, Z values of the two vectors, and then with the W values. This operator is useful for sorting vectors.
booloperator <=(right:Vector4i)🔗
Compares twoVector4i vectors by first checking if the X value of the left vector is less than or equal to the X value of theright
vector. If the X values are exactly equal, then it repeats this check with the Y values of the two vectors, Z values of the two vectors, and then with the W values. This operator is useful for sorting vectors.
booloperator ==(right:Vector4i)🔗
Returnstrue
if the vectors are exactly equal.
booloperator >(right:Vector4i)🔗
Compares twoVector4i vectors by first checking if the X value of the left vector is greater than the X value of theright
vector. If the X values are exactly equal, then it repeats this check with the Y values of the two vectors, Z values of the two vectors, and then with the W values. This operator is useful for sorting vectors.
booloperator >=(right:Vector4i)🔗
Compares twoVector4i vectors by first checking if the X value of the left vector is greater than or equal to the X value of theright
vector. If the X values are exactly equal, then it repeats this check with the Y values of the two vectors, Z values of the two vectors, and then with the W values. This operator is useful for sorting vectors.
Access vector components using theirindex
.v[0]
is equivalent tov.x
,v[1]
is equivalent tov.y
,v[2]
is equivalent tov.z
, andv[3]
is equivalent tov.w
.
Returns the same value as if the+
was not there. Unary+
does nothing, but sometimes it can make your code more readable.
Returns the negative value of theVector4i. This is the same as writingVector4i(-v.x,-v.y,-v.z,-v.w)
. This operation flips the direction of the vector while keeping the same magnitude.