Repository navigation
feat(boolean): one general boolean pipeline (draft: toward replacing the family handlers) - #64
Draft
Basnederveen wants to merge 10 commits into
Draft
Basnederveen wants to merge 10 commits into
Basnederveen wants to merge 10 commits into
Conversation
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>
…r/general-boolean
…pr/general-boolean
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 aCoverageGapwhen no family fits. This adds one general pipeline (about 1.8k lines,boolean/general), the classic one:intersect_brepsintersects 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.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.flatunrolls each face into flat (u, v), lengths kept on a cylinder;arrangementtraces the face's regions there, outer loops and their holes.sewbuilds 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 failsvalidate()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_booleanalone: 218 tests fail, against 10 at baseline on this machine.["cylinder_box_boolean"]and the like); the general pipeline built the body.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:
aarch64-apple-darwinonly, so it needs re-recording on your machine.Is this a direction you would take? If so I would continue with the clusters above in separate PRs.
Tests
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.assert_cut_keeps_volume; the mixed cutter batch's cylindrical step. The multi-tool failure test fails on a torus instead. Handler lists namegeneral_boolean.general_steelmeasures 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 warningsand the source rules pass.cargo teston 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 withCI=true, the matrix and batch handlers and refusals are unchanged.general_booleanin their attempted list; the handler listings; the acceptance session. They need re-recording withOG_GOLDEN_UPDATE=1.npm run checknot run yet; I will before this leaves draft.Files
main/opengeometry/src/operations/modifying/boolean/general/(mod.rs,pieces.rs,flat.rs,arrangement.rs,imprint.rs,curve.rs,sew.rs)boolean/dispatch/table.rs,dispatch/handler_id.rs,boolean/mod.rs,intersection/mod.rs(exportsBodyIntersectionGraph)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 asbranch_anchorstests/source_rules/layer_rules.rs:generalin the boolean order, between handlers and dispatchdeveloper.md: "The general boolean"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-supportworld_graph.rs(assert_cut_keeps_volume),scenes/acceptance.rs;scenes/coverage_gap.rsandtests/booleans/coverage_gap.rsremoved🤖 Generated with Claude Code