Namespace: Math

me. Math

a collection of math utility functions
Source:
math.js, line 9

Methods

<static> clamp(val, low, high) → {number}

clamp the given value
Parameters:
Name Type Description
val number the value to clamp
low number lower limit
high number higher limit
Source:
math.js, line 93
Returns:
clamped value
Type
number

<static> degToRad(angle) → {number}

Converts an angle in degrees to an angle in radians
Parameters:
Name Type Description
angle number angle in degrees
Source:
math.js, line 61
Returns:
corresponding angle in radians
Type
number
Example
// convert a specific angle
me.Math.degToRad(60); // return 1.0471...

<static> isPowerOfTwo(val) → {boolean}

returns true if the given value is a power of two
Parameters:
Name Type Description
val Number
Source:
math.js, line 28
Returns:
Type
boolean

<static> nextPowerOfTwo(val) → {boolean}

returns the next power of two for the given value
Parameters:
Name Type Description
val Number
Source:
math.js, line 41
Returns:
Type
boolean

<static> radToDeg(radians) → {number}

Converts an angle in radians to an angle in degrees.
Parameters:
Name Type Description
radians number angle in radians
Source:
math.js, line 77
Returns:
corresponding angle in degrees
Type
number
Example
// convert a specific angle
me.Math.radToDeg(1.0471975511965976); // return 60

<static> random(min, max) → {number}

return a random integer between min (included) and max (excluded)
Parameters:
Name Type Description
min number minimum value.
max number maximum value.
Source:
math.js, line 108
Returns:
random value
Type
number
Example
// Print a random number; one of 5, 6, 7, 8, 9
console.log(me.Math.random(5, 10) );

<static> randomFloat(min, max) → {number}

return a random float between min, max (exclusive)
Parameters:
Name Type Description
min number minimum value.
max number maximum value.
Source:
math.js, line 125
Returns:
random value
Type
number
Example
// Print a random number; one of 5, 6, 7, 8, 9
console.log(me.Math.randomFloat(5, 10) );

<static> weightedRandom(min, max) → {number}

return a weighted random between min, max (exclusive)
Parameters:
Name Type Description
min number minimum value.
max number maximum value.
Source:
math.js, line 142
Returns:
random value
Type
number
Example
// Print a random number; one of 5, 6, 7, 8, 9
console.log(me.Math.weightedRandom(5, 10) );

<static> weightedRandom(num, dec) → {number}

round a value to the specified number of digit
Parameters:
Name Type Argument Default Description
num number value to be rounded.
dec number <optional>
0 number of decimal digit to be rounded to.
Source:
math.js, line 159
Returns:
rounded value
Type
number
Example
// round a specific value to 2 digits
me.Math.round(10.33333, 2); // return 10.33