Namespace: math
Interfaces
Variables
DEG_TO_RAD_FACTOR
• Const
DEG_TO_RAD_FACTOR: number
Constant for PI / 180 which can be used to convert degrees to radians.
EPSILON
• Const
EPSILON: 0.00001
Constant for a very small floating point value. Used to determine if the result of floating point math is “close enough” to be considered zero.
PI2
• Const
PI2: number
Constant for 2π, ie. a full circle in radians.
RAD_TO_DEG_FACTOR
• Const
RAD_TO_DEG_FACTOR: number
Constant for 180 / PI which can be used to convert radians to degrees.
Functions
add
▸ add(u
, v
): Point
Adds other vector to another.
Parameters
Name | Type | Description |
---|---|---|
u |
Point |
Left hand side vector |
v |
Point |
Right hand side vector |
Returns
angleBetweenVectors
▸ angleBetweenVectors(u
, v
): number
| null
Returns unsigned angle between vectors in radians.
Parameters
Name | Type | Description |
---|---|---|
u |
Point |
Left hand side vector |
v |
Point |
Right hand side vector |
Returns
number
| null
angularDistance
▸ angularDistance(from
, to
): number
Returns signed angular distance between two angles in the range from -π to π.
Parameters
Name | Type | Description |
---|---|---|
from |
number |
Start angle |
to |
number |
End angle |
Returns
number
clamp
▸ clamp(value
, min
, max
): number
Clamps a number between min (inclusive) and max (inclusive).
Parameters
Name | Type | Description |
---|---|---|
value |
number |
Value to clamp |
min |
number |
Minimum limit |
max |
number |
Maximum limit |
Returns
number
createVec2
▸ createVec2(x
, y
): Point
Creates a 2d vector from params.
Parameters
Name | Type | Description |
---|---|---|
x |
number |
X coordinate |
y |
number |
Y coordinate |
Returns
cross
▸ cross(u
): Point
Takes a 2d cross product from vector u, ie. rotates it to the left by 90 degrees.
Parameters
Name | Type | Description |
---|---|---|
u |
Point |
Vector to take cross product from |
Returns
crossProduct
▸ crossProduct(u
, v
): Vector3
Returns cross product of 2 vectors.
Parameters
Name | Type | Description |
---|---|---|
u |
Point | Vector3 |
Left hand side Vector3 or Point |
v |
Point | Vector3 |
Right hand side Vector3 or Point |
Returns
degToRad
▸ degToRad(degrees
): number
Converts the specified value to radians.
Parameters
Name | Type | Description |
---|---|---|
degrees |
number |
The value to be converted in degrees |
Returns
number
distance
▸ distance(u
, v
): number
Returns distance between two points.
Parameters
Name | Type | Description |
---|---|---|
u |
Point |
First point |
v |
Point |
Second point |
Returns
number
div
▸ div(u
, v
): Point
Divides the vectors component-wise.
Parameters
Name | Type | Description |
---|---|---|
u |
Point |
Vector to divide |
v |
Point |
Vector to divide with |
Returns
dot
▸ dot(u
, v
): number
Calculates 2d dot product between the two vectors.
Parameters
Name | Type | Description |
---|---|---|
u |
Point |
Left hand side vector |
v |
Point |
Right hand side vector |
Returns
number
equal
▸ equal(u
, v
): boolean
Returns true if values are close enough to each other using math.EPSILON
.
Parameters
Name | Type | Description |
---|---|---|
u |
number |
First value |
v |
number |
Second value |
Returns
boolean
getZeroVec2
▸ getZeroVec2(): Point
Returns a zero 2d vector.
Returns
hexDistance
▸ hexDistance(start
, dest
): number
Returns the hexagonal “manhattan” distance between two hexagons denoted by 2d vectors.
Parameters
Name | Type | Description |
---|---|---|
start |
Point |
Start hexagon |
dest |
Point |
Destination hexagon |
Returns
number
length
▸ length(u
): number
Calculates the length of a vector.
Parameters
Name | Type | Description |
---|---|---|
u |
Point |
Vector to get the length from |
Returns
number
lerp
▸ lerp(target
, start
, t
): Point
Interpolates between start and target point.
Parameters
Name | Type | Description |
---|---|---|
target |
Point |
Target of the interpolation |
start |
Point |
Start of the interpolation |
t |
number |
Interpolation value |
Returns
mul
▸ mul(u
, v
): Point
Multiplies the vector component-wise.
Parameters
Name | Type | Description |
---|---|---|
u |
Point |
Left hand side vector |
v |
Point |
Right hand side vector |
Returns
mulScalar
▸ mulScalar(u
, scalar
): Point
Multiplies u with scalar, ie. scales the vector.
Parameters
Name | Type | Description |
---|---|---|
u |
Point |
Vector to scale |
scalar |
number |
Scale factor |
Returns
neg
▸ neg(u
): Point
Negates a vector.
Parameters
Name | Type | Description |
---|---|---|
u |
Point |
Vector to negate |
Returns
normalize
▸ normalize(v
): Point
Returns a normalized vector from vector. If the vector has zero length the return value will be a zero vector.
Parameters
Name | Type | Description |
---|---|---|
v |
Point |
Vector to normalize |
Returns
perpDot
▸ perpDot(uPerp
, v
): number
Calculates perpendicular 2d dot product between the two vectors.
Parameters
Name | Type | Description |
---|---|---|
uPerp |
Point |
Left hand side vector u is replaced by the perpendicular vector rotated 90 degrees to the left |
v |
Point |
Right hand side vector |
Returns
number
perpDot2
▸ perpDot2(u
, vPerp
): number
Calculates perpendicular 2d dot product between the two vectors.
Parameters
Name | Type | Description |
---|---|---|
u |
Point |
Left hand side vector u |
vPerp |
Point |
Right hand side vector v which is rotated 90 degrees to the left |
Returns
number
radToDeg
▸ radToDeg(radians
): number
Converts the specified value to degrees.
Parameters
Name | Type | Description |
---|---|---|
radians |
number |
The value to be converted in radians |
Returns
number
signedAngle
▸ signedAngle(u
, v
): number
| null
Returns signed angle between vectors in radians.
Parameters
Name | Type | Description |
---|---|---|
u |
Point |
Left hand side vector |
v |
Point |
Right hand side vector |
Returns
number
| null
sub
▸ sub(u
, v
): Point
Subtracts other vector from another.
Parameters
Name | Type | Description |
---|---|---|
u |
Point |
Vector from which is subtracted |
v |
Point |
Vector that is subtracted |
Returns
unsignedMod
▸ unsignedMod(a
, n
): number
Unsigned modulo function. The default modulo function returns negative values for negative
numbers whereas this function returns positive ones. For example -1 % 10 = 9
instead of the
default -1 % 10 = -1
.
Parameters
Name | Type | Description |
---|---|---|
a |
number |
Dividend |
n |
number |
Divisor |
Returns
number
vectorsEqual
▸ vectorsEqual(u
, v
): boolean
Compares if the vectors are equal.
Parameters
Name | Type | Description |
---|---|---|
u |
Point |
Left hand side 2d vector to compare |
v |
Point |
Right hand side 2d vector to compare |
Returns
boolean