This is terrain made computable: the wild, unstructured bulk of ground and sky reduced to consistent, predictable rules upon which you may build anything.
A complete voxel toolkit in 733 lines of TypeScript: sparse storage, shape generation, neighbor queries, flood fill, connected components, A* pathfinding, raycasting, and set operations. 99.7% test coverage across 1,419 lines of tests.
npm: @superinstance/voxel-logic
Repo: SuperInstance/voxel-logic
| Capability | Function | Algorithm |
|---|---|---|
| Sparse storage | VoxelGrid<T> |
Hash-map backed β empty air costs nothing |
| Coordinate math | voxel, voxAdd, manhattan, chebyshev, euclidean |
L1, Lβ, L2 distances |
| Neighbor queries | faceNeighbors (6), allNeighbors (26) |
von Neumann + Moore neighborhoods |
| Shapes | filledBox, hollowBox, voxelLine, filledSphere, hollowSphere |
3D Bresenham line, true sphere |
| Flood fill | floodFill(start, isOccupied) |
BFS connected region |
| Components | connectedComponents(voxels) |
All disconnected groups |
| Pathfinding | findPath(start, goal, isPassable) |
A* with Manhattan heuristic |
| Raycasting | raycast(origin, direction, maxDist) |
Amanatides & Woo voxel traversal |
| Set operations | voxUnion, voxIntersect, voxDifference |
Set algebra on voxel collections |
import {
voxel, VoxelGrid, filledSphere, floodFill, findPath, raycast,
} from '@superinstance/voxel-logic';
// Create a sparse grid
const grid = new VoxelGrid<string>();
grid.set(voxel(0, 0, 0), 'spawn');
grid.set(voxel(1, 0, 0), 'corridor');
// Generate a sphere shape
const sphere = filledSphere(voxel(5, 5, 5), 3);
// Raycast through space (Amanatides-Woo)
const hits = raycast(voxel(0, 0, 0), voxel(1, 0, 0), 50);
// A* pathfinding
const path = findPath(
voxel(0, 0, 0),
voxel(10, 0, 0),
(v) => grid.has(v), // passable check
);voxel(x,y,z) Β· voxEq Β· voxAdd Β· voxSub Β· voxScale Β· manhattan Β· chebyshev Β· euclidean Β· voxKey Β· fromKey
boundsFrom Β· inBounds Β· voxelsInBounds Β· boundsVolume
faceNeighbors (6 faces) Β· allNeighbors (26 Moore) Β· bounded variants
set Β· get Β· has Β· delete Β· size Β· bounds Β· adjacentTo Β· entries
filledBox Β· hollowBox Β· voxelLine (3D Bresenham) Β· filledSphere Β· hollowSphere
floodFill Β· connectedComponents Β· findPath (A*) Β· raycast (Amanatides-Woo)
voxUnion Β· voxIntersect Β· voxDifference
Voxels ARE terrain. This library is the computational substrate for:
- β terrain β MUD-to-visual bridge using voxel grids
- β mud-engine β world topology as voxel adjacency
- β spatial-registry β room placement on 3D grid
- β room-render β voxel-based room rendering
- β base60-lattice β hexagonal tiling β voxel grid
- β elephant β Phaser game client with tile-based rooms
- β scummvm-prototype β room-based adventure game
- β Lucineer Roblox β 3D build placement
The fleet's spatial topology is The Reef: mud-engine β spatial-registry β room-render β terrain β scummvm-prototype. Voxel-logic provides the discrete 3D math underneath all of them β the grid the reef grows on.
npm test # Run all tests
npm run test:coverage # Generate coverage report
npm run test:watch # Watch mode| Suite | Lines | Focus |
|---|---|---|
voxel-logic.test.ts |
356 | Core functionality β coordinates, bounds, neighbors, grid, shapes |
voxel-logic-extended.test.ts |
825 | Extended scenarios β complex shapes, multi-step algorithms, edge cases |
voxel-logic-coverage.test.ts |
238 | Coverage gap-filling β boundary conditions, empty inputs, degenerate geometry |
Coverage: 99.7% β every critical path, every edge case, every fallible assumption probed.
- Sparse by default: Empty voxels consume zero memory. The hash-map only stores occupied cells.
- Pure functions: Shape generators and algorithms are pure β they return voxel arrays without side effects.
- Bounds optional: Most algorithms accept optional bounds for performance (avoids exploring infinite space).
- Generic values:
VoxelGrid<T>stores any value type at each voxel β strings, numbers, objects.
- β CHARTER.md β Mission and fleet integration
- β DOCKSIDE-EXAM.md β Coast Guard fleet certification checklist
- β CONTRIBUTING.md β Development practices
MIT Β© SuperInstance