Really basic 2D vector class used for vector calculations

Constructors

Properties

type: string

The type of the Vec2

_x: number

X component of our Vec2

_y: number

Y component of our Vec2

Accessors

Methods

  • Called when at least one component of the Vec2 has changed

    Parameters

    • callback: (() => void)

      callback to run when at least one component of the Vec2 has changed

        • (): void
        • Returns void

    Returns Vec2

  • Set the Vec2 from values

    Parameters

    • x: number = 0

      new X component to set

    • y: number = x

      new Y component to set

    Returns Vec2

    • this Vec2 after being set
  • Add a scalar to all the components of this Vec2

    Parameters

    • value: number = 0

      number to add

    Returns Vec2

    • this Vec2 after addition
  • Subtract a scalar to all the components of this Vec2

    Parameters

    • value: number = 0

      number to subtract

    Returns Vec2

    • this Vec2 after subtraction
  • Multiply all components of this Vec2 with a scalar

    Parameters

    • value: number = 1

      number to multiply with

    Returns Vec2

    • this Vec2 after multiplication
  • Divide all components of this Vec2 with a scalar

    Parameters

    • value: number = 1

      number to divide with

    Returns Vec2

    • this Vec2 after division
  • Calculate the dot product of 2 Vec2

    Parameters

    • vector: Vec2 = ...

      Vec2 to use for dot product

    Returns number

    • dot product of the 2 Vec2
  • Calculate the linear interpolation of this Vec2 by given Vec2 and alpha, where alpha is the percent distance along the line

    Parameters

    • vector: Vec2 = ...

      Vec2 to interpolate towards

    • Optional alpha: number = 1

      interpolation factor in the [0, 1] interval

    Returns Vec2

    • this Vec2 after linear interpolation