◐ Off-By-One · answer catalog

js-bsp-csg-solid-boolean-manifold-repair

2 answer(s)jsnode20jsnode20

js-bsp-csg-solid-boolean-manifold-repair

📦 Source in repository (JSON)

Answer 1

Done. I built and verified a complete BSP-tree CSG implementation in ~/bsp-csg/:

Root causes addressed

  1. Exact plane tests fragment geometry → classify vertices with t < -EPSILON ? BACK : t > EPSILON ? FRONT : COPLANAR, and only cut SPANNING edges.
  2. Coplanar faces silently dropped/duplicated → the critical orientation-aware routing: js if (this.normal.dot(poly.plane.normal) > 0) coplanarFront.push(poly); else coplanarBack.push(poly);
  3. T-junctions (long edge abutting two collinear short edges) make the shell look open combinatorially even though it's geometrically closed → resolveTJunctions inserts interior-on-edge vertices, making every edge shared by exactly two half-edges.
  4. Winding → the clipTo/invert/build sequences leave only outward faces; divergence-theorem volume is always positive.

Verification (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 & signatures

# 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"}

Answer 2

Done. I built and verified a complete BSP-tree CSG implementation in ~/bsp-csg/:

Root causes addressed

  1. Exact plane tests fragment geometry → classify vertices with t < -EPSILON ? BACK : t > EPSILON ? FRONT : COPLANAR, and only cut SPANNING edges.
  2. Coplanar faces silently dropped/duplicated → the critical orientation-aware routing: js if (this.normal.dot(poly.plane.normal) > 0) coplanarFront.push(poly); else coplanarBack.push(poly);
  3. T-junctions (long edge abutting two collinear short edges) make the shell look open combinatorially even though it's geometrically closed → resolveTJunctions inserts interior-on-edge vertices, making every edge shared by exactly two half-edges.
  4. Winding → the clipTo/invert/build sequences leave only outward faces; divergence-theorem volume is always positive.

Verification (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 & signatures

# 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"}
Generated from the verified corpus · MIT licensedBack to the catalog