rhodonite
    Preparing search index...

    Class MutableVector2

    Mutable 2D vector class with 32-bit float components. Provides efficient vector operations that modify the vector in place, implementing both IMutableVector and IMutableVector2 interfaces.

    const vec = MutableVector2.zero();
    vec.setComponents(3, 4);
    vec.normalize(); // vec is now (0.6, 0.8)

    Hierarchy (View Summary)

    Implements

    Index
    _v: TypedArray = ...

    Internal typed array storage for vector components

    • get bytesPerComponent(): number

      Gets the number of bytes per component in the underlying typed array.

      Returns number

      The number of bytes per element

    • get className(): string

      Gets the class name for debugging and reflection purposes.

      Returns string

      The string "MutableVector2"

    • get glslStrAsFloat(): string

      Converts the vector to a GLSL vec2 string representation with float precision.

      Returns string

      GLSL-compatible vec2 string

    • get glslStrAsInt(): string

      Converts the vector to a GLSL ivec2 string representation with integer precision.

      Returns string

      GLSL-compatible ivec2 string

    • get glslStrAsUint(): string

      Gets the GLSL string representation of the vector as unsigned integer values.

      Returns string

      GLSL-formatted string for unsigned integer values with 'u' suffix

      Error - Must be implemented by subclasses

    • get w(): number

      Gets the w component of the vector (always 1 for homogeneous coordinates).

      Returns number

      Always returns 1

    • get wgslStrAsFloat(): string

      Converts the vector to a WGSL vec2f string representation with float precision.

      Returns string

      WGSL-compatible vec2f string

    • get wgslStrAsInt(): string

      Converts the vector to a WGSL vec2i string representation with integer precision.

      Returns string

      WGSL-compatible vec2i string

    • get wgslStrAsUint(): string

      Gets the WGSL string representation of the vector as unsigned integer values.

      Returns string

      WGSL-formatted string for unsigned integer values with 'u' suffix

      Error - Must be implemented by subclasses

    • get x(): number

      Gets the x component of the vector.

      Returns number

      The x component value

    • set x(x: number): void

      Sets the x component of the vector.

      Parameters

      • x: number

        The new x component value

      Returns void

    • get y(): number

      Gets the y component of the vector.

      Returns number

      The y component value

    • set y(y: number): void

      Sets the y component of the vector.

      Parameters

      • y: number

        The new y component value

      Returns void

    • get z(): number

      Gets the z component of the vector (always 0 for 2D vectors).

      Returns number

      Always returns 0

    • get compositionType(): CompositionTypeClass<"VEC2">

      Gets the composition type of this vector.

      Returns CompositionTypeClass<"VEC2">

      The composition type (Vec2)

    • Gets the component at the specified index.

      Parameters

      • i: number

        The index (0 for x, 1 for y)

      Returns number

      The component value at the specified index

    • Divides this vector by a scalar value (modifies this vector in place). If the divisor is zero, sets components to 0 and logs an error.

      Parameters

      • value: number

        The scalar value to divide by

      Returns MutableVector2

      This vector instance for method chaining

    • Calculates the dot product with another vector.

      Parameters

      • vec: IVector2

        The vector to calculate dot product with

      Returns number

      The dot product result

    • Checks if this vector is a dummy (empty) vector.

      Returns boolean

      True if the vector has no components, false otherwise

    • Checks if this vector is approximately equal to another vector within a tolerance.

      Parameters

      • vec: IVector2

        The vector to compare with

      • delta: number = Number.EPSILON

        The tolerance value (default: Number.EPSILON)

      Returns boolean

      True if vectors are approximately equal, false otherwise

    • Checks if this vector is strictly equal to another vector (exact comparison).

      Parameters

      • vec: IVector2

        The vector to compare with

      Returns boolean

      True if vectors are exactly equal, false otherwise

    • Checks if the internal storage shares the same ArrayBuffer as the provided one. Useful for determining if vectors share underlying memory.

      Parameters

      • arrayBuffer: ArrayBuffer

        The ArrayBuffer to compare against

      Returns boolean

      True if the same ArrayBuffer is used, false otherwise

    • Calculates the length (magnitude) of the vector.

      Returns number

      The length of the vector

    • Calculates the squared length of the vector. This is more efficient than calculating the actual length when only comparison is needed.

      Returns number

      The squared length of the vector

    • Sets the value at the specified index.

      Parameters

      • i: number

        The component index (0 for x, 1 for y)

      • value: number

        The value to set

      Returns MutableVector2

      This vector instance for method chaining

    • Converts the vector to a string representation.

      Returns string

      String representation in the format "(x, y)"

    • Gets the component value at the specified index. Alias for the at() method for convenience.

      Parameters

      • i: number

        The index of the component to retrieve

      Returns number

      The component value at the given index

    • Creates a new vector by adding two vectors.

      Parameters

      • l_vec: IVector2

        The left operand vector

      • r_vec: IVector2

        The right operand vector

      Returns MutableVector2

      A new MutableVector2 instance containing the sum

    • Calculates the angle between two vectors in radians.

      Parameters

      Returns number

      The angle between the vectors in radians

    • Creates a new vector by dividing a vector by a scalar.

      Parameters

      • vec: IVector2

        The vector to divide

      • value: number

        The scalar value to divide by

      Returns MutableVector2

      A new MutableVector2 instance containing the divided vector

    • Creates a new vector by dividing two vectors component-wise.

      Parameters

      Returns MutableVector2

      A new MutableVector2 instance containing the component-wise quotient

    • Calculates the dot product of two vectors (static version).

      Parameters

      • l_vec: IVector2

        The left vector operand

      • r_vec: IVector2

        The right vector operand

      Returns number

      The dot product of the two vectors

    • Creates a dummy vector for placeholder purposes.

      Returns MutableVector2

      A new MutableVector2 instance

    • Creates a new vector from an array by copying the first two values.

      Parameters

      • array: number[]

        An array containing at least 2 numeric values

      Returns MutableVector2

      A new MutableVector2 instance

    • Creates a new vector from a 2-element array by copying the values.

      Parameters

      • array: Array2<number>

        A 2-element array containing [x, y] components

      Returns MutableVector2

      A new MutableVector2 instance

    • Creates a new vector by copying data from an existing Float32Array.

      Parameters

      • float32Array: Float32Array

        The Float32Array to copy from

      Returns MutableVector2

      A new MutableVector2 instance with copied data

    • Creates a new vector from an existing Float32Array (shares the same buffer).

      Parameters

      • float32Array: Float32Array

        The Float32Array to use as the vector's data

      Returns MutableVector2

      A new MutableVector2 instance

    • Calculates the distance between two vectors.

      Parameters

      Returns number

      The distance between the vectors

    • Calculates the squared length of a vector (static version). This is more efficient than calculating the actual length when only comparison is needed.

      Parameters

      • vec: IVector2

        The vector to calculate squared length for

      Returns number

      The squared length of the vector

    • Creates a new vector by multiplying a vector by a scalar.

      Parameters

      • vec: IVector2

        The vector to multiply

      • value: number

        The scalar value to multiply by

      Returns MutableVector2

      A new MutableVector2 instance containing the scaled vector

    • Creates a new vector by multiplying two vectors component-wise.

      Parameters

      • l_vec: IVector2

        The left operand vector

      • r_vec: IVector2

        The right operand vector

      Returns MutableVector2

      A new MutableVector2 instance containing the component-wise product

    • Creates a normalized copy of the given vector.

      Parameters

      Returns MutableVector2

      A new normalized MutableVector2 instance

    • Creates a vector with all components set to one (1, 1).

      Returns MutableVector2

      A new MutableVector2 instance with components set to 1

    • Creates a new vector by subtracting the second vector from the first.

      Parameters

      • l_vec: IVector2

        The vector to subtract from

      • r_vec: IVector2

        The vector to subtract

      Returns MutableVector2

      A new MutableVector2 instance containing the difference

    • Creates a zero vector (0, 0).

      Returns MutableVector2

      A new MutableVector2 instance with zero components