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 value is less than min, min will be returned. If value is more than max, max will be returned. Otherwise, value will 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 scale which is optional. If not passed. MathUtils.scale will 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 a and b is less than epsilon.
  • Passing epsilon is optional. If not passed, MathUtils.epsilon will be used.

sign(n: number): number

  • Returns one of [-1, 0, 1] to indicate the sign of n.

lerp(a: number, b: number, t: number): number

  • Returns the linear interpolation between a and b at time t.
  • t is a value representing a period in time where 0 will return a (start) and 1 will return b end.
  • Important t is not clamped, the linear period can be extended beyond bounds.

randomInt(min: number, max: number): number

  • Returns a random whole number in the range min to max, bounds inclusive.

randomFloat(min: number, max: number): number

  • Returns a random floating point value in the range min to max, 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.