Gets the alpha (transparency) component of the color.
The alpha component value (0.0 = transparent, 1.0 = opaque)
Gets the blue component of the color.
The blue component value (0.0 to 1.0)
Gets the number of bytes per component in the underlying typed array.
The number of bytes per element (4 for Float32Array, 8 for Float64Array)
Gets the class name of this vector type.
The string "Vector4"
Gets the green component of the color.
The green component value (0.0 to 1.0)
Converts the vector to a GLSL vec4 string representation with float precision.
A GLSL-compatible vec4 string (e.g., "vec4(1.0, 2.0, 3.0, 4.0)")
Converts the vector to a GLSL ivec4 string representation with integer values.
A GLSL-compatible ivec4 string (e.g., "ivec4(1, 2, 3, 4)")
Gets the red component of the color.
The red component value (0.0 to 1.0)
Gets the w component (equivalent to alpha component).
The w/alpha component value
Converts the vector to a WGSL vec4f string representation with float precision.
A WGSL-compatible vec4f string (e.g., "vec4f(1.0, 2.0, 3.0, 4.0)")
Converts the vector to a WGSL vec4i string representation with integer values.
A WGSL-compatible vec4i string (e.g., "vec4i(1, 2, 3, 4)")
Gets the x component (equivalent to red component).
The x/red component value
Gets the y component (equivalent to green component).
The y/green component value
Gets the z component (equivalent to blue component).
The z/blue component value
Static
compositionGets the composition type identifier for this vector type.
The CompositionType.Vec4 identifier
Calculates the dot product between this vector and another vector. The dot product is the sum of the products of corresponding components.
The vector to calculate dot product with
The dot product of the two vectors
Checks if this vector is approximately equal to another vector within a specified tolerance.
The vector to compare with
The tolerance value for comparison (default: Number.EPSILON)
True if the vectors are approximately equal, false otherwise
Checks if this vector is strictly equal to another vector (exact component equality).
The vector to compare with
True if all components 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 to calculate distance to
The distance between the two vectors
Static
_addAdds two vectors component-wise and returns a new vector.
The left operand vector
The right operand vector
The typed array constructor to use for internal storage
A new vector containing the sum (l_vec + r_vec)
Static
_divideDivides a vector by a scalar value and returns a new vector. If the divisor is zero, the result components will be set to Infinity and an error will be logged.
The vector to divide
The scalar value to divide by
The typed array constructor to use for internal storage
A new vector with each component divided by the scalar
Static
_divideDivides the left vector by the right vector component-wise and returns a new vector. If any component of the right vector is zero, the corresponding result component will be set to Infinity.
The left operand vector (dividend)
The right operand vector (divisor)
The typed array constructor to use for internal storage
A new vector with component-wise division result
Static
_dummyCreates a dummy vector with no components (empty array). This is used as a placeholder when a vector is needed but not yet initialized.
The typed array constructor to use for internal storage
A new dummy vector with empty components
Static
_fromCreates a new vector from individual component values.
The X component value
The Y component value
The Z component value
The W component value
The typed array constructor to use for internal storage
A new vector instance with the specified component values
Static
_fromCreates a new vector from an array by copying the first 4 values. If the array has fewer than 4 elements, the remaining components will be undefined.
Array containing numeric values (at least 4 elements recommended)
The typed array constructor to use for internal storage
A new vector instance with the first 4 values from the array
Static
_fromCreates a new vector from a 4-element array by copying the values.
Array containing exactly 4 numeric values [x, y, z, w]
The typed array constructor to use for internal storage
A new vector instance with the copied values
Static
_fromCreates a new Vector4 from a Vector3, setting the W component to 1. This is commonly used for converting 3D positions to homogeneous coordinates.
The source Vector3 to copy from
The typed array constructor to use for internal storage
A new Vector4 with (vec3.x, vec3.y, vec3.z, 1.0)
Static
_fromCreates a new vector by copying values from another Vector4.
The source Vector4 to copy from
The typed array constructor to use for internal storage
A new vector instance with copied values from the source vector
Static
_fromCreates a new Vector4 from a Vector2, setting Z to 0 and W to 1. This is commonly used for converting 2D positions to homogeneous coordinates.
The source Vector2 to copy from
The typed array constructor to use for internal storage
A new Vector4 with (vec2.x, vec2.y, 0.0, 1.0)
Static
_multiplyMultiplies a vector by a scalar value and returns a new vector. This operation scales the vector while preserving its direction.
The vector to multiply
The scalar value to multiply by
The typed array constructor to use for internal storage
A new vector with each component multiplied by the scalar
Static
_multiplyMultiplies two vectors component-wise and returns a new vector. This is also known as the Hadamard product or element-wise multiplication.
The left operand vector
The right operand vector
The typed array constructor to use for internal storage
A new vector with each component being the product of corresponding components
Static
_normalizeCreates a normalized version of the given vector. A normalized vector has a length of 1 while maintaining its direction.
The vector to normalize
The typed array constructor to use for internal storage
A new normalized vector
Static
_oneCreates a vector with all components set to 1 (1, 1, 1, 1).
The typed array constructor to use for internal storage
A new vector with all components set to 1
Static
_subtractSubtracts the right vector from the left vector component-wise and returns a new vector.
The left operand vector (minuend)
The right operand vector (subtrahend)
The typed array constructor to use for internal storage
A new vector containing the difference (l_vec - r_vec)
Static
_zeroCreates a zero vector (0, 0, 0, 0).
The typed array constructor to use for internal storage
A new zero vector
Static
addStatic
addAdds two vectors component-wise and stores the result in the output vector. This method modifies the output vector in-place for better performance.
The left operand vector
The right operand vector
The output vector to store the result (will be modified)
The modified output vector containing the sum
Static
divideStatic
divideDivides a vector by a scalar value and stores the result in the output vector. If the divisor is zero, the result components will be set to Infinity and an error will be logged. This method modifies the output vector in-place for better performance.
The vector to divide
The scalar value to divide by
The output vector to store the result (will be modified)
The modified output vector with each component divided by the scalar
Static
divideStatic
divideDivides the left vector by the right vector component-wise and stores the result in the output vector. If any component of the right vector is zero, the corresponding result component will be set to Infinity. This method modifies the output vector in-place for better performance.
The left operand vector (dividend)
The right operand vector (divisor)
The output vector to store the result (will be modified)
The modified output vector with component-wise division result
Static
dotStatic
dummyStatic
fromStatic
fromCreates a new ColorRgba instance from individual RGBA component values.
The red component value
The green component value
The blue component value
The alpha component value
A new ColorRgba instance with the specified component values
Static
fromStatic
fromStatic
fromStatic
fromStatic
fromStatic
fromStatic
lengthStatic
lengthCalculates the squared length (magnitude) of a vector. This is more efficient than length() when only comparing magnitudes.
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. This method modifies the output vector in-place for better performance.
The vector to multiply
The scalar value to multiply by
The output vector to store the result (will be modified)
The modified output vector with each component multiplied by the scalar
Static
multiplyStatic
multiplyMultiplies two vectors component-wise and stores the result in the output vector. This method modifies the output vector in-place for better performance.
The left operand vector
The right operand vector
The output vector to store the result (will be modified)
The modified output vector with component-wise multiplication result
Static
normalizeStatic
oneStatic
subtractStatic
subtractSubtracts the right vector from the left vector component-wise and stores the result in the output vector. This method modifies the output vector in-place for better performance.
The left operand vector (minuend)
The right operand vector (subtrahend)
The output vector to store the result (will be modified)
The modified output vector containing the difference
Static
zero
A RGBA color class that extends Vector4 to provide color-specific functionality. Represents colors with red, green, blue, and alpha (transparency) components, each ranging from 0.0 to 1.0.
Example