Fudge Core
    Preparing search index...

    Class Vector2

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

               +y
                |__ +x
    

    Lukas Scheuerle, Jirka Dell'Oro-Friedl, HFU, 2019 | Jonas Plotzky, HFU, 2025

    Hierarchy (View Summary)

    Implements

    Index

    Constructors

    Properties

    x: number
    y: number

    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

    • Calls a defined callback function on each component of the vector and assigns the result to the component. Similar to Vector2.map but mutates this vector instead of creating a new one.

      Parameters

      • _function: (
            _value: number,
            _index: number,
            _component: "x" | "y",
            _vector: Vector2,
        ) => number

      Returns Vector2

      A reference to this vector.

    • 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

    • Set the values of this object from the given array starting at the given offset.

      Parameters

      • _array: ArrayLike<number>

        The array to read the values from.

      • _offset: number = 0

        (optional) The offset to start reading from.

      Returns this

      A reference to this instance.

    • 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

    • Calls a defined callback function on each component of the vector, and returns a new vector that contains the results. Similar to Array.map.

      Parameters

      • _function: (
            _value: number,
            _index: number,
            _component: "x" | "y",
            _vector: Vector2,
        ) => number
      • _out: Vector2 = ...

        Optional vector to store the result in.

      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

      Returns void

    • Copy the values of this object into the given array starting at the given offset. Creates a new array if none is provided.

      Type Parameters

      • T extends { [n: number]: number } = number[]

      Parameters

      • _out: T = ...

        (optional) The receiving array.

      • _offset: number = 0

        (optional) The offset to start writing to.

      Returns T

      _out or a new array if none is provided.

    • 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 Vector2

      A reference to this vector.

    • 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

      Returns number

    • 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

      • _out: Vector2 = ...

        Optional vector to store the result in.

      Returns Vector2

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

    • 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)