rapid-render
    Preparing search index...

    Class Vec2

    Represents a 2D vector with x and y components.

    Implements

    Index

    Constructors

    • Creates an instance of Vec2.

      Parameters

      • Optionalx: number

        The x coordinate (default is 0).

      • Optionaly: number

        The y coordinate (default is 0).

      Returns Vec2

    Properties

    x: number
    y: number
    DOWN: Vec2 = ...
    LEFT: Vec2 = ...
    ONE: Vec2 = ...
    RIGHT: Vec2 = ...
    UP: Vec2 = ...
    ZERO: Vec2 = ...

    Methods

    • Returns a new vector with the absolute values of the components.

      Returns Vec2

      A new vector with absolute values.

    • Adds another vector to this vector.

      Parameters

      • v: Vec2

        The vector to add.

      Returns Vec2

      A new Vec2 instance with the result of the addition.

    • Calculates the angle of the vector relative to the x-axis.

      Returns number

      The angle of the vector.

    • Calculates the angle between two vectors.

      Parameters

      • v: Vec2

        The other vector.

      Returns number

      The angle between the two vectors in radians.

    • Returns a new vector with ceiled components.

      Returns Vec2

      A new vector with components rounded up to the nearest integer.

    • Clones the vector.

      Returns Vec2

      A new Vec2 instance with the same x and y values.

    • Copy the vector

      Parameters

      • vec: Vec2

        The vector to copy.

      Returns void

    • Calculates the cross product of this vector with another vector.

      Parameters

      • v: Vec2

        The other vector.

      Returns number

      The cross product result.

    • Calculates the distance to another point.

      Parameters

      • v: Vec2

        The other point.

      Returns number

      The distance between the two points.

    • Divides the vector by a scalar or another vector.

      Parameters

      • f: number | Vec2

        The scalar value or vector to divide by.

      Returns Vec2

      A new Vec2 instance with the result of the division.

    • Calculates the dot product of this vector with another vector.

      Parameters

      • v: Vec2

        The other vector.

      Returns number

      The dot product result.

    • Check if the vector is equal to another vector.

      Parameters

      • vec: Vec2

        The vector to compare with.

      Returns boolean

      True if the vectors are equal, otherwise false.

    • Returns a new vector with floored components.

      Returns Vec2

      A new vector with components rounded down to the nearest integer.

    • Inverts the direction of the vector.

      Returns this

      The current instance with updated values.

    • Calculates the length of the vector.

      Returns number

      The length of the vector.

    • Calculates the middle point between the current vector and another vector.

      Parameters

      • other: Vec2

        The other vector.

      Returns Vec2

      A new vector representing the middle point between the current vector and the other vector.

    • Multiplies the vector by a scalar or another vector.

      Parameters

      • f: number | Vec2

        The scalar value or vector to multiply by.

      Returns Vec2

      A new Vec2 instance with the result of the multiplication.

    • Normalizes the vector to have a length of 1.

      Returns this

      The current instance with updated values.

    • Rotates the vector 90 degrees counterclockwise.

      Returns this

      The current instance with updated values.

    • Snaps the vector components to the nearest increment.

      Parameters

      • increment: number

        The increment to snap to.

      Returns Vec2

      A new vector with components snapped to the nearest increment.

    • Converts the vector to a string representation.

      Returns string

      A string containing the vector's x and y coordinates.

    • Subtracts another vector from this vector.

      Parameters

      • v: Vec2

        The vector to subtract.

      Returns Vec2

      A new Vec2 instance with the result of the subtraction.

    • Parameters

      • angle: number

      Returns Vec2

    • Converts an array of coordinate pairs into an array of Vec2 instances.

      Parameters

      • array: number[][]

        An array of [x, y] coordinate pairs.

      Returns Vec2[]

      An array of Vec2 instances.