aninest-root / Vec2
Vec2
A collection of 2D vector math functions and a few other generic scalar operations.
Vectors are represented as {x: number, y: number} and are meant to be immutable, following a functional programming style.
Type Aliases
| Type Alias | Description |
|---|---|
| Vec2 | A 2D vector. |
Variables
| Variable | Description |
|---|---|
| ZERO_VEC2 | A 2D vector with x and y set to 0. |
Functions
| Function | Description |
|---|---|
| addVec | Adds two vectors together, returning a new vector. |
| bezier | Performs a bezier interpolation between two vectors by a time value. |
| clamp | Clamps a value between a minimum and maximum value. |
| copy | Duplicates the vector. |
| cross | Calculates the cross product of two vectors. |
| distanceTo | Calculates the distance between two vectors. |
| distanceTo2 | Calculates the squared distance between two vectors. |
| divScalar | Divides a vector v by a scalar s immutably. |
| divVec | Performs component-wise division of v1 / v2 immutably. |
| dot | Calculates the dot product of two vectors. |
| lerp | Performs a linear interpolation between two vectors by a time value. |
| lerpFunc | Lerps between a and b by t. |
| mag | Calculates the magnitude of a vector. |
| magSquared | Squares the magnitude of a vector. |
| mapVec | Calls a function func on each component of a vector, creating a new vector from the result of each function call. |
| mulScalar | Multiplies a vector v by a scalar s immutably. |
| mulVec | Does component-wise multiplication of two vectors immutably. |
| newVec2 | Vec2 Constructor |
| normalize | Returnes a normalized version of the vector. |
| rotate | Rotates a vector by an angle in radians. |
| rotateAround | Rotates a vector around a pivot point by an angle in radians. |
| subVec | Subtracts v2 from v1 immutably. |
| vecToIter | Converts a vector to an array. Useful for spreading into function arguments. |