Vec
Source: classes.
Represents a 2D vector.
Child class
Property
new Vec(x, y)
Creates a new vector. Can also be done with constructors.V.
Parameters
Name | Type | Optional | Description |
---|---|---|---|
x |
|
|
The x component |
y |
|
|
The y component |
- Returns
Class
Vec
Property
size
Gets the size of the vector
- Returns
-
number
Methods
add(other) → Vec
Add another vector to this one
Parameter
Name | Type | Optional | Description |
---|---|---|---|
other |
|
The other vector |
- Returns
-
A new vector
adj() → Array of Vec
Gets a list of the four adjacent vectors to this one
- Returns
-
Array of Vec
clone() → Vec
Clones the vector
- Returns
div(factor) → Vec
Divides this vector by factor
Parameter
Name | Type | Optional | Description |
---|---|---|---|
factor |
number |
|
The factor to divide by |
- Returns
-
A new vector
down() → Vec
Moves the vector down by 1 unit using Vec.downn
- Returns
-
The new vector
downn(n) → Vec
Moves the vector down by n
units (increases y
), in place.
Parameter
Name | Type | Optional | Description |
---|---|---|---|
n |
number |
|
The number of units to move |
- Returns
-
The new vector
left() → Vec
Moves the vector left by 1 unit using Vec.leftn
- Returns
-
The new vector
leftn(n) → Vec
Moves the vector left by n
units (decreases x
), in place.
Parameter
Name | Type | Optional | Description |
---|---|---|---|
n |
number |
|
The number of units to move |
- Returns
-
The new vector
mul(factor) → Vec
Multiplies this vector by factor
Parameter
Name | Type | Optional | Description |
---|---|---|---|
factor |
number |
|
The factor to multiply by |
- Returns
-
A new vector
on(grid) → T
Gets the cell at this vector on grid
Parameter
Name | Type | Optional | Description |
---|---|---|---|
grid |
Array of Array of T |
|
The grid to get the cell from |
- Returns
-
T
right() → Vec
Moves the vector right by 1 unit using Vec.rightn
- Returns
-
The new vector
rightn(n) → Vec
Moves the vector right by n
units (increases x
), in place.
Parameter
Name | Type | Optional | Description |
---|---|---|---|
n |
number |
|
The number of units to move |
- Returns
-
The new vector
sub(other) → Vec
Subtract another vector from this one
Parameter
Name | Type | Optional | Description |
---|---|---|---|
other |
|
The other vector |
- Returns
-
A new vector
up() → Vec
Moves the vector up by 1 unit using Vec.upn
- Returns
-
The new vector
upn(n) → Vec
Moves the vector up by n
units (decreases y
), in place.
Parameter
Name | Type | Optional | Description |
---|---|---|---|
n |
number |
|
The number of units to move |
- Returns
-
The new vector