Create a vector out of its x and y components.
The set functions create a new copy of the vector, updating a single field.
sub v1 v2 computes v1 - v2.
Can be easily confused in pipelines like
v2
|> sub v1 -- this is actually v1 - v2I think both alternatives are confusing, so I chose this one rather arbitrarily.
Given v, computes -v.
Normalizes a vector v, returning v/|v|. If the vector is 0, it returns 0.
Returns a normalized vector pointing from from to to.
Returns the midpoint between two points. This operation is commutative.
Linearly interpolate from to to with a [0, 1] parameter.
lerp { from = vec2 0 1, to = vec2 1 1 } 0.75 == vec2 0.75 1Rotates a given vector by an angle in radians, in counterclockwise fashion.
Computes |v| for a vector v.
If you need the square of this value, use Vec2.lengthSquared for efficiency.
Computes |v|^2 for a vector v.
Faster than length because it saves a square root operation.
Returns the z-coordinate of the cross product when interpreting the 2D vectors as
3D vectors of the form vec3 v.x v.y 0:
cross v1 v2
== (Vec3.cross
(vec3 v1.x v1.y 0)
(vec3 v2.x v2.y 0)
).zThis operation is useful for calculating the torque created by a force in 2D, for example.
Convenient for debugging purposes.