Creates a new mutable 2D vector with 64-bit float components.
The typed array containing vector components
Gets the number of bytes per component in the underlying typed array.
The number of bytes per element
Gets the class name of this vector instance.
The constructor name of the class
Converts the vector to a GLSL vec2 string representation with float precision.
GLSL-compatible vec2 string
Converts the vector to a GLSL ivec2 string representation with integer precision.
GLSL-compatible ivec2 string
Gets the w component of the vector (always 1 for homogeneous coordinates).
Always returns 1
Converts the vector to a WGSL vec2f string representation with float precision.
WGSL-compatible vec2f string
Converts the vector to a WGSL vec2i string representation with integer precision.
WGSL-compatible vec2i string
Gets the x component of the vector.
The x component value
Sets the x component of the vector.
The new x component value
Gets the y component of the vector.
The y component value
Sets the y component of the vector.
The new y component value
Gets the z component of the vector (always 0 for 2D vectors).
Always returns 0
Static
compositionGets the composition type of this vector.
The composition type (Vec2)
Adds another vector to this vector (modifies this vector in place).
The vector to add
This vector instance for method chaining
Creates a deep copy of this vector with double precision.
A new MutableVector2d instance with the same component values
Copies components from another vector to this vector.
The source vector to copy from
This vector instance for method chaining
Divides this vector by a scalar value (modifies this vector in place). If the divisor is zero, sets components to Infinity and logs an error.
The scalar value to divide by
This vector instance for method chaining
Divides this vector component-wise by another vector (modifies this vector in place). If any component of the divisor is zero, sets that component to Infinity and logs an error.
The vector to divide by
This vector instance for method chaining
Calculates the dot product with another vector.
The vector to calculate dot product with
The dot product result
Checks if this vector is approximately equal to another vector within a tolerance.
The vector to compare with
The tolerance value (default: Number.EPSILON)
True if vectors are approximately equal, false otherwise
Checks if this vector is strictly equal to another vector (exact comparison).
The vector to compare with
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.
The ArrayBuffer to compare against
True if the same ArrayBuffer is used, false otherwise
Calculates the distance from this vector to another vector.
The target vector
The distance between the vectors
Multiplies this vector by a scalar value (modifies this vector in place).
The scalar value to multiply by
This vector instance for method chaining
Multiplies this vector component-wise by another vector (modifies this vector in place).
The vector to multiply by
This vector instance for method chaining
Normalizes this vector to unit length (modifies the vector in place). If the vector has zero length, the result is undefined.
This vector instance for method chaining
Sets both components to one.
This vector instance for method chaining
Returns the raw typed array containing the vector components.
The underlying typed array
Sets the value at the specified index.
The component index (0 for x, 1 for y)
The value to set
This vector instance for method chaining
Sets both x and y components of the vector.
The x component value
The y component value
This vector instance for method chaining
Subtracts another vector from this vector (modifies this vector in place).
The vector to subtract
This vector instance for method chaining
Sets both components to zero.
This vector instance for method chaining
Static
_addAdds two vectors component-wise (static version).
The left vector operand
The right vector operand
The typed array constructor
A new vector containing the sum
Static
_divideDivides a vector by a scalar value (static version).
The vector to divide
The scalar value to divide by
The typed array constructor
A new vector containing the divided result
Static
_divideDivides the left vector by the right vector component-wise (static version).
The left vector operand (dividend)
The right vector operand (divisor)
The typed array constructor
A new vector containing the component-wise division result
Static
_dummyCreates a dummy vector with no components.
The typed array constructor
A new dummy vector
Static
_fromCreates a vector from individual x and y components.
The x component
The y component
The typed array constructor
A new vector instance
Static
_fromCreates a vector from an array, taking the first 2 elements.
The array containing components
The typed array constructor
A new vector instance
Static
_fromCreates a vector from a 2-element array.
The array containing [x, y] components
The typed array constructor
A new vector instance
Static
_fromCreates a vector by copying components from another IVector2.
The source vector
The typed array constructor
A new vector instance
Static
_fromCreates a vector by copying the first 2 components from a 3D vector.
The source 3D vector
The typed array constructor
A new vector instance
Static
_fromCreates a vector by copying the first 2 components from a 4D vector.
The source 4D vector
The typed array constructor
A new vector instance
Static
_fromCreates a vector from another IVector2 by sharing the underlying array.
The source vector
The typed array constructor
A new vector instance
Static
_multiplyMultiplies a vector by a scalar value (static version).
The vector to multiply
The scalar value to multiply by
The typed array constructor
A new vector containing the scaled result
Static
_multiplyMultiplies two vectors component-wise (static version).
The left vector operand
The right vector operand
The typed array constructor
A new vector containing the component-wise product
Static
_normalizeNormalizes a vector to unit length (static version).
The vector to normalize
The typed array constructor
A new normalized vector
Static
_oneCreates a one vector (1, 1).
The typed array constructor
A new one vector
Static
_subtractSubtracts the right vector from the left vector component-wise (static version).
The left vector operand
The right vector operand
The typed array constructor
A new vector containing the difference
Static
_zeroCreates a zero vector (0, 0).
The typed array constructor
A new zero vector
Static
addCreates a new vector by adding two vectors with double precision.
A new MutableVector2d instance containing the sum
Static
addAdds two vectors component-wise and stores the result in the output vector.
The left vector operand
The right vector operand
The output vector to store the result
The output vector containing the sum
Static
angleStatic
divideCreates a new vector by dividing a vector by a scalar with double precision.
The vector to divide
The scalar value to divide by
A new MutableVector2d instance containing the divided vector
Static
divideDivides a vector by a scalar value and stores the result in the output vector.
The vector to divide
The scalar value to divide by
The output vector to store the result
The output vector containing the divided result
Static
divideCreates a new vector by dividing two vectors component-wise with double precision.
A new MutableVector2d instance containing the component-wise quotient
Static
divideDivides the left vector by the right vector component-wise and stores the result in the output vector.
The left vector operand (dividend)
The right vector operand (divisor)
The output vector to store the result
The output vector containing the component-wise division result
Static
dotStatic
dummyCreates a dummy vector for placeholder purposes with double precision.
A new MutableVector2d instance
Static
fromCreates a new vector from a 2-element array by copying the values.
A 2-element array containing [x, y] components
A new MutableVector2d instance
Static
lengthStatic
lengthCalculates the squared length of a vector (static version). This is more efficient than calculating the actual length when only comparison is needed.
The vector to calculate squared length for
The squared length of the vector
Static
multiplyCreates a new vector by multiplying a vector by a scalar with double precision.
The vector to multiply
The scalar value to multiply by
A new MutableVector2d instance containing the scaled vector
Static
multiplyMultiplies a vector by a scalar value and stores the result in the output vector.
The vector to multiply
The scalar value to multiply by
The output vector to store the result
The output vector containing the scaled result
Static
multiplyCreates a new vector by multiplying two vectors component-wise with double precision.
A new MutableVector2d instance containing the component-wise product
Static
multiplyMultiplies two vectors component-wise and stores the result in the output vector.
The left vector operand
The right vector operand
The output vector to store the result
The output vector containing the component-wise product
Static
normalizeCreates a normalized copy of the given vector with double precision.
The vector to normalize
A new normalized MutableVector2d instance
Static
oneCreates a vector with all components set to one (1, 1) with double precision.
A new MutableVector2d instance with components set to 1
Static
subtractCreates a new vector by subtracting the second vector from the first with double precision.
A new MutableVector2d instance containing the difference
Static
subtractSubtracts the right vector from the left vector component-wise and stores the result in the output vector.
The left vector operand
The right vector operand
The output vector to store the result
The output vector containing the difference
Static
zeroCreates a zero vector (0, 0) with double precision.
A new MutableVector2d instance with zero components
Mutable 2D vector class with 64-bit float components. Provides high-precision vector operations for applications requiring double-precision floating-point arithmetic.
Example