Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Num

Num class provides various helper functions for basic numeric operations

Hierarchy

  • Num

Index

Methods

Static average

  • Sum a group of numeric arrays

    Parameters

    • pts: GroupLike | number[][]

      an array of numeric arrays

    Returns Pt

    a array of sums

Static boundValue

  • boundValue(val: number, min: number, max: number): number
  • Different from Num.clamp in that the value out-of-bound will be "looped back" to the other end.

    example

    boundValue(361, 0, 360) will return 1

    Parameters

    • val: number

      value to bound

    • min: number

      min value

    • max: number

      max value

    Returns number

Static clamp

  • clamp(val: number, min: number, max: number): number
  • Clamp values between min and max

    Parameters

    • val: number

      value to clamp

    • min: number

      min value

    • max: number

      max value

    Returns number

Static cycle

  • cycle(t: number): number
  • Given a value between 0 to 1, returns a value that cycles between 0 -> 1 -> 0 using sine method.

    Parameters

    • t: number

      a value between 0 to 1

    Returns number

    a value between 0 to 1

Static equals

  • equals(a: number, b: number, threshold?: number): boolean
  • Check if two numbers are equal or almost equal within a threshold

    Parameters

    • a: number

      number a

    • b: number

      number b

    • Default value threshold: number = 0.00001

      a threshold within which the two numbers are considered equal

    Returns boolean

Static lerp

  • lerp(a: number, b: number, t: number): number
  • Linear interpolation

    Parameters

    • a: number

      start value

    • b: number

      end value

    • t: number

      usually a value between 0 to 1

    Returns number

Static mapToRange

  • mapToRange(n: number, currA: any, currB: any, targetA: any, targetB: any): number
  • Map a value from one range to another

    Parameters

    • n: number

      a value in the first range

    • currA: any
    • currB: any
    • targetA: any
    • targetB: any

    Returns number

    a remapped value in the second range

Static normalizeValue

  • normalizeValue(n: number, a: number, b: number): number
  • Normalize a value within a range

    Parameters

    • n: number

      the value to normalize

    • a: number

      range value 1

    • b: number

      range value 1

    Returns number

Static randomRange

  • randomRange(a: number, b?: number): number
  • Get a random number within a range

    Parameters

    • a: number

      range value 1

    • Default value b: number = 0

      range value 2

    Returns number

Static sum

  • Sum a group of numeric arrays

    Parameters

    • pts: GroupLike | number[][]

      an array of numeric arrays

    Returns Pt

    a array of sums

Static within

  • within(p: number, a: number, b: number): boolean
  • Check if a value is within

    Parameters

    • p: number
    • a: number
    • b: number

    Returns boolean

Generated using TypeDoc