dot big bang

Developer API
Menu

Interface MathUtils

All
  • Public
  • Public/Protected
  • All

Hierarchy

  • MathUtils

Index

Methods

clamp

  • clamp(value: number, min: number, max: number): number
  • Clamps the value to be between min and max.

    Parameters

    • value: number

      Value to be clamped.

    • min: number

      The minimum value.

    • max: number

      The maximum value.

    Returns number

degToRad

  • degToRad(degrees: number): number
  • Converts an angle expressed in degrees into radians.

    Parameters

    • degrees: number

      The angle in degrees to convert to radians.

    Returns number

euclideanModulo

  • euclideanModulo(n: number, m: number): number
  • Computes the Euclidean modulo of m % n, that is: ( ( n % m ) + m ) % m

    Parameters

    • n: number

      The dividend of the modulo operation.

    • m: number

      The divisor of the modulo operation.

    Returns number

isPowerOfTwo

  • isPowerOfTwo(value: number): number
  • Return true if value is a power of 2.

    Parameters

    • value: number

      The number to test.

    Returns number

lerp

  • lerp(v1: number, v2: number, alpha: number): number
  • Linearly interpolates ("lerp" for short) between v1 and v2 by alpha amount (alpha=0 returns v1, while alpha=1 returns v2). For eg: lerp(100, 200, 0.3) returns 130.

    Parameters

    • v1: number

      The starting number (returned when alpha equals 0).

    • v2: number

      The number to interpolate towards (returned when alpha equals 1).

    • alpha: number

      The interpolation factor, typically in the closed interval [0, 1].

    Returns number

mapLinear

  • mapLinear(x: number, a1: number, a2: number, b1: number, b2: number): number
  • Linearily maps x from range [a1, a2] to range [b1, b2].

    Parameters

    • x: number

      The value to be mapped.

    • a1: number

      The minimum value for range A.

    • a2: number

      The maximum value for range A.

    • b1: number

      The minimum value for range B.

    • b2: number

      The maximum value for range B.

    Returns number

radToDeg

  • radToDeg(radians: number): number
  • Converts an angle expressed in radians into degrees.

    Parameters

    • radians: number

      The angle in radians to convert to degrees.

    Returns number

randFloat

  • randFloat(low: number, high: number): number
  • Returns a random float in the interval [low, high].

    Parameters

    • low: number

      The lower bound of the interval where to draw the random float.

    • high: number

      The higher bound of the interval where to draw the random float.

    Returns number

randFloatSpread

  • randFloatSpread(range: number): number
  • Returns a random float in the interval [-range/2, range/2].

    Parameters

    • range: number

      The width of the zero-centered range where to draw the random float.

    Returns number

randInt

  • randInt(low: number, high: number): number
  • Returns a random integer in the interval [low, high].

    Parameters

    • low: number

      The lower bound of the interval where to draw the random integer.

    • high: number

      The higher bound of the interval where to draw the random integer.

    Returns number

smootherstep

  • smootherstep(x: number, min: number, max: number): number
  • Returns a value between 0-1. A variation on smoothstep that has zero 1st and 2nd order derivatives at x=0 and x=1.

    Parameters

    • x: number

      The value to evaluate based on its position between min and max.

    • min: number

      The "left-edge" of the smoothstep function. Any x value below min will be 0.

    • max: number

      The "right-edge" of the smoothstep function. Any x value above max will be 1.

    Returns number

smoothstep

  • smoothstep(x: number, min: number, max: number): number
  • Returns a value between 0-1 that represents the percentage that x has moved between min and max, but smoothed or slowed down the closer x is to the min and max. See Smoothstep for details.

    Parameters

    • x: number

      The value to evaluate based on its position between min and max.

    • min: number

      The "left-edge" of the smoothstep function. Any x value below min will be 0.

    • max: number

      The "right-edge" of the smoothstep function. Any x value above max will be 1.

    Returns number