Options
All
  • Public
  • Public/Protected
  • All
Menu

Hierarchy

Index

Constructors

Properties

_x: number = 0
_y: number = 0

Accessors

  • get size(): number
  • set size(newLength: number): void
  • The size (magnitude) of the Vector

    Returns number

  • Setting the size mutates the current vector

    warning

    Can be used to set the size of the vector, be very careful using this, mutating vectors can cause hard to find bugs

    Parameters

    • newLength: number

    Returns void

  • get x(): number
  • set x(val: number): void
  • get y(): number
  • set y(val: number): void

Methods

  • Adds one vector to this one modifying the original

    warning

    Be very careful using this, mutating vectors can cause hard to find bugs

    Parameters

    Returns Vector

  • Performs a 2D cross product with scalar. 2D cross products with a scalar return a vector.

    Parameters

    • v: number

      The scalar to cross

    Returns Vector

  • Performs a 2D cross product with another vector. 2D cross products return a scalar value not a vector.

    Parameters

    • v: Vector

      The vector to cross

    Returns number

  • The distance to another vector. If no other Vector is specified, this will return the [[magnitude]].

    Parameters

    • Optional v: Vector

      The other vector. Leave blank to use origin vector.

    Returns number

  • equals(vector: Vector, tolerance?: number): boolean
  • Compares this point against another and tests for equality

    Parameters

    • vector: Vector

      The other point to compare to

    • tolerance: number = 0.001

      Amount of euclidean distance off we are willing to tolerate

    Returns boolean

  • scaleEqual(size: number): Vector
  • Scales this vector by a factor of size and modifies the original

    warning

    Be very careful using this, mutating vectors can cause hard to find bugs

    Parameters

    • size: number

    Returns Vector

  • setTo(x: number, y: number): void
  • Sets the x and y components at once, THIS MUTATES the current vector. It is usually better to create a new vector.

    warning

    Be very careful using this, mutating vectors can cause hard to find bugs

    Parameters

    • x: number
    • y: number

    Returns void

  • squareDistance(v?: Vector): number
  • Subtracts a vector from another, if you subtract vector B.sub(A) the resulting vector points from A -> B

    Parameters

    • v: Vector

      The vector to subtract

    Returns Vector

  • Subtracts a vector from this one modifying the original

    warning

    Be very careful using this, mutating vectors can cause hard to find bugs

    Parameters

    • v: Vector

      The vector to subtract

    Returns Vector

  • toAngle(): number
  • toString(fixed?: number): string
  • fromAngle(angle: number): Vector
  • Returns a vector of unit length in the direction of the specified angle in Radians.

    Parameters

    • angle: number

      The angle to generate the vector

    Returns Vector

  • Checks if vector is not null, undefined, or if any of its components are NaN or Infinity.

    Parameters

    Returns boolean