Options
All
  • Public
  • Public/Protected
  • All
Menu

Math utility functions.

Hierarchy

  • b2Math

Index

Constructors

constructor

Properties

Static b2Mat22_identity

b2Mat22_identity: b2Mat22

Global instance of a 2x2 identity matrix. Use as read-only.

Static b2Transform_identity

b2Transform_identity: b2Transform

Global instance of an identity transform. Use as read-only.

Static b2Vec2_zero

b2Vec2_zero: b2Vec2

Global instance of a zero'ed vector. Use as read-only.

Methods

Static Abs

  • Abs(a: number): number
  • Creates an ABS number.

    Parameters

    • a: number

      Number to ABS.

    Returns number

    Absolute value of a.

Static AbsM

  • Creates an ABS matrix.

    Parameters

    • A: b2Mat22

      Matrix to ABS all values.

    Returns b2Mat22

    Matrix with all positive values.

Static AbsV

  • Creates an ABS vector.

    Parameters

    • a: b2Vec2

      Vector to ABS all values.

    Returns b2Vec2

    Vector with all positive values.

Static AddMM

  • Parameters

    Returns b2Mat22

Static AddVV

  • Adds two vectors.

    Parameters

    Returns b2Vec2

    a + b.

Static Clamp

  • Clamp(a: number, low: number, high: number): number
  • Clamp a number to the range of low to high.

    Parameters

    • a: number

      Number to clamp.

    • low: number

      Low range.

    • high: number

      High range.

    Returns number

    Number a clamped to range of low to high.

Static ClampV

  • Clamps a vector to the range of low to high.

    Parameters

    Returns b2Vec2

    Vector a clamped to range of low to high.

Static CrossFV

  • Cross product of s and vector 2.

    Parameters

    • s: number

      s value.

    • a: b2Vec2

      Vector 2 to use in cross product.

    Returns b2Vec2

    Cross product of s and a.

Static CrossVF

  • Cross product of vector 2 and s.

    Parameters

    • a: b2Vec2

      Vector 2 to use in cross product.

    • s: number

      s value.

    Returns b2Vec2

    Cross product of a and s.

Static CrossVV

  • Cross product of two vector 2s.

    Parameters

    • a: b2Vec2

      Vector 2 to use in cross product.

    • b: b2Vec2

      Vector 2 to use in cross product.

    Returns number

    Cross product of a and b.

Static Distance

  • Calculates the distance between two vectors.

    Parameters

    Returns number

    Distance between a and b.

Static DistanceSquared

  • Calculates the squared distance between two vectors.

    Parameters

    Returns number

    dist^2 between a and b.

Static Dot

  • Dot product of two vector 2s.

    Parameters

    • a: b2Vec2

      Vector 2 to use in dot product.

    • b: b2Vec2

      Vector 2 to use in dot product.

    Returns number

    Dot product of a and b.

Static IsPowerOfTwo

  • IsPowerOfTwo(x: number): boolean
  • Check if a number is a power of 2.

    Parameters

    • x: number

      Number to check if it is a power of 2.

    Returns boolean

    True if x is a power of 2, otherwise false.

Static IsValid

  • IsValid(x: number): boolean
  • Determines if a number is valid. A number is valid if it is finite.

    Parameters

    • x: number

      Number to check for validity.

    Returns boolean

    True if x is valid, otherwise false.

Static Max

  • Max(a: number, b: number): number
  • Determines the max number.

    Parameters

    • a: number

      First number.

    • b: number

      Second number.

    Returns number

    a or b depending on which is the maximum.

Static MaxV

  • Determines the max vector.

    Parameters

    Returns b2Vec2

    a or b depending on which is the maximum.

Static Min

  • Min(a: number, b: number): number
  • Determines the minimum number.

    Parameters

    • a: number

      First number.

    • b: number

      Second number.

    Returns number

    a or b depending on which is the minimum.

Static MinV

  • Determines the minimum vector.

    Parameters

    Returns b2Vec2

    a or b depending on which is the minimum.

Static MulFV

  • Parameters

    Returns b2Vec2

Static MulMM

  • Parameters

    Returns b2Mat22

Static MulMV

  • Multiply matrix and vector.

    Parameters

    Returns b2Vec2

    Result.

Static MulTMM

  • Parameters

    Returns b2Mat22

Static MulTMV

  • Parameters

    Returns b2Vec2

Static MulX

  • Parameters

    Returns b2Vec2

Static MulXT

  • Parameters

    Returns b2Vec2

Static NextPowerOfTwo

  • NextPowerOfTwo(x: number): number
  • Calculates the next power of 2 after the given number.

    Parameters

    • x: number

      Number to start search for the next power of 2.

    Returns number

    The next number that is a power of 2.

Static Random

  • Random(): number
  • Generates a random number.

    Returns number

Static RandomRange

  • RandomRange(lo: number, hi: number): number
  • Returns a random number between lo and hi.

    Parameters

    • lo: number

      Lowest random number.

    • hi: number

      Highest random number.

    Returns number

    Number between lo and hi.

Static SubtractVV

  • Subtracts two vectors.

    Parameters

    Returns b2Vec2

    a - b.

Static Swap

  • Swap(a: any, b: any): void
  • Swaps a and b objects.

    Parameters

    • a: any

      a -> b.

    • b: any

      b -> a.

    Returns void

Generated using TypeDoc