Math

The class that encompasses some useful static mathematical methods.

Constructor

new Math()

Classes

Noise
SeededRandom

Methods

(static) clamp(value, min, max) → {number}

Method to clamp a value between a range.

Parameters:
NameTypeDescription
valuenumber

Value to clamp.

minnumber

Minimum.

maxnumber

Maximum.

Returns:

Original value if it is not clamped.

Type: 
number

(static) degrees(degrees) → {number}

Method to convert radians to cartesian degrees.

Parameters:
NameTypeDescription
degreesnumber

The amount of radians to convert.

Returns:
Type: 
number

(static) dist(x1, y1, x2, y2) → {number}

Method to get the distance between two 2D points.

Parameters:
NameTypeDescription
x1number

X-coordinate of the first point.

y1number

Y-coordinate of the first point.

x2number

X-coordinate of the second point.

y2number

Y-coordinate of the second point.

Returns:
Type: 
number

(static) lerp(start, end, amt) → {number}

Linear interpolation method.

Parameters:
NameTypeDescription
startnumber

Value to interpolate from.

endnumber

Value to interpolate to.

amtnumber

Amount to interpolate by.

Returns:
Type: 
number

(static) map(value, valLow, valHigh, resLow, resHigh) → {number}

Method to map a number to another range.

Parameters:
NameTypeDescription
valuenumber

The value to map.

valLownumber

The minimum of value.

valHighnumber

The maximum of value.

resLownumber

The minimum value of the result.

resHighnumber

The maximum value of the result.

Returns:
Type: 
number

(static) radians(degrees) → {number}

Method to convert cartesian degrees to radians.

Parameters:
NameTypeDescription
degreesnumber

The amount of degrees to convert.

Returns:
Type: 
number

(static) random(low, high) → {number}

Utility method to get a random floating point value in a range, instead of 'Math.random' which only does 0-1.

Parameters:
NameTypeDefaultDescription
lownumber0

The minimum resulting value (inclusive).

highnumber1

The maximum resulting value (exclusive).

Returns:
Type: 
number

(static) randomInt(low, high) → {number}

Utility method to get a random integer in a range, instead of 'Math.random' which only does floats 0-1.

Parameters:
NameTypeDefaultDescription
lownumber0

The minimum resulting value (inclusive).

highnumber1

The maximum resulting value (exclusive).

Returns:
Type: 
number

(static) rectCircleCollision(rectPos, rectSize, circleCenter, circleRadius) → {boolean}

Method to check for a collision between an axis-aligned rectangle and a circle.

Parameters:
NameTypeDescription
rectPosglMatrix.vec2

Position of the rectangle.

rectSizeglMatrix.vec2

Size of the rectangle.

circleCenterglMatrix.vec2

Position of the center of the circle.

circleRadiusnumber

Radius of the circle.

Returns:

true if colliding.

Type: 
boolean

(static) rectRectCollision(vectorA, sizeA, vectorB, sizeB) → {boolean}

Method to check for a collision between two axis-aligned rectangles.

Parameters:
NameTypeDescription
vectorAglMatrix.vec2

Position of the first rectangle.

sizeAglMatrix.vec2

Size of the first rectangle.

vectorBglMatrix.vec2

Position of the second rectangle.

sizeBglMatrix.vec2

Size of the second rectangle.

Returns:

true if colliding.

Type: 
boolean

(static) wrap(value, min, max) → {number}

Method to wrap a value once it is too big or small.

Parameters:
NameTypeDescription
valuenumber

Value to wrap.

minnumber

Minimum to wrap around.

maxnumber

Maximum to wrap around.

Returns:

Original value if it is not wrapped.

Type: 
number