Skip to content

feat(boolean): one general boolean pipeline (draft: toward replacing the family handlers) - #64

Draft
Basnederveen wants to merge 10 commits into
OpenGeometry-io:mainfrom
Bas-Automation-Services:pr/general-boolean
Draft

Basnederveen wants to merge 10 commits into
OpenGeometry-io:mainfrom
Bas-Automation-Services:pr/general-boolean

Conversation

@Basnederveen

Copy link
Copy Markdown
Contributor

What

One boolean instead of one per operand family. A draft to show a direction rather than to merge as is. Builds on #36 (public builder) and #40 (loop winding): this branch contains both, and the last commit is new. Review it against those two, or after they land.

Today a boolean goes through a chain of family handlers (about 18k lines under boolean/handlers) and is a CoverageGap when no family fits. This adds one general pipeline (about 1.8k lines, boolean/general), the classic one:

  1. intersect_breps intersects every face pair whose boxes meet: closed-form curves where the surfaces have them, traced curves where not, each clipped to where it lies on both faces.
  2. pieces: each piece cuts the face it crosses, and its ends split the edges they lie on. A cut over a cylinder's seam is split there on every face it crosses, and so is the seam.
  3. flat unrolls each face into flat (u, v), lengths kept on a cylinder; arrangement traces the face's regions there, outer loops and their holes.
  4. Each region is located against the other solid at a point well inside it. A whole face with a corner outside the other solid's box is outside without a probe.
  5. sew builds the kept regions (the tool's reversed in a subtraction) into one body by their edges' geometry: vertices where the curves through them meet, one edge per pair of uses. A result that fails validate() is a refusal, never an invalid body.

Faces of both solids on one surface imprint each other, and a region lying on the other solid's boundary is kept by whether the two faces point the same way.

In this PR it runs as the last attempt after the handlers, so every case a handler builds is unchanged. Cases that were coverage gaps now build: oblique cylinder-box unions, the width-1.0 arch prisms through a curved wall, rail less wall, mixed cutter batches whose planar stage is oblique, pitched or skew, and structural details (an IPE mitred and skew-cut, a notched cope, a hollow section mitred, a round bar cut obliquely across its seam).

Where this is meant to go

The aim is to replace the family handlers with this one pipeline, not to add a fallback. I measured the distance by routing every boolean in the suite through general_boolean alone: 218 tests fail, against 10 at baseline on this machine.

  • About 55 only assert which handler ran (["cylinder_box_boolean"] and the like); the general pipeline built the body.
  • About 160 are gaps of the general pipeline, in five clusters:
    • collapsed edges: sphere poles and cone apexes are refused (about 20). Flat (u, v) already works for any surface's charts; the singular points do not.
    • "an edge of the result has N faces" (about 30): sewing where cut curves coincide or touch (coaxial cylinders, box pockets, doors touching).
    • a region on the other solid's boundary whose facing cannot be told on a curved surface (about 30).
    • slivers, loops that do not close, a hole outside every loop (about 15).
    • errors from the intersection layer, such as "bounded SSI branch may cross a trim box" (about 10).

The plan would be to close those clusters with the handlers still behind as the fallback, each step keeping the suite green; then run the general pipeline first, then alone; then delete the handlers, route batch and multi-tool through the same path, and shrink ErrorDetails.attempted.

Costs to weigh:

  • Stored fixtures change wherever the topology does: matrix, batch, the IFC digests and the golden file. The golden is recorded for aarch64-apple-darwin only, so it needs re-recording on your machine.
  • On simple cuts the general pipeline is slower than a dedicated handler: about 3.5 ms against 1.1 ms for a straight cut through an IPE300 (release build, median of 15). A few handlers could stay as fast paths if that matters.

Is this a direction you would take? If so I would continue with the clusters above in separate PRs.

Tests

  • New: general_steel (cuboid less a corner; IPE mitred at 45° and skew-cut; hollow section mitred; round bar cut obliquely across its seam, three directions), exact volumes, validate, STEP. steel_notch (an I-section coped by a notch, square and rounded, skewed, both flanges), exact volumes. general_band: a curved band less an oblique then a round opening, where projecting a vertex onto a traced curve used to step past the branch's end. tests/booleans/general.rs: rail less wall, cuboid less oblique cylinder.
  • Tests that pinned these gaps now check what is built: the width-1.0 arch prisms against the exact removed volume; cut + common = whole (to 1%) through the new test-support helper assert_cut_keeps_volume; the mixed cutter batch's cylindrical step. The multi-tool failure test fails on a torus instead. Handler lists name general_boolean.
  • The acceptance scene no longer attempts rail less wall. A failed operate left the graph as it was, so the level export is unchanged.
  • general_steel measures at deflection 1e-4. At 1e-5 the oblique round bar needs the curved-trim tessellation of fix(tessellation): Delaunay meshing of curved trimmed faces, without needle triangles #60.
  • cargo fmt --check, cargo clippy --all-targets -D warnings and the source rules pass.
  • cargo test on Windows: 967 pass. The 7 failures are the same as on the base without this commit: stored fixtures and digests that differ on this platform (wc_subtract, cases x3, golden, IFC oracle x2). Run with CI=true, the matrix and batch handlers and refusals are unchanged.
  • Golden scenes that change: the 9 that now build (oblique cylinder-box unions x5, staged batches x4), each checked here by volume (union = A + B − A∩B; batch = the same cuts one by one); the torus and revolved-bowl half-spaces only gain general_boolean in their attempted list; the handler listings; the acceptance session. They need re-recording with OG_GOLDEN_UPDATE=1.
  • npm run check not run yet; I will before this leaves draft.

Files

  • New: main/opengeometry/src/operations/modifying/boolean/general/ (mod.rs, pieces.rs, flat.rs, arrangement.rs, imprint.rs, curve.rs, sew.rs)
  • Hooked in: boolean/dispatch/table.rs, dispatch/handler_id.rs, boolean/mod.rs, intersection/mod.rs (exports BodyIntersectionGraph)
  • intersection/face_intersection/clip.rs: a closed-form piece whose box misses either face's bounds is skipped before sampling; each sample is tested once; anchors split out as branch_anchors
  • tests/source_rules/layer_rules.rs: general in the boolean order, between handlers and dispatch
  • developer.md: "The general boolean"
  • Tests: boolean/tests/{general_steel,steel_notch,general_band}.rs, tests/booleans/general.rs, curved_wall_arches.rs, multi_tool.rs, errors.rs, creating/revolve.rs, creating/revolved.rs, handlers/cylinder_box/tests/{tilt,robust}.rs, boolean/tests/arched_band.rs; test-support world_graph.rs (assert_cut_keeps_volume), scenes/acceptance.rs; scenes/coverage_gap.rs and tests/booleans/coverage_gap.rs removed

🤖 Generated with Claude Code

Basnederveen and others added 10 commits November 1, 2026 11:28
A crate that depends on OpenGeometry and needs a solid the primitives
don't cover can only build one by writing BRep JSON by hand. The builder
the kernel uses for every primitive and boolean result is crate-private.

- brep::{Builder, Use, boundary, plane_boundary, uv_line} are public:
  Builder::{new, vertex, edge, face, face_with_holes, finish_solid}
- face() and face_with_holes() return the new face id
- Builder::brep() gives read access while building
- Builder::set_face_sense() sets a face's sense by id
- the types those signatures need are public: brep::Orientation,
  brep::PcurveGeometry (and IntersectionSide), math::Interval::new
- the 14 internal tail calls of face() now end in `?; Ok(())`

tests/public_brep_builder.rs builds a box through the public API only:
valid, volume 24, inside/outside classification, STEP export; a face
sense set by id flips face_normal_at; an edge used by a third loop is
rejected.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VFZvqx1RmXzPtbL9VXP4H7
Face loops now follow the standard B-rep / STEP rule (ISO 10303-42):
seen against the face's material normal (surface normal times sense),
outer loops run counter-clockwise and holes clockwise, so the face lies
to the left of every loop. Most producers already did; the tube builders
(cylinder_with_circular_hole, annular_cylinder) wound the cap holes like
the outer loops and gave the inner wall the outer wall's loop before
setting its sense to Reverse, so their STEP export wrote the hole bounds
and the inner wall's bound running the wrong way. Boolean results that
keep those faces inherited them.

- validate() rejects a face whose loops run against its material normal,
  measured as signed area in UV (continuous across chart seams and inside
  an intersection pcurve; two loops bounding a seamless band are judged
  against each other). Straight pcurves on planes are measured from their
  ends.
- orient_loops() (crate-internal) reverses misoriented loops in place.
  Builder::finish_solid, the sweep builder and the boolean result sites
  call it before validate().
- from_json() turns the loops of bodies written with the old winding, so
  saved bodies keep loading.

The check refuses the cone-sphere intersection of
generic_closed_loop_handles_periodic_winding: on main it keeps the sphere
cap outside the cone (a point inside both operands classifies Outside),
and its cone patch's loop runs against the patch's normal. The test now
asserts the refusal.

Stored fixtures edited by hand because their bodies had the old winding:
only the half-edges' from/to/next/prev/sense and the vertices'
outgoing_halfedge change, every number is byte-identical (tube bodies,
validity builders, five boolean-matrix and six batch-matrix results, the
annular-first input). The tube STEP texts change in four ORIENTED_EDGE
senses each (the two hole bounds and the inner wall's circles). The tube
tessellations list the reversed loops' vertices the other way round;
eight positions differ by one ULP from sampling the circles in the other
direction, and were recorded on x86_64 Windows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VFZvqx1RmXzPtbL9VXP4H7
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- plane_boundary and face/face_with_holes check edge, curve and vertex ids
  (MissingReference) instead of indexing.
- face_with_holes checks every use (ids, edge already used twice, empty
  loops) and the UV bounds before writing anything, so a rejected face
  leaves the builder unchanged and a corrected retry works.
- Builder::face_sense reads a face's sense back. The builder does not check
  orientation; developer.md says the caller owns it and how to check it.
- PcurveGeometry is crate-private again. Callers get an opaque UvCurve from
  uv_line or the new uv_conic, which boundary() takes.
- Tests: a plate with a round through-hole (holed planar faces, a cylinder
  bore with a seam edge, reversed with set_face_sense), every face probed
  outward; an inside-out box accepted as built; unknown ids; a rejected
  face leaving the builder unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…the family handlers

One boolean for analytic solids by the classic pipeline instead of by
operand family: intersect every face pair (intersect_breps), cut each face
along the pieces that cross it and split its edges at their ends, trace
each face's regions in its own flat (u, v), locate each region against the
other solid, and sew the regions the operation keeps by their edges'
geometry. Faces of both solids on one surface imprint each other. A
result that fails validate() is a refusal, never an invalid body.

Hooked in as the last attempt in generic_boolean, so every case a family
handler builds is unchanged; cases that were coverage gaps now build:
oblique cylinder-box unions, wide arch prisms through curved walls, rail
less wall, mixed cutter batches with oblique planar stages, I-section
copes and mitres. Tests check what it builds (exact volumes, or cut +
common = whole); tests that pinned those gaps now pin a torus instead.

The pipeline is described in developer.md ("The general boolean"); the
boolean stage order gains `general` between handlers and dispatch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant