Math

An object with several math utility functions.

Functions

# .angleToRange_0_2Pi (angle : Float) : Float

Wraps the given angle in radians to the range [0, 2π).

# .angleToRange_mPi_Pi (angle : Float) : Float

Wraps the given angle in radians to the range [-π, π).

# .clamp (value : Float, min : Float, max : Float) : Float

value — Value to be clamped.
min — Minimum value.
max — Maximum value.

Clamps the value to be between min and max.

# .euclideanModulo (n : Integer, m : Integer) : Integer

n, m - Integers

Computes the Euclidean modulo of m % n, that is: `((n % m) + m) % m`

# .generateUUID () : UUID

Generate a UUID (universally unique identifier).

# .isPowerOfTwo (n : Number) : Boolean

Return true if n is a power of 2.

# .lerp (x : Float, y : Float, t : Float) : Float

x - Start point.
y - End point.
t - interpolation factor in the closed interval [0, 1].

Returns a value linearly interpolated from two known points based on the given interval - t = 0 will return x and t = 1 will return y.

# .mapLinear (x : Float, a1 : Float, a2 : Float, b1 : Float, b2 : Float) : Float

x — Value to be mapped.
a1 — Minimum value for range A.
a2 — Maximum value for range A.
b1 — Minimum value for range B.
b2 — Maximum value for range B.

Linear mapping of x from range [a1, a2] to range [b1, b2].

# .ceilPowerOfTwo (n : Number) : Integer

Returns the smallest power of 2 that is greater than or equal to n.

# .floorPowerOfTwo (n : Number) : Integer

Returns the largest power of 2 that is less than or equal to n.

# .randFloat (low : Float, high : Float) : Float

Random float in the interval low to high.

# .randFloatSpread (range : Float) : Float

Random float in the interval *- range / 2* to *range / 2*.

# .randInt (low : Integer, high : Integer) : Integer

Random integer in the interval low to high.

# .smoothstep (x : Float, min : Float, max : Float) : Float

x - The value to evaluate based on its position between min and max.
min - Any x value below min will be 0.
max - Any x value above max will be 1.

Returns a value between 0-1 that represents the percentage that x has moved between min and max, but smoothed or slowed down the closer X is to the min and max.

See Smoothstep for details.

# .smootherstep (x : Float, min : Float, max : Float) : Float

x - The value to evaluate based on its position between min and max.
min - Any x value below min will be 0.
max - Any x value above max will be 1.

Returns a value between 0-1. A variation on smoothstep that has zero 1st and 2nd order derivatives at x=0 and x=1.