Creates a new Vector2 instance
The x component of the vector. Defaults to 0
The y component of the vector. Defaults to 0
Adds another vector to this vector
The vector to add
Returns this vector for method chaining
Returns the angle between two vectors
The vector to measure angle against
The angle between the vectors in radians
Creates a new vector with the same values as this vector
A new Vector2 instance with copied values
Copies values from another vector into this vector
The vector to copy from
Returns this vector for method chaining
Computes the cross product of this vector with another vector
The other vector for the cross product
The cross product result (scalar in 2D)
Computes the distance between this vector and another vector
The other vector to measure distance to
The distance between the vectors
Computes the squared distance between this vector and another vector (avoids sqrt for performance)
The other vector to measure distance to
The squared distance between the vectors
Divides this vector component-wise by another vector
The vector to divide by
Returns this vector for method chaining
Divides this vector by a scalar
The scalar value to divide by
Returns this vector for method chaining
Computes the dot product of this vector with another vector
The other vector for the dot product
The dot product result
Compares this vector with another vector for equality
The vector to compare with
True if vectors are equal, false otherwise
Computes the length (magnitude) of this vector
The length of the vector
Computes the squared length of this vector (avoids sqrt for performance)
The squared length of the vector
Multiplies this vector component-wise by another vector
The vector to multiply by
Returns this vector for method chaining
Multiplies this vector by a scalar
The scalar value to multiply by
Returns this vector for method chaining
Converts to normal vector (y, -x)
This vector as a normal vector for method chaining
Rotates the vector by a given angle
The rotation angle in radians
Returns this vector for method chaining
Sets the components of this vector
The new x component
The new y component
Returns this vector for method chaining
Sets the x component of this vector
The new x component
Returns this vector for method chaining
Sets the y component of this vector
The new y component
Returns this vector for method chaining
Subtracts another vector from this vector
The vector to subtract
Returns this vector for method chaining
Converts this vector to an array of its components
An array containing the vector's components [x, y]
Normalizes this vector to unit length (length = 1)
Returns this vector for method chaining
Represents a 2D vector with x and y components. Provides various vector operations for 2D mathematics and transformations.