Options
All
  • Public
  • Public/Protected
  • All
Menu

Namespace Math2

Index

Type aliases

WeightedAverageWithExclusionInput

WeightedAverageWithExclusionInput: []

WeightedAverageWithExclusionInputWithOptions

WeightedAverageWithExclusionInputWithOptions: []

Variables

Const NUMBERS_COMMA_DECIMAL

NUMBERS_COMMA_DECIMAL: boolean = (0.1).toLocaleString().includes(",")

Const clamp1

clamp1: (...args: A) => R = clamp.bind(null, 0, 1)

Clamps the given number in the range 0-1

Type declaration

    • (...args: A): R
    • Parameters

      • Rest ...args: A

      Returns R

Const clamp255

clamp255: (...args: A) => R = clamp.bind(null, 0, 255)

Clamps the given number in the range 0-255

Type declaration

    • (...args: A): R
    • Parameters

      • Rest ...args: A

      Returns R

Functions

average

  • average(...ns: number[]): number
  • Parameters

    • Rest ...ns: number[]

    Returns number

clamp

  • clamp(min: number, max: number, value: number): number
  • Clamps the given number in the given range

    Parameters

    • min: number
    • max: number
    • value: number

    Returns number

lerp

  • lerp(from: number, to: number, t: number): number
  • Return a number between from and to, using the decimal t

    Example: lerp(1, 2, .5): 1.5

    Parameters

    • from: number
    • to: number
    • t: number

    Returns number

mod

  • mod(n1: number, n2: number): number
  • Parameters

    • n1: number
    • n2: number

    Returns number

parseLocalizedFloat

  • parseLocalizedFloat(str: string): number
  • Parameters

    • str: string

    Returns number

roundNumber

  • roundNumber(num: number, places: number): number
  • Returns a number rounded to a certain number of decimal places.

    Example: roundNumber(1.24999999, 2): 1.25

    Parameters

    • num: number
    • places: number

    Returns number

roundNumberToMultiple

  • roundNumberToMultiple(num: number, multiple: number): number
  • Returns a number rounded to a multiple

    Example: roundNumberToMultiple(97, 10): 100

    Parameters

    • num: number
    • multiple: number

    Returns number

sum

  • sum(...ns: number[]): number
  • Parameters

    • Rest ...ns: number[]

    Returns number

unlerp

  • unlerp(from: number, to: number, lerped: number): number
  • Given a number between from and to, returns a decimal how far it is, t.

    Parameters

    • from: number
    • to: number
    • lerped: number

    Returns number

weightedAverage

  • weightedAverage(...ns: Array<[]>): number
  • Takes an any number of [weight, number] tuples, and returns the "weighted average".

    Parameters

    • Rest ...ns: Array<[]>

      Any number of [weight, number] tuples.

      For example: weightedAverage([1, 0], [3, 1]) returns 0.75.

      • One part 0, three parts 1. That adds up to four parts, which means each part is worth 0.25.
      • Three parts 1 means 0.25 * 3, one part 0 means 0 * 1.
      • 0.75 + 0 is 0.75.

    Returns number

weightedAverageWithExclusion

  • Takes an any number of [weight, number] tuples, and returns the "weighted average".

    Parameters

    • Rest ...ns: WeightedAverageWithExclusionInput[]

      Any number of [weight, number] tuples.

      For example: weightedAverage([1, 0], [3, 1]) returns 0.75.

      • One part 0, three parts 1. That adds up to four parts, which means each part is worth 0.25.
      • Three parts 1 means 0.25 * 3, one part 0 means 0 * 1.
      • 0.75 + 0 is 0.75.

    Returns number

Generated using TypeDoc