Stores and manipulates a twodimensional vector comprised of the components x and y

           +y
            |__ +x

Authors

Lukas Scheuerle, Jirka Dell'Oro-Friedl, HFU, 2019

Hierarchy (view full)

Implements

Constructors

Accessors

  • get magnitudeSquared(): number
  • Returns the square of the magnitude of the vector without calculating a square root. Faster for simple proximity evaluation.

    Returns number

  • get type(): string
  • Retrieves the type of this mutable subclass as the name of the runtime class

    Returns string

    The type of the mutable

Methods

  • Returns true if the coordinates of this and the given vector are to be considered identical within the given tolerance TODO: examine, if tolerance as criterium for the difference is appropriate with very large coordinate values or if _tolerance should be multiplied by coordinate value

    Parameters

    • _compare: Vector2
    • _tolerance: number = Number.EPSILON

    Returns boolean

  • Collect applicable attributes of the instance and copies of their values in a Mutator-object. By default, a mutator cannot be extended, since extensions are not available in the object the mutator belongs to. A mutator may be reduced by the descendants of Mutable to contain only the properties needed.

    Returns Mutator

  • Uses the standard array.map functionality to perform the given function on all components of this vector and return a new vector with the results

    Parameters

    • _function: ((value, index, array) => number)
        • (value, index, array): number
        • Parameters

          • value: number
          • index: number
          • array: Float32Array

          Returns number

    Returns Vector2

  • Updates the attribute values of the instance according to the state of the mutator. The mutation may be restricted to a subset of the mutator and the event dispatching suppressed. Uses mutateBase, but can be overwritten in subclasses

    Parameters

    • _mutator: Mutator
    • _selection: string[] = null
    • _dispatchMutate: boolean = true

    Returns Promise<void>

  • Normalizes this to the given length, 1 by default

    Parameters

    • _length: number = 1

    Returns void

  • Defines the components of this vector with the given numbers

    Parameters

    • _x: number = 0
    • _y: number = 0

    Returns void

  • Subtracts the given vector from the executing vector, changing the executor.

    Parameters

    • _subtrahend: Vector2

      The vector to subtract.

    Returns void

  • Transforms this vector by the given matrix, including or exluding the translation. Including is the default, excluding will only rotate and scale this vector.

    Parameters

    • _mtxTransform: Matrix3x3
    • _includeTranslation: boolean = true

    Returns void

  • Calculates the cross product of two Vectors. Due to them being only 2 Dimensional, the result is a single number, which implicitly is on the Z axis. It is also the signed magnitude of the result.

    Parameters

    • _a: Vector2

      Vector to compute the cross product on

    • _b: Vector2

      Vector to compute the cross product with

    Returns number

    A number representing result of the cross product.

  • Normalizes a given vector to the given length without editing the original vector.

    Parameters

    • _vector: Vector2

      the vector to normalize

    • _length: number = 1

      the length of the resulting vector. defaults to 1

    Returns Vector2

    a new vector representing the normalised vector scaled by the given length

  • Calculates the orthogonal vector to the given vector. Rotates counterclockwise by default.

    ↑ => ← => ↓ => → => ↑
    

    Parameters

    • _vector: Vector2

      Vector to get the orthogonal equivalent of

    • _clockwise: boolean = false

      Should the rotation be clockwise instead of the default counterclockwise? default: false

    Returns Vector2

    A Vector that is orthogonal to and has the same magnitude as the given Vector.

  • Creates and returns a vector through transformation of the given vector by the given matrix

    Parameters

    Returns Vector2

  • A shorthand for writing new Vector2(x, 0).

    Parameters

    • _scale: number = 1

      The number to write in the x coordinate. Default: 1

    Returns Vector2

    A new vector with the values (_scale, 0)

  • A shorthand for writing new Vector2(0, y).

    Parameters

    • _scale: number = 1

      The number to write in the y coordinate. Default: 1

    Returns Vector2

    A new vector with the values (0, _scale)