Set each component to its absolute value. Mutates and returns this.
Angle in radians. No arg: angle of this from origin. With other: angle from this toward other.
Optionalother: Vector2Round each component up. Mutates and returns this.
Clamp each axis to its [min, max] range. y defaults to x. Mutates and returns this.
New Vec2 with the same components.
Approximate equality (within approxEqual tolerance). Scalar broadcasts.
Approximate equality (within approxEqual tolerance). Scalar broadcasts.
Optionaly: numberRound each component down. Mutates and returns this.
true when both components are finite (rules out NaN and ±Infinity).
Euclidean magnitude (sqrt(x² + y²)).
Manhattan magnitude (|x| + |y|).
Apply callback to each component (index is 0 for x, 1 for y). Mutates and returns this.
Larger of the two components.
Smaller of the two components.
Per-axis Euclidean modulo (result sign matches the divisor). Mutates and returns this.
Optionaly: numberFlip the sign of both components (same as mult(-1)). Mutates and returns this.
Scale to unit length. Zero-length vectors are left untouched and warn (throttled). Mutates and returns this.
Scale so |x| + |y| === 1. Zero-length vectors are left untouched. Mutates and returns this.
Per-axis remainder (JavaScript %, sign follows the dividend). Mutates and returns this.
Optionaly: numberRound each component to the nearest integer. Mutates and returns this.
Tuple [x, y].
Build a Rect with the argument as position and this as size.
Optionaly: numberBuild a Rect with this as position and the argument as size.
Optionaly: numberDebug string like "Vec2 [x: 1, y: 2]".
StaticfromUnit vector at angle rad (radians), scaled per-axis. scaleY defaults to scaleX.
2D vector. Scalar args to
set/add/sub/mult/div/rem/mod/equalsbroadcast to both axes:vec.add(5)adds 5 to x and y,vec.mult(-1)negates both. Pass(x, y)or aVector2for per-axis values.