Vector2

A vector that holds 2 numbers
Can be created using functions in the "vectors" api
Meta name Allowed other parameters Meta execution method
__le
  • Vector2
x <= y
__lt
  • Vector2
x < y
__len
#x
__unm
-x
__eq
  • Vector2
x == y
__mod
  • Number
  • Vector2
x % y
__div
  • Number
  • Vector2
x / y
__mul
  • Number
  • Vector2
  • Matrix2
x * y
__add
  • Vector2
  • Number
x + y
__sub
  • Vector2
  • Number
x - y

Vector2.add

Adds the given vector or values to this one, and returns self for chaining
overload 1:
Vector2:add(vec)
Method Property Fluent Description Representation
vec accepts a Vector2
Return Value a Vector2
overload 2:
Vector2:add(x, y)
Method Property Fluent Description Representation
x accepts a Number
y accepts a Number
Return Value a Vector2

Vector2.length

Returns the length of this vector
overload 1:
Vector2:length()
Method Property Fluent Description Representation
Return Value a Number

Vector2.floor

Returns a copy of this vector with its values rounded down
overload 1:
Vector2:floor()
Method Property Fluent Description Representation
Return Value a Vector2

Vector2.ceil

Returns a copy of this vector with its values rounded up
overload 1:
Vector2:ceil()
Method Property Fluent Description Representation
Return Value a Vector2

Vector2.scale

Scales this vector by the given factor, and returns self for chaining
overload 1:
Vector2:scale(factor)
Method Property Fluent Description Representation
factor accepts a Number
Return Value a Vector2

Vector2.offset

Offsets this vector by the given factor, adding the factor to all components, and returns self for chaining
overload 1:
Vector2:offset(factor)
Method Property Fluent Description Representation
factor accepts a Number
Return Value a Vector2

Vector2.transform

Transforms this vector by the given matrix, and returns self for chaining
overload 1:
Vector2:transform(mat)
Method Property Fluent Description Representation
mat accepts a Matrix2
Return Value a Vector2

Vector2.dot

Returns the dot product of this vector with the other
overload 1:
Vector2:dot(vec)
Method Property Fluent Description Representation
vec accepts a Vector2
Return Value a Number

Vector2.set

Sets this vector to have the given values
Nil values are treated as zero
Returns self for chaining
overload 1:
Vector2:set(vec)
Method Property Fluent Description Representation
vec accepts a Vector2
Return Value a Vector2
overload 2:
Vector2:set(x, y)
Method Property Fluent Description Representation
x accepts a Number
y accepts a Number
Return Value a Vector2

Vector2.copy

Creates and returns a copy of this vector
overload 1:
Vector2:copy()
Method Property Fluent Description Representation
Return Value a Vector2

Vector2.normalize

Modifies this vector so that its length is 1 unless its length was originally 0
Returns self for chaining
overload 1:
Vector2:normalize()
Method Property Fluent Description Representation
Return Value a Vector2

Vector2.reset

Resets this vector back to being all zeroes, and returns itself for chaining
overload 1:
Vector2:reset()
Method Property Fluent Description Representation
Return Value a Vector2

Vector2.reduce

Reduces this vector modulo the given vector or values, and returns self for chaining
overload 1:
Vector2:reduce(vec)
Method Property Fluent Description Representation
vec accepts a Vector2
Return Value a Vector2
overload 2:
Vector2:reduce(x, y)
Method Property Fluent Description Representation
x accepts a Number
y accepts a Number
Return Value a Vector2

Vector2.normalized

Returns a copy of this vector with length 1 unless its length was originally 0
overload 1:
Vector2:normalized()
Method Property Fluent Description Representation
Return Value a Vector2

Vector2.sub

Subtracts the given vector or values from this one, and returns self for chaining
overload 1:
Vector2:sub(vec)
Method Property Fluent Description Representation
vec accepts a Vector2
Return Value a Vector2
overload 2:
Vector2:sub(x, y)
Method Property Fluent Description Representation
x accepts a Number
y accepts a Number
Return Value a Vector2

Vector2.mul

Multiplies the given vector or values into this one, and returns self for chaining
overload 1:
Vector2:mul(vec)
Method Property Fluent Description Representation
vec accepts a Vector2
Return Value a Vector2
overload 2:
Vector2:mul(x, y)
Method Property Fluent Description Representation
x accepts a Number
y accepts a Number
Return Value a Vector2

Vector2.div

Divides this vector by the given vector or values, and returns self for chaining
overload 1:
Vector2:div(vec)
Method Property Fluent Description Representation
vec accepts a Vector2
Return Value a Vector2
overload 2:
Vector2:div(x, y)
Method Property Fluent Description Representation
x accepts a Number
y accepts a Number
Return Value a Vector2

Vector2.clamped

Returns a modified copy of this vector, with its length clamped from minLength to maxLength
If the vector has length zero,
then the copy does too
overload 1:
Vector2:clamped(minLength, maxLength)
Method Property Fluent Description Representation
minLength accepts a Number
maxLength accepts a Number
Return Value a Vector2

Vector2.lengthSquared

Returns the length of this vector squared
Suitable when you only care about relative lengths,
because it avoids a square root
overload 1:
Vector2:lengthSquared()
Method Property Fluent Description Representation
Return Value a Number

Vector2.toDeg

Returns a copy of this vector, in degrees
overload 1:
Vector2:toDeg()
Method Property Fluent Description Representation
Return Value a Vector2

Vector2.clampLength

Modifies this vector so that its length is between minLength and maxLength
If the vector has length zero,
it is unmodified
Returns self for chaining
overload 1:
Vector2:clampLength(minLength, maxLength)
Method Property Fluent Description Representation
minLength accepts a Number
maxLength accepts a Number
Return Value a Vector2

Vector2.toRad

Returns a copy of this vector, in radians
overload 1:
Vector2:toRad()
Method Property Fluent Description Representation
Return Value a Vector2

Vector2.applyFunc

Calls the given function on each element of this vector, and sets the values of the vector to the returns
The current index and its value is given as arguments of the function
Returns self for chaining
overload 1:
Vector2:applyFunc(func)
Method Property Fluent Description Representation
func accepts a function that takes a Number and an Integer and will return a Number
Return Value a Vector2

Vector2.x

The first coordinate of this vector
Can also be gotten with the indices "r" and [1]
field signature:
x
Method Property Fluent Description Representation
Field Type a Number

Vector2.y

The second coordinate of this vector
Can also be gotten with the indices "g" and [2]
field signature:
y
Method Property Fluent Description Representation
Field Type a Number
a a