The pack
vectorMath
function vectorMath(): Pack<{ vecMath: VecMathApi }>
The vector-math pack. Pure maths, so it needs no backend and runs headless.
Helpers
dist
function dist(a: Vec2, b: Vec2): number
Returns the distance between two points.
fromAngle
function fromAngle(rad: number, mag: number = 1): Vec2
A unit (or mag-length) vector at the given angle in radians.
normalize
function normalize(a: Vec2): Vec2
Zero-safe normalize: a zero vector returns {0,0} rather than NaN.
Functions
add
function add(a: Vec2, b: Vec2): Vec2
Returns the sum of two vectors as a new vector.
angleOf
function angleOf(a: Vec2): number
The angle of a vector in radians (-PI..PI).
clampLen
function clampLen(a: Vec2, max: number): Vec2
Clamp a vector's magnitude to at most max (terminal-velocity caps).
dist2
function dist2(a: Vec2, b: Vec2): number
Returns the squared distance between two points. Use it to compare distances without a square root.
dot
function dot(a: Vec2, b: Vec2): number
Returns the dot product of two vectors.
len
function len(a: Vec2): number
Returns the length of a vector.
len2
function len2(a: Vec2): number
Returns the squared length of a vector. Use it to compare lengths without a square root.
lerp
function lerp(a: Vec2, b: Vec2, t: number): Vec2
Linear interpolation between two points.
rotate
function rotate(a: Vec2, rad: number): Vec2
Rotate a vector by rad radians.
scale
function scale(a: Vec2, s: number): Vec2
Returns the vector a multiplied by the scalar s.
stepToward
function stepToward(from: Vec2, to: Vec2, maxStep: number): Vec2
Move from toward to by at most maxStep, never overshooting (it clamps
exactly at to).
sub
function sub(a: Vec2, b: Vec2): Vec2
Returns a minus b as a new vector.
Types
Vec2
interface Vec2
A 2D point or vector. Plain data, so anything can produce one.
x: number— Horizontal coordinate, in whatever units the caller uses.y: number— Vertical coordinate, in the same units asx.
VecMathApi
type VecMathApi = typeof kit
game.vecMath — every function this pack carries, as one namespace.
VecPt
type VecPt = Vec2
A point on a path — the same shape, named for what it is used as.


