rhodonite
    Preparing search index...

    Class MutableVector3

    Mutable 3D vector class with 32-bit float precision. Provides in-place vector operations for efficient mathematical computations. All operations modify the vector instance and return it for method chaining.

    Hierarchy (View Summary)

    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 (4 for Float32Array, 8 for Float64Array)

    • get className(): string

      Gets the class name for debugging purposes.

      Returns string

      The class name string

    • get glslStrAsFloat(): string

      Gets the GLSL representation of this vector as a float vec3.

      Returns string

      A string representation suitable for GLSL shaders

    • get glslStrAsInt(): string

      Gets the GLSL representation of this vector as an integer ivec3.

      Returns string

      A string representation suitable for GLSL shaders with integer components

    • 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 (always 1 for 3D vectors).

      Returns number

      Always returns 1

    • get wgslStrAsFloat(): string

      Gets the WGSL representation of this vector as a float vec3f.

      Returns string

      A string representation suitable for WGSL shaders

    • get wgslStrAsInt(): string

      Gets the WGSL representation of this vector as an integer vec3i.

      Returns string

      A string representation suitable for WGSL shaders with integer components

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

      Returns void

    • get z(): number

      Gets the z component of the vector.

      Returns number

      The z component value

    • set z(z: number): void

      Sets the z component of the vector.

      Parameters

      • z: number

        The new z value

      Returns void

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

      Gets the composition type for this vector class.

      Returns CompositionTypeClass<"VEC3">

      The composition type (Vec3)

    • Adds another vector to this vector. Performs component-wise addition and modifies this vector in place.

      Parameters

      Returns MutableVector3

      This vector instance for method chaining

    • Gets the component at the specified index.

      Parameters

      • i: number

        The index (0 for x, 1 for y, 2 for z)

      Returns number

      The component value at the specified index

    • Computes the cross product of this vector with another vector. Calculates the cross product and modifies this vector in place to store the result. The cross product produces a vector perpendicular to both input vectors.

      Parameters

      • vec: IVector3

        The vector to compute cross product with

      Returns MutableVector3

      This vector instance for method chaining

    • Divides this vector by a scalar value. Scales all components by 1/value and modifies this vector in place. If value is 0, sets all components to 0 and logs an error.

      Parameters

      • value: number

        The scalar value to divide by

      Returns MutableVector3

      This vector instance for method chaining

    • Divides this vector by another vector component-wise. Performs element-wise division and modifies this vector in place. If any component of the divisor vector is 0, sets the corresponding component to 0.

      Parameters

      Returns MutableVector3

      This vector instance for method chaining

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

      Parameters

      • vec: IVector3

        The vector to calculate dot product with

      Returns number

      The dot product result

    • Converts the vector to a flat array.

      Returns number[]

      An array containing the x, y, and z components

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

      Returns boolean

      True if the vector is dummy (has no components), false otherwise

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

      Parameters

      • vec: IVector3

        The vector to compare with

      • delta: number = Number.EPSILON

        The tolerance for comparison (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: IVector3

        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

    • Calculates the distance from this vector to another vector.

      Parameters

      Returns number

      The distance between the vectors

    • Multiplies this vector by a scalar value. Scales all components by the given value and modifies this vector in place.

      Parameters

      • value: number

        The scalar value to multiply by

      Returns MutableVector3

      This vector instance for method chaining

    • Applies a quaternion rotation to this vector. Rotates this vector by the given quaternion and modifies it in place. Equivalent to: quat * vector3 * quat^(-1)

      Parameters

      • quat: IQuaternion

        The quaternion representing the rotation

      Returns MutableVector3

      This vector instance for method chaining

    • Multiplies this vector by another vector component-wise. Performs element-wise multiplication and modifies this vector in place.

      Parameters

      • vec: IVector3

        The vector to multiply by

      Returns MutableVector3

      This vector instance for method chaining

    • Normalizes this vector to unit length. Modifies the vector in place to have a magnitude of 1. A zero-length vector stays a zero vector (an error is logged) instead of becoming Infinity/NaN.

      Returns MutableVector3

      This vector instance for method chaining

    • Returns the raw typed array containing the vector components.

      Returns TypedArray

      The underlying typed array

    • Sets the value at the specified index.

      Parameters

      • i: number

        The index (0 for x, 1 for y, 2 for z)

      • value: number

        The new value to set

      Returns MutableVector3

      This vector instance for method chaining

    • Sets all three components of the vector.

      Parameters

      • x: number

        The x component value

      • y: number

        The y component value

      • z: number

        The z component value

      Returns MutableVector3

      This vector instance for method chaining

    • Subtracts another vector from this vector. Performs component-wise subtraction and modifies this vector in place.

      Parameters

      Returns MutableVector3

      This vector instance for method chaining

    • Converts the vector to a string representation.

      Returns string

      A string representation of the vector in the format "(x, y, z)"

    • Converts the vector to an approximate string representation with limited decimal places.

      Returns string

      A string representation with financial formatting

    • 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

    • Calculates the angle between two vectors in radians.

      Parameters

      Returns number

      The angle between the vectors in radians

      Error if either vector has zero length

    • Creates a new vector that is the cross product of two vectors.

      Parameters

      Returns MutableVector3

      A new vector containing the cross product

    • Creates a new vector that is the scalar division of a vector.

      Parameters

      • vec: IVector3

        The vector to divide

      • value: number

        The scalar divisor

      Returns MutableVector3

      A new divided vector

    • Divides a vector by a scalar and stores the result in the output vector.

      Parameters

      • vec: IVector3

        The vector to divide

      • value: number

        The scalar value to divide by

      • out: IMutableVector3

        The output vector to store the result

      Returns IMutableVector3

      The output vector containing the divided result

      If division by zero occurs, the result is set to 0 and an error is logged

    • Creates a new vector that is the component-wise division of two vectors.

      Parameters

      Returns MutableVector3

      A new vector containing the component-wise quotient

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

      Parameters

      Returns number

      The dot product of the two vectors

    • Creates a dummy vector for initialization purposes.

      Returns MutableVector3

      A new dummy vector

    • Creates a vector with all components set to the same value.

      Parameters

      • val: number

        The value for all components

      Returns MutableVector3

      A new vector instance

    • Creates a vector from three component values.

      Parameters

      • x: number

        The x component

      • y: number

        The y component

      • z: number

        The z component

      Returns MutableVector3

      A new vector instance

    • Creates a vector from an array, taking the first 3 elements.

      Parameters

      • array: number[]

        The array containing at least 3 values

      Returns MutableVector3

      A new vector instance

    • Creates a vector from a 3-element array.

      Parameters

      • array: Array3<number>

        The array containing x, y, z values

      Returns MutableVector3

      A new vector instance

    • Creates a vector by copying from an existing Float32Array.

      Parameters

      • float32Array: Float32Array

        The Float32Array to copy from

      Returns MutableVector3

      A new vector instance with copied data

    • Creates a vector by copying from another 3D vector.

      Parameters

      Returns MutableVector3

      A new vector instance

    • Creates a 3D vector by copying from a 4D vector (ignoring w component).

      Parameters

      • vec: IVector4

        The 4D vector to copy from

      Returns MutableVector3

      A new 3D vector instance

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

      Parameters

      • float32Array: Float32Array

        The Float32Array to use

      Returns MutableVector3

      A new vector instance

    • Calculates the distance between two vectors.

      Parameters

      Returns number

      The distance between the two 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: IVector3

        The vector to calculate squared length for

      Returns number

      The squared length of the vector

    • Creates a new vector that is the scalar multiplication of a vector.

      Parameters

      • vec: IVector3

        The vector to multiply

      • value: number

        The scalar value

      Returns MutableVector3

      A new scaled vector

    • Creates a new vector by applying a quaternion rotation to a vector.

      Parameters

      • quat: IQuaternion

        The quaternion representing the rotation

      • vec: IVector3

        The vector to rotate

      Returns MutableVector3

      A new rotated vector

    • Creates a new vector that is the component-wise multiplication of two vectors.

      Parameters

      Returns MutableVector3

      A new vector containing the component-wise product

    • Creates a normalized copy of the given vector.

      Parameters

      Returns MutableVector3

      A new normalized vector

    • Creates a unit vector (1, 1, 1).

      Returns MutableVector3

      A new unit vector

    • Rotates a vector around the X-axis and stores the result in the output vector. Only the Y and Z components are affected by X-axis rotation.

      Parameters

      • vec3: IVector3

        The input vector to rotate

      • radian: number

        The rotation angle in radians

      • outVec: MutableVector3

        The output vector to store the result

      Returns void

    • Rotates a vector around the Y-axis and stores the result in the output vector. Only the X and Z components are affected by Y-axis rotation.

      Parameters

      • vec3: IVector3

        The input vector to rotate

      • radian: number

        The rotation angle in radians

      • outVec: MutableVector3

        The output vector to store the result

      Returns void

    • Rotates a vector around the Z-axis and stores the result in the output vector. Only the X and Y components are affected by Z-axis rotation.

      Parameters

      • vec3: IVector3

        The input vector to rotate

      • radian: number

        The rotation angle in radians

      • outVec: MutableVector3

        The output vector to store the result

      Returns void

    • Creates a new vector that is the difference of two vectors.

      Parameters

      • l_vec: IVector3

        The left vector (minuend)

      • r_vec: IVector3

        The right vector (subtrahend)

      Returns MutableVector3

      A new vector containing the difference

    • Creates a zero vector (0, 0, 0).

      Returns MutableVector3

      A new zero vector