Class Vec2

Vec2 represents a 2D position or a 2D vector. It is used everywhere in Illuminated.

Vec2 is based on Box2D's Vec2 except that in Illuminated, a Vec2 vector is immutable. It means every method creates a new Vec2 instance and you can safely use a same Vec2 instance everywhere because the immutability guarantees that properties will not be modified.

Hierarchy

  • Vec2

Constructors

Properties

x y

Methods

Constructors

  • Parameters

    • x: number = 0

      X coordinate for the vector.

    • y: number = 0

      Y coordinate for the vector.

    Returns Vec2

Properties

x: number = 0

X coordinate for the vector.

y: number = 0

Y coordinate for the vector.

Methods

  • Adds the given vector to the vector.

    Parameters

    • v: Vec2

      A vector to add to the vector.

    Returns Vec2

    A new vector that is the result of the addition.

  • Returns a copy of the vector.

    Returns Vec2

    A new vector that is a copy of the vector.

  • Calculates the squared distance between the vector and the given vector.

    Parameters

    • v: Vec2

      A vector with which the squared distance is calculated.

    Returns number

    The squared distance.

  • Calculates the dot product of the vector and the given vector.

    Parameters

    • v: Vec2

      A vector with which to calculate the dot product.

    Returns number

    The result of the dot product.

  • Determines if the vector is within the bounds defined by the given vectors.

    Parameters

    • topLeft: Vec2

      A vector that is the top-left of the bounds.

    • bottomRight: Vec2

      A vector that is the bottom-right of the bounds.

    Returns boolean

    true if the vector is within the given bounds.

  • Returns the inverse of the vector.

    Returns Vec2

    A new vector that is the inverse of the vector.

  • Calculates the squared length of the vector.

    Returns number

    The squared length.

  • Multiplies the given vector with the vector.

    Parameters

    • n: number

      A number to multiply with the vector.

    Returns Vec2

    A new vector that is the result of the multiplication.

  • Calculates the normalized form of the vector.

    Returns Vec2

    A new vector in normalized form.

  • Subtracts the given vector from the vector.

    Parameters

    • v: Vec2

      A vector to subtract from the vector.

    Returns Vec2

    A new vector that is the result of the subtraction.

  • Returns a string representing the vector.

    Returns string

    A string representing the vector.