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
valuenumber

Value to be clamped.

minnumber

The minimum value.

maxnumber

The 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
valuenumber

The value to be denormalized.

arrayTypedArray

The 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
nnumber

The dividend.

mnumber

The divisor.

Returns:
  • The result of the modulo operation.
Type: 
number

(static) fromHalfFloat(val) → {number}

Converts half float to float.

Parameters:
NameTypeDescription
valnumber

The half float value.

Returns:
  • The float value.
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
valuenumber

The 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
xnumber

The first value.

ynumber

The second value.

tnumber

The interpolation factor.

Returns:
  • The interpolated value.
Type: 
number

(static) nearestPowerOfTwo(value) → {number}

Return the nearest power of two number of this number.

Parameters:
NameTypeDescription
valuenumber

The input number.

Returns:
  • The result number.
Type: 
number

(static) nextPowerOfTwo(value) → {number}

Return the next power of two number of this number.

Parameters:
NameTypeDescription
valuenumber

The input number.

Returns:
  • The result number.
Type: 
number

(static) nextPowerOfTwoSquareSize(value) → {number}

Return the next power of two square size of this number. This method is usually used to calculate the minimum 2d texture size based on the pixel length.

Parameters:
NameTypeDescription
valuenumber

The input number.

Returns:
  • The result size.
Type: 
number

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

Normalizes a value based on the type of the provided array.

Parameters:
NameTypeDescription
valuenumber

The value to be normalized.

arrayTypedArray

The 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

(static) toHalfFloat(val) → {number}

Converts float to half float.

Parameters:
NameTypeDescription
valnumber

The float value.

Returns:
  • The half float value.
Type: 
number