Foundation.MathUtils
A collection of commonly needed math helper functions.
Implementation Details
Reference paths
'/foundation/_digest.ts''/foundation/core/math/_digest.ts''/foundation/core/math/MathUtils.ts'
Extends
This type does not extend a base type.
Implements
This type does not implement any interfaces.
Public Properties (Static)
static epsilon: number = 0.00001;
- Value used to check for close comparison between 2 floating point values.
static scale: number = 10000;
- When using the
precisionRound()function, this is the default value used to determine the precision which numbers should be rounded to.
Static Functions
clamp(value: number, min: number, max: number): number
- If
valueis less thanmin,minwill be returned. Ifvalueis more thanmax,maxwill be returned. Otherwise,valuewill be returned.
precisionRound(num: number, scale: number = MathUtils.scale): number
- Converts a Float32 number to a standard safe precision.
- The number of points of precision is determined by
scalewhich is optional. If not passed.MathUtils.scalewill be used.
distance(a: number, b: number): number
- Returns the absolute distance between 2 numbers.
virtuallyEqual(a: number, b: number, epsilon: number = MathUtils.epsilon): boolean
- Returns true if the distance between
aandbis less thanepsilon. - Passing
epsilonis optional. If not passed,MathUtils.epsilonwill be used.
sign(n: number): number
- Returns one of [
-1,0,1] to indicate the sign ofn.
lerp(a: number, b: number, t: number): number
- Returns the linear interpolation between
aandbat timet. tis a value representing a period in time where0will returna(start) and1will returnbend.- Important
tis not clamped, the linear period can be extended beyond bounds.
randomInt(min: number, max: number): number
- Returns a random whole number in the range
mintomax, bounds inclusive.
randomFloat(min: number, max: number): number
- Returns a random floating point value in the range
mintomax, bounds inclusive. - Precision is not guaranteed.
toDegrees(rads: number): number
- Converts a radian value to degrees.
toRadians(degs: number): number
- Converts a degrees value to radians.