MathUtils

An utility class for mathematical operations.

Constructor

new MathUtils()

Methods

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

Clamps the value to be between min and max.
Parameters:
NameTypeDescription
valueNumberValue to be clamped.
minNumberThe minimum value.
maxNumberThe maximum value.
Returns:
- The clamped value.
Type: 
Number

(static) denormalize(value, array) → {Number}

Denormalizes a value based on the type of the provided array.
Parameters:
NameTypeDescription
valueNumberThe value to be denormalized.
arrayTypedArrayThe typed array to determine the normalization factor.
Throws:
- Throws an error if the array type is invalid.
Type
Error
Returns:
- The denormalized value.
Type: 
Number

(static) euclideanModulo(n, m) → {Number}

Compute euclidean modulo of m % n. Refer to: https://en.wikipedia.org/wiki/Modulo_operation
Parameters:
NameTypeDescription
nNumberThe dividend.
mNumberThe divisor.
Returns:
- The result of the modulo operation.
Type: 
Number

(static) generateUUID() → {String}

Method for generate uuid. http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/21963136#21963136
Returns:
- The uuid.
Type: 
String

(static) isPowerOfTwo(value) → {Boolean}

Is this number a power of two.
Parameters:
NameTypeDescription
valueNumberThe input number.
Returns:
- Is this number a power of two.
Type: 
Boolean

(static) lerp(x, y, t) → {Number}

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.
Parameters:
NameTypeDescription
xNumberThe first value.
yNumberThe second value.
tNumberThe interpolation factor.
Returns:
- The interpolated value.
Type: 
Number

(static) nearestPowerOfTwo(value) → {Number}

Return the nearest power of two number of this number.
Parameters:
NameTypeDescription
valueNumberThe input number.
Returns:
- The result number.
Type: 
Number

(static) nextPowerOfTwo(value) → {Number}

Return the next power of two number of this number.
Parameters:
NameTypeDescription
valueNumberThe input number.
Returns:
- The result number.
Type: 
Number

(static) normalize(value, array) → {Number}

Normalizes a value based on the type of the provided array.
Parameters:
NameTypeDescription
valueNumberThe value to be normalized.
arrayTypedArrayThe typed array to determine the normalization factor.
Throws:
- Throws an error if the array type is invalid.
Type
Error
Returns:
- The normalized value.
Type: 
Number