Skip to content

Vector2int16

Supported Datatype

Represents a Vector2 with signed 16-bit integers for components.

Description

The Vector2int16 data type represents a vector in 2D space with a signed 16-bit integer for its components. It is similar to Vector2 in that it allows for the same arithmetic operations, but it lacks commonly used vector functions.

Vector2int16 should not be confused with:

  • Vector2, a more precise and complete implementation for 2D vectors.
  • Vector3int16, a similar implementation for 3D vectors.

For each component:

  • The lower bound is -215, or -32,768.
  • The upper bound is 215 − 1, or 32,767.

Converting to Vector2

To convert a Vector2int16 to a Vector2, construct a Vector2 by passing each component of the Vector2int16 to Vector2.new():

local vector2int16 = Vector2int16.new(1, 2)
local vector2 = Vector2.new(vector2int16.X, vector2int16.Y)
print(vector2)  --> 1, 2

Do not pass an entire Vector2int16 to Vector2.new(), as the constructor interprets a Vector2int16 as a 0 within its parameters without producing an error. This can lead to silent logic errors if you do something like:

local vector2int16 = Vector2int16.new(1, 2)
local vector2 = Vector2.new(vector2int16)
print(vector2)  --> 0, 0

Math Operations

The following math operations are valid for the Vector2int16 data type. For all operations, be mindful of the bounds associated with signed 16-bit integers, described earlier.

Operation Description
Datatype.Vector2int16 + Datatype.Vector2int16 Produces a Datatype.Vector2int16 whose components are the sum of the operands' respective components.
Datatype.Vector2int16 - Datatype.Vector2int16 Produces a Datatype.Vector2int16 whose components are the difference of the operands' respective components.
Datatype.Vector2int16 * Datatype.Vector2int16 Produces a Datatype.Vector2int16 whose components are the product of the operands' respective components.
Datatype.Vector2int16 / Datatype.Vector2int16 Produces a Datatype.Vector2int16 whose components are the quotient of the operands' respective components. The results of the division are rounded down.
Datatype.Vector2int16 * number Produces a Datatype.Vector2int16 whose components are the product of the respective Datatype.Vector2int16 components and the number (factor). This operation is commutative.
Datatype.Vector2int16 / number Produces a Datatype.Vector2int16 whose components are the quotient of the respective Datatype.Vector2int16 components and the number (divisor). The results of the division are rounded toward zero.

Constructors

new Supported Returns a Vector2int16 from the given x and y components.
Vector2int16.new(x: number, y: number)

Returns a Vector2int16 from the given x and y components.

Returns a new Vector2int16 given the x and y components. Non-integer components are rounded down.

The components must fall within the range [-215, 215). If outside this range, integer overflow may occur. For example, providing 32,768 (equal to 215) as a component overflows the 16-bit integer, and so the component is -32,768 (equal to -215) instead.

Properties

X Supported The x-coordinate of the Vector2int16.
Vector2int16.X()

The x-coordinate of the Vector2int16.

The x-coordinate of the Vector2int16, also accessible in its lower-case variant.

Y Supported The y-coordinate of the Vector2int16.
Vector2int16.Y()

The y-coordinate of the Vector2int16.

The y-coordinate of the Vector2int16, also accessible in its lower-case variant.

Math operations

+ Check Produces a Vector2int16 whose components are the sum of the operands' respective components.
+: Vector2int16

Produces a Vector2int16 whose components are the sum of the operands' respective components. Be mindful of the bounds associated with signed 16-bit integers, described earlier.

operator
- Check Produces a Vector2int16 whose components are the difference of the operands' respective components.
-: Vector2int16

Produces a Vector2int16 whose components are the difference of the operands' respective components. Be mindful of the bounds associated with signed 16-bit integers, described earlier.

operator
* Check Produces a Vector2int16 whose components are the product of the operands' respective components.
*: Vector2int16

Produces a Vector2int16 whose components are the product of the operands' respective components. Be mindful of the bounds associated with signed 16-bit integers, described earlier.

operator
/ Check Produces a Vector2int16 whose components are the quotient of the operands' respective components.
/: Vector2int16

Produces a Vector2int16 whose components are the quotient of the operands' respective components. The results of the division are rounded down. Be mindful of the bounds associated with signed 16-bit integers, described earlier.

operator
* Check Produces a Vector2int16 whose components are the product of the respective Vector2int16 components and the number (fact…
*: Vector2int16

Produces a Vector2int16 whose components are the product of the respective Vector2int16 components and the number (factor). This operation is commutative. Be mindful of the bounds associated with signed 16-bit integers, described earlier.

operator
/ Check Produces a Vector2int16 whose components are the quotient of the respective Vector2int16 components and the number (div…
/: Vector2int16

Produces a Vector2int16 whose components are the quotient of the respective Vector2int16 components and the number (divisor). The results of the division are rounded toward zero. Be mindful of the bounds associated with signed 16-bit integers, described earlier.

operator

Nova binding inventory

Library Members
new X, Y, x, y

Roblox reference: Vector2int16