API Reference
All public APIs are named ESM exports from @1pizzateam/spock. There is no default export and no namespace object, so you import exactly what you use and a bundler drops the rest.
js
import { Vec2, Rect, Utils } from '@1pizzateam/spock';The classes — vectors, matrices, quaternions, and shapes — are mutable. Their methods write into the instance they were called on and return it, so operations chain and a render loop can reuse instances instead of allocating each frame. Methods that measure or test return a number or boolean instead. Trigo, Bezier, Rand, NumArray, Utils, and Time are plain objects of stateless functions, called directly on the export.
Vectors
- Vec2 — mutable two-dimensional vector, the workhorse for positions, directions, and sizes
- Vec3 — mutable three-dimensional vector, plus cross products and the type the 3D transforms speak
Vec— TypeScript interface withx,y, and optionalz, for code that accepts either vector
Matrices and rotations
- Mat3 — 3×3 matrix for 2D affine transforms
- Mat4x3 — 4×3 affine 3D transform, no projection row, cheaper to invert
- Mat4 — full 4×4 matrix, adds
perspective()andorthographic() - Quat — rotation as a unit quaternion
[w, x, y, z], composable and interpolable withslerp()
Geometry
- Circ — circle with a centre, a radius, and optional grid occupancy
- Rect — axis-aligned rectangle with cached corners, also the bounds type for
Vec2.clamp() - Grid — uniform cell lattice used as a broad-phase spatial index
GRID_EMPTY_CELL—-1, the sentinel used for empty occupancy, also exposed asGrid.emptyCell
Curves
- Quadratic Bézier — degree-2 curves with 3 control points: evaluation, tangents, splits, and sampled arc length
- Cubic Bézier — degree-3 curves with 4 control points: evaluation, tangents, splits, and sampled arc length
Trigo
- Trigo — angle constants and conversions, lookup-table and precise sine and cosine, wave equations
Utilities
- Rand — uniform values, distributions, and picks, from
Math.random()or a replayable seed - NumArray — min, max, sum, product, and average reductions over number arrays
- RollingAverage — fixed-capacity circular buffer for $O(1)$ real-time rolling averages with zero allocations
- Utils — clamping, interpolation, range mapping, and decimal rounding
- Time — conversions between ms, seconds, and frame rates, monotonic clock, delta clamping, and sub-stepping