Creates a new Vector2 instance.
The typed array containing the vector components
Gets the number of bytes per component in the underlying typed array.
The number of bytes per component
Gets the class name.
The string "Vector2"
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
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
Gets the Y component of the vector.
The Y component value
Static
compositionGets the composition type of this vector.
The composition type (Vec2)
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
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
addStatic
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
divideStatic
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
divideStatic
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
dummyStatic
fromStatic
fromStatic
fromStatic
fromStatic
fromStatic
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
multiplyStatic
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
multiplyStatic
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
normalizeStatic
oneStatic
subtractStatic
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
zero
Immutable 2D vector class with 32-bit float components. This class provides comprehensive vector operations for 2D graphics and mathematics. All operations return new vector instances, preserving immutability.