Vector2
A vector that holds 2 numbers
Can be created using functions in the "vectors" api
For this entire page assume:
local vec2 = vec(2, 5)
add(Vector2)
Adds the given vector or values to this one, and returns self for chaining
Example:
vec2:add(2, 0.5)
length()
Returns the length of this vector
Example:
vec2:length()
floor()
Returns a copy of this vector with its values rounded down
Example:
vec2:floor()
ceil()
Returns a copy of this vector with its values rounded up
Example:
vec2:ceil()
scale(Number)
Scales this vector by the given factor, and returns self for chaining
Example:
vec2:scale(2)
offset(Number)
Offsets this vector by the given factor, adding the factor to all components, and returns self for chaining
Example:
vec2:offset(2)
transform(Matrix2)
Transforms this vector by the given matrix, and returns self for chaining
Example:
vec2:transform(matrices.mat2())
dot(Vector2)
Returns the dot product of this vector with the other
Example:
vec2:dot(vec(2, 2))
set(Vector2)
Sets this vector to have the given values
Nil values are treated as zero
Returns self for chaining
Example:
vec2:set(10, 3)
copy()
Creates and returns a copy of this vector
Example:
vec2:copy()
normalize()
Modifies this vector so that its length is 1, unless its length was originally 0
Returns self for chaining
Example:
vec2:normalize()
reset()
Resets this vector back to being all zeroes, and returns itself for chaining
Example:
vec2:reset()
reduce(Vector2)
Reduces this vector modulo the given vector or values, and returns self for chaining
Example:
vec2:reduce(1, 0.5)
normalized()
Returns a copy of this vector with length 1, unless its length was originally 0
Example:
vec2:normalized()
sub(Vector2)
Subtracts the given vector or values from this one, and returns self for chaining
Example:
vec2:sub(1, 0.5)