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

int

w

0

int

x

0

int

y

0

int

z

0

Constructors

Vector4i

Vector4i()

Vector4i

Vector4i(from:Vector4i)

Vector4i

Vector4i(from:Vector4)

Vector4i

Vector4i(x:int, y:int, z:int, w:int)

Methods

Vector4i

abs()const

Vector4i

clamp(min:Vector4i, max:Vector4i)const

Vector4i

clampi(min:int, max:int)const

int

distance_squared_to(to:Vector4i)const

float

distance_to(to:Vector4i)const

float

length()const

int

length_squared()const

Vector4i

max(with:Vector4i)const

int

max_axis_index()const

Vector4i

maxi(with:int)const

Vector4i

min(with:Vector4i)const

int

min_axis_index()const

Vector4i

mini(with:int)const

Vector4i

sign()const

Vector4i

snapped(step:Vector4i)const

Vector4i

snappedi(step:int)const

Operators

bool

operator !=(right:Vector4i)

Vector4i

operator %(right:Vector4i)

Vector4i

operator %(right:int)

Vector4i

operator *(right:Vector4i)

Vector4

operator *(right:float)

Vector4i

operator *(right:int)

Vector4i

operator +(right:Vector4i)

Vector4i

operator -(right:Vector4i)

Vector4i

operator /(right:Vector4i)

Vector4

operator /(right:float)

Vector4i

operator /(right:int)

bool

operator <(right:Vector4i)

bool

operator <=(right:Vector4i)

bool

operator ==(right:Vector4i)

bool

operator >(right:Vector4i)

bool

operator >=(right:Vector4i)

int

operator [](index:int)

Vector4i

operator unary+()

Vector4i

operator unary-()


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

intw =0🔗

The vector's W component. Also accessible by using the index position[3].


intx =0🔗

The vector's X component. Also accessible by using the index position[0].


inty =0🔗

The vector's Y component. Also accessible by using the index position[1].


intz =0🔗

The vector's Z component. Also accessible by using the index position[2].


Constructor Descriptions

Vector4iVector4i()🔗

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

Vector4iabs()const🔗

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.


floatlength()const🔗

Returns the length (magnitude) of this vector.


intlength_squared()const🔗

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


intmax_axis_index()const🔗

Returns the axis of the vector's highest value. SeeAXIS_* constants. If all components are equal, this method returnsAXIS_X.


Vector4imaxi(with:int)const🔗

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


intmin_axis_index()const🔗

Returns the axis of the vector's lowest value. SeeAXIS_* constants. If all components are equal, this method returnsAXIS_W.


Vector4imini(with:int)const🔗

Returns the component-wise minimum of this andwith, equivalent toVector4i(mini(x,with),mini(y,with),mini(z,with),mini(w,with)).


Vector4isign()const🔗

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.


intoperator [](index:int)🔗

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.


Vector4ioperator unary+()🔗

Returns the same value as if the+ was not there. Unary+ does nothing, but sometimes it can make your code more readable.


Vector4ioperator unary-()🔗

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.


User-contributed notes

Please read theUser-contributed notes policy before submitting a comment.