Options
All
  • Public
  • Public/Protected
  • All
Menu

Module "vector"

Index

Type aliases

Constructors Functions

Length Functions

Other Functions

Transform Functions

Type aliases

Vector

Vector: [number, number]

Vector represents a direction and a magnitude.

Constructors Functions

clone

  • Creates a copy of vector that can be modified separately.

    Parameters

    Returns Vector

from

  • from(x: number, y: number): Vector
  • Creates a vector from X and Y components.

    Parameters

    • x: number
    • y: number

    Returns Vector

fromAngle

  • fromAngle(radians: number, length: number): Vector
  • Creates a vector from an angle and a length.

    Parameters

    • radians: number

      Angle in radians

    • length: number

    Returns Vector

fromPoints

  • Creates a vector from start and end points.

    Parameters

    Returns Vector

Length Functions

chebyshev

  • chebyshev(vector: Vector): number

length

  • length(vector: Vector): number
  • Calculates the magnitude of a vector.

    Parameters

    Returns number

manhattan

  • manhattan(vector: Vector): number

Other Functions

add

  • Adds v2 to v1.

    Use added if you want to create a new vector instead.

    Parameters

    Returns void

added

  • Adds v1 and v2 to create a new vector.

    Use add if you want to modify v1 instead.

    Parameters

    Returns Vector

divide

  • Divides v1 by v2

    Use divided if you want to create a new vector instead.

    Parameters

    Returns void

divided

  • Divides v1 by v2 to create a new vector.

    Use divide if you want to modify v1 instead.

    Parameters

    Returns Vector

dot

  • Calculates the dot product of v1 and v2.

    Parameters

    Returns number

equals

  • Check whether v1 and v2 are equal.

    Vectors are equal if both of their components are the equal.

    Parameters

    Returns boolean

is

  • is(value: any): value is Vector
  • Determines whether value is a Vector.

    Parameters

    • value: any

    Returns value is Vector

multiplied

  • Multiplies v1 and v2 to create a new vector.

    Use multiply if you want to modify v1 instead.

    Parameters

    Returns Vector

multiply

  • Multiplies v1 by v2.

    Use multiplied if you want to create a new vector instead.

    Parameters

    Returns void

normalize

  • normalize(vector: Vector): void
  • Normalizes vector to have a length of 1.

    This function modifies vector. Use normalized if you want to create a new vector instead.

    Parameters

    Returns void

normalized

  • Creates a new vector by normalizing vector.

    Use normalize if you want to normalize vector in place.

    Parameters

    Returns Vector

subtract

  • Subtracts v2 from v1.

    Use subtracted if you want to create a new vector instead.

    Parameters

    Returns void

subtracted

  • Subtracts v2 from v1 to create a new vector.

    Use subtract if you want to modify v1 instead.

    Parameters

    Returns Vector

Transform Functions

rotate

  • rotate(vector: Vector, radians: number): void
  • Rotates vector.

    This function modifies vector. Use rotated if you want to produce a new vector.

    Parameters

    • vector: Vector
    • radians: number

      Rotation angle in radians

    Returns void

rotated

  • Creates a new rotated vector.

    Use rotate if you want to rotate vector in place.

    Parameters

    • vector: Vector
    • radians: number

      Rotation angle in radians

    Returns Vector

scale

  • scale(vector: Vector, scale: number): void
  • Scales a vector in-place.

    This function modifies vector. Use scaled if you want to produce a new vector.

    Parameters

    • vector: Vector
    • scale: number

      Scaling factor

    Returns void

scaled

  • Creates a new scaled vector.

    This function produces a new vector. Use scale if you want to scale vector in-place.

    Parameters

    • vector: Vector
    • scale: number

      Scaling factor

    Returns Vector

Generated using TypeDoc