Options
All
  • Public
  • Public/Protected
  • All
Menu

Namespace Utils

Index

Variables

ARRAY_TYPE: (new (n: number) => Float32Array | number[]) = ...

Type declaration

    • new (n: number): Float32Array | number[]
    • The array type to use for internal numeric computations throughout the library. Float32Array is used if it is available, but falls back on Array. If you want to set array type manually, inject it via the global variable P2_ARRAY_TYPE. See example below.

      example
      <script>
      <!-- Inject your preferred array type before loading p2-es -->
      P2_ARRAY_TYPE = Array;
      </script>
      <script src="p2-es.js"></script>

      Parameters

      • n: number

      Returns Float32Array | number[]

Functions

  • appendArray(a: unknown[], b: unknown[]): void
  • Append the values in array b to the array a.

    Parameters

    • a: unknown[]

      the array to append to

    • b: unknown[]

      the array to append values from

    Returns void

  • arrayRemove(array: unknown[], element: unknown): void
  • Remove an element from an array, if the array contains the element.

    Parameters

    • array: unknown[]
    • element: unknown

    Returns void

  • extend<A, B>(a: A, b: B): A & B
  • Extend an object with the properties of another

    Type Parameters

    • A

    • B

    Parameters

    • a: A
    • b: B

    Returns A & B

  • shallowClone<T>(obj: T): T
  • Shallow clone an object. Returns a new object instance with the same properties as the input instance.

    Type Parameters

    • T

    Parameters

    • obj: T

    Returns T

  • splice(array: unknown[], index: number, howmany?: number): void
  • Garbage free Array.splice(). Does not allocate a new array.

    Parameters

    • array: unknown[]
    • index: number
    • howmany: number = 1

    Returns void