Skip to content

About

Logic engine for voxel data structures and 3D simulations.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

1 star

Watchers

0 watching

Forks

Latest commit

Β 

History

13 Commits

Folders and files

Repository files navigation

🧊 Voxel Logic β€” Discrete 3D Spatial Reasoning

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


What This Does

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

Quick Start

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
);

API Overview

Coordinates & Distances

voxel(x,y,z) Β· voxEq Β· voxAdd Β· voxSub Β· voxScale Β· manhattan Β· chebyshev Β· euclidean Β· voxKey Β· fromKey

Bounds

boundsFrom Β· inBounds Β· voxelsInBounds Β· boundsVolume

Neighbors

faceNeighbors (6 faces) Β· allNeighbors (26 Moore) Β· bounded variants

VoxelGrid

set Β· get Β· has Β· delete Β· size Β· bounds Β· adjacentTo Β· entries

Shapes

filledBox Β· hollowBox Β· voxelLine (3D Bresenham) Β· filledSphere Β· hollowSphere

Algorithms

floodFill Β· connectedComponents Β· findPath (A*) Β· raycast (Amanatides-Woo)

Set Operations

voxUnion Β· voxIntersect Β· voxDifference


Terrain Connection

Voxels ARE terrain. This library is the computational substrate for:


Reef Connection

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.


Testing

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.


Design Notes

  • 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.

Fleet Certification


License

MIT Β© SuperInstance

About

Logic engine for voxel data structures and 3D simulations.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages