js-bsp-csg-solid-boolean-manifold-repair
Done. I built and verified a complete BSP-tree CSG implementation in ~/bsp-csg/:
csg.js — engine (Vec/Plane/Polygon/Node, union/intersect/subtract, T-junction repair, volume + edge-topology verification)test.js — analytic battery (57 checks, all passing)SOLUTION.md — the full self-contained write-up with both files embeddedt < -EPSILON ? BACK : t > EPSILON ? FRONT : COPLANAR, and only cut SPANNING edges.js
if (this.normal.dot(poly.plane.normal) > 0) coplanarFront.push(poly);
else coplanarBack.push(poly);resolveTJunctions inserts interior-on-edge vertices, making every edge shared by exactly two half-edges.clipTo/invert/build sequences leave only outward faces; divergence-theorem volume is always positive.node test.js → 57/57, exit 0)Divergence-theorem signed volume V = (1/6)Σ a·(b×c) matched analytic values:
| Case | Expected | Got |
|---|---|---|
Cube [-1,1]³ |
8 | 8 |
| Tetrahedron | 1/6 | 0.166666667 |
A∪B / A∩B / A−B |
12 / 4 / 4 | ✓ |
A∪C / A∩C / A−C |
15 / 1 / 7 | ✓ |
Cavity 4³−2³ |
56 | 56 |
(A∪B)−D / (A∪B)∩D / triple chain |
8 / 4 / 5 | ✓ |
Shared-face L∪R, L−R |
2 / 1 | ✓ |
| Stacked union, flush subtract | 2 / 0.5 | ✓ |
Cubic scaling V(sS)=s³V(S), s∈{0.5,2,3.7} |
— | ✓ |
Every case also passed boundaryEdges=0, nonManifoldEdges=0, badOrient=0, dupDir=0.
Leaky demo (coplanar handling disabled via CSG.union(L, R, false)): only 2 triangles, volume 0 instead of 2, and 4 boundary edges — the shared internal face is discarded and T-junction repair cannot repair a true hole. This proves orientation-aware coplanar routing is mandatory.
Run it yourself:
cd ~/bsp-csg && node test.js
The complete, copy-pasteable source for both files is embedded in ~/bsp-csg/SOLUTION.md.
# Evidence - Problem class: js-bsp-csg-solid-boolean-manifold-repair - Model: openrouter/deepseek/deepseek-v4.1-flash - Solved: 2026-09-15T04:34:39.399Z - Verification: solution produced by pi in sandbox; see signatures.json
{"description": "Build BSP-tree constructive solid geometry over an input triangle soup: robust polygon classification and splitting against planes with epsilon handling (including coplanar same-orientation vs opposite-orientation faces), then evaluate union, intersection and difference to emit a watertight two-manifold surface with consistent outward winding. Verify with the divergence theorem that signed volume of the output equals the analytically known volume for a battery of primitive and chained booleans, that every edge has exactly two incident half-edges, and show the leaky non-manifold output produced when coplanar-face handling is skipped.", "environment": "node20", "language": "js", "model": "openrouter/deepseek/deepseek-v4.1-flash", "problem_class": "js-bsp-csg-solid-boolean-manifold-repair", "provider": "openrouter", "solved_at": "2026-09-15T04:34:39.399Z", "version": "20"}Done. I built and verified a complete BSP-tree CSG implementation in ~/bsp-csg/:
csg.js — engine (Vec/Plane/Polygon/Node, union/intersect/subtract, T-junction repair, volume + edge-topology verification)test.js — analytic battery (57 checks, all passing)SOLUTION.md — the full self-contained write-up with both files embeddedt < -EPSILON ? BACK : t > EPSILON ? FRONT : COPLANAR, and only cut SPANNING edges.js
if (this.normal.dot(poly.plane.normal) > 0) coplanarFront.push(poly);
else coplanarBack.push(poly);resolveTJunctions inserts interior-on-edge vertices, making every edge shared by exactly two half-edges.clipTo/invert/build sequences leave only outward faces; divergence-theorem volume is always positive.node test.js → 57/57, exit 0)Divergence-theorem signed volume V = (1/6)Σ a·(b×c) matched analytic values:
| Case | Expected | Got |
|---|---|---|
Cube [-1,1]³ |
8 | 8 |
| Tetrahedron | 1/6 | 0.166666667 |
A∪B / A∩B / A−B |
12 / 4 / 4 | ✓ |
A∪C / A∩C / A−C |
15 / 1 / 7 | ✓ |
Cavity 4³−2³ |
56 | 56 |
(A∪B)−D / (A∪B)∩D / triple chain |
8 / 4 / 5 | ✓ |
Shared-face L∪R, L−R |
2 / 1 | ✓ |
| Stacked union, flush subtract | 2 / 0.5 | ✓ |
Cubic scaling V(sS)=s³V(S), s∈{0.5,2,3.7} |
— | ✓ |
Every case also passed boundaryEdges=0, nonManifoldEdges=0, badOrient=0, dupDir=0.
Leaky demo (coplanar handling disabled via CSG.union(L, R, false)): only 2 triangles, volume 0 instead of 2, and 4 boundary edges — the shared internal face is discarded and T-junction repair cannot repair a true hole. This proves orientation-aware coplanar routing is mandatory.
Run it yourself:
cd ~/bsp-csg && node test.js
The complete, copy-pasteable source for both files is embedded in ~/bsp-csg/SOLUTION.md.
# Evidence - Problem class: js-bsp-csg-solid-boolean-manifold-repair - Model: openrouter/deepseek/deepseek-v4.1-flash - Solved: 2026-09-15T04:34:39.399Z - Verification: solution produced by pi in sandbox; see signatures.json
{"description": "Build BSP-tree constructive solid geometry over an input triangle soup: robust polygon classification and splitting against planes with epsilon handling (including coplanar same-orientation vs opposite-orientation faces), then evaluate union, intersection and difference to emit a watertight two-manifold surface with consistent outward winding. Verify with the divergence theorem that signed volume of the output equals the analytically known volume for a battery of primitive and chained booleans, that every edge has exactly two incident half-edges, and show the leaky non-manifold output produced when coplanar-face handling is skipped.", "environment": "node20", "language": "js", "model": "openrouter/deepseek/deepseek-v4.1-flash", "problem_class": "js-bsp-csg-solid-boolean-manifold-repair", "provider": "openrouter", "solved_at": "2026-09-15T04:34:39.399Z", "version": "20"}