Skip to main content

Crate brep_boolean

Crate brep_boolean 

Source
Expand description

Booleans and healing of the BREP kernel: imprint, fragment, boolean assembly, sewing and face merging.

It is one of the implementation crates the kernel is built from. Applications should depend on BREP_kernel, which re-exports the public API of every kernel crate at its root (brep_kernel::…) and adds the feature pipeline and the STEP, IGES, Parasolid (import), 3MF, GLB, STL and OBJ exchange. Many items here are public only so the other kernel crates can reach them; those are hidden from the documentation and carry no stability promise beyond the kernel’s own. The kernel crates are released together, at one version.

It contains:

  • face splitting, imprinting, edge splits and fragmentation;
  • boolean union, subtraction and intersection (boolean_operation) with its acceptance checks and oracle;
  • healing: curve coalescing, same-surface face merging, sewing and pinched-vertex splits;
  • triangle-soup repair into a faceted B-rep, mesh segmentation and spherical mesh unions.

Kernel crates it requires: BREP_RANSAC, BREP_geometry, BREP_topology. It is required by BREP_construction, BREP_blend, BREP_offset, BREP_direct_edit, BREP_kernel.

§Building

The crate builds natively and for wasm32-unknown-unknown. The parallel feature runs some per-face loops on rayon; profile-wall turns on a diagnostic wall-time partition. Both are off by default, and BREP_kernel forwards them.

The packaged crate ships the library sources, the README, the licence and the manifest; it carries no test suite.

§License

The Autodrop3d licence in LICENSE.md, shipped in the crate (license-file in the manifest). Source: https://github.com/mmiscool/next.BREP.io_RUST_BREP_KERNEL

Re-exports§

pub use brep_geometry::*;
pub use brep_topology::*;

Structs§

BooleanOptions
CrossingRepairRecord
One self-crossing this module REPAIRED rather than refused.
EdgeSplitRecord
FaceFragmentRecord
FaceImprints
FaceKey
FacePcurve
FragmentCoedge
FragmentLoop
FragmentOrder
What orders a face’s fragments (lane X, fillet-bore-notch): the outer area of the fragment’s region in the face’s parameter plane, the key the arrangement returns regions by, and the region’s topological key, the sorted (chain, segment) list of its outer loop, then the sorted lists of its holes. The topological key reads no coordinate.
ImprintOptions
ImprintPieceRecord
ImprintResultRecord
ImprintVertex
MeshRegion
One smooth region of the mesh with its recognized carrier and fit residuals (residuals are zero for Freeform regions — no fit).
MeshRepairReport
What repair_triangle_soup had to change to close the input.
MeshSegmentation
Segmentation result: triangle_region_ids[t] is the region id of input triangle t (index into regions; UNASSIGNED_REGION for degenerate triangles with no assignable neighbor).
OracleReport
Outcome of boolean_semantic_disagreement.
ResidualFusable
One boolean_residual_fusables finding.
SegmentOptions
Options for segment_mesh_faces. All tolerances are dimensionless or in degrees; distances derive from the region/mesh scale so the segmentation is size-invariant.
SemanticDisagreement
One point where the result’s membership contradicts the CSG expectation.
SewReport
TangentSectionRecord
One extended tangential contact the imprint recognised (see ImprintResultRecord::tangent_sections).

Enums§

BooleanOperation
FragmentEdgeSource
RegionCarrier
Recognized analytic carrier of a region. Axis directions are unit vectors; sense is +1 when the mesh normals point along the carrier’s outward normal (away from the axis/center) and -1 for a cavity.
ResidualKind
A single residual fusable — coincident geometry the assembler left unwelded.
SplitSurface
A closed analytic tool region used to cut a body. Each variant is realised as a closed solid (unbounded carriers are capped well beyond the body) whose interior is one side of the analytic surface.

Constants§

DISAGREEMENT_THRESHOLD
A boolean is FLAGGED structurally wrong when its decidable-point disagreement rate exceeds this. Tuned from the measured spread (fixed-seed, so these numbers are stable): every KNOWN-GOOD boolean scores ≤ 0.7% (a handful of stray points on the fused seam of tangent/glue unions), benign doubly-curved cases (sphere/torus tubes) top out near 1.7%, while a genuine structural defect — a mis-selected fragment, a lost overlap region, an opened shell — flips a whole region and scores ≥ 7%. The 3% line sits cleanly in the gap: above the near-boundary noise the On-skip + threshold are meant to absorb, well below any real wrongness. One named constant so the audit, the tests, and the stress binary share a single definition of “wrong”.
UNASSIGNED_REGION
Region id given to triangles that could not be assigned to any region (degenerate triangles with no non-degenerate neighbor).

Functions§

accept_sound
Scan a finished result and either accept it, repair it, or refuse it by name.
accept_sound_against
accept_sound for a lane whose INPUTS may themselves self-intersect.
accept_sound_against_scoped
accept_sound_against reading only the faces in candidates: the faces the operation built or changed, their neighbours, and every face whose box reaches the other operand. A face outside that set is an operand’s own, untouched, and lies clear of everything the operation added, so a crossing on it was the operand’s and passes through exactly as the full scan passes it (the inputs are scanned, flagged, and the result returned). An empty set is a result with nothing to scan. A flagged subset hands the whole result to the full acceptance, so every repair and refusal reads as before. (BooleanOptions::untouched_passthrough)
apply_edge_splits
Apply the boundary-edge partition produced by imprint construction.
apply_edge_splits_with_map
apply_edge_splits plus the identity ledger: original edge id → the minted sub-edge ids that replaced it. Consumers keyed on ORIGINAL edge ids (the fragment-selection barrier set) must remap through it, since the split solid’s coedges reference the minted ids.
boolean_operation
boolean_operation_nary
N-ary union / intersect / subtract of operands in ONE imprint+fragment pass (Golovanov T4.4). Additive: does not touch the binary path.
boolean_operation_nary_with_options
boolean_operation_nary under the caller’s BooleanOptions: the tolerance, the coplanar-face merge and its keep_unmerged_name_substrs list are honoured exactly as the binary path honours them, so a caller that falls back from a sequence of binary unions to one arrangement (the sheet metal walk with adjacent bends) keeps the same face partition contract.
boolean_operation_with_diagnostics
boolean_operation_with_diagnostics_at_offset
boolean_operation_with_diagnostics with both operands translated by offset for the operation and the result translated back. Refusal messages name the translated coordinates.
boolean_residual_fusables
Part 2 — the fuse-after detector. Any geometry in result that is coincident within tol yet NOT topologically shared is an intersector / assembler bug: the weld pass should have fused it. Reports distinct vertices at one point and duplicate coincident edges. Purely diagnostic.
boolean_semantic_disagreement
Part 1 — the semantic cross-check. Sample points across the combined box of first ∪ second, classify each versus the two operands and the result, and flag every decidable point where the result membership disagrees with the CSG expectation for operation. See the module docs for the sampling / On-skip / threshold design.
boolean_semantic_disagreement_nary
N-ary semantic cross-check — the correctness gate for crate::boolean_operation_nary. Sample points across the combined box of all operands, classify each versus every operand and the result, and flag every decidable point where the result membership disagrees with the n-ary CSG expectation (Union = In any, Intersect = In all, Subtract = In operand 0 and Out of the rest). Points on or near ANY operand or result boundary are skipped, so a correct n-ary boolean scores ~0.
boolean_split_operands
The two operands a binary boolean’s arrangement reads: prepared as the boolean prepares them, with every boundary edge split where the imprint’s sections meet it. These are the NNN-first and NNN-second stages BREP_BOOLEAN_DUMP writes, not the operands at the boolean’s entry.
build_imprints
concatenate_exact_curve_pieces
Join two exact NURBS pieces with a degree-multiplicity internal knot.
fragment_face
Back-compat entry point: builds the imprint index for this single face. fragment_solid builds it once and calls fragment_face_indexed directly.
fragment_solid
merge_curve_continuation_edges
Collapse tangent continuation edges seen by the same two incident faces — or by the same face TWICE, which is what a split seam looks like.
merge_faces_within
Merge edge-adjacent faces of group that ride the same carrier — the pairs merge_same_surface_faces would merge, at the same tolerance, plus two lanes only a user’s selection opts into: cone patches, and two half-turn patches closing a ring on a shared axial edge (see MergeLanes) — and nothing else: a face outside group is never touched, however cosurface with a neighbour.
merge_same_surface_faces
merge_same_surface_faces_excluding
Like merge_same_surface_faces, but any face whose name CONTAINS one of keep_unmerged is pinned: it never merges with a coplanar/cosurface neighbour and is emitted unchanged, while every other face merges exactly as merge_same_surface_faces would. An empty keep_unmerged is identical to the plain call.
merge_same_surface_faces_scoped
merge_same_surface_faces_excluding whose closing validation reads the geometry of the faces in scope and of the faces the merge built; every pair still merges exactly as the plain call merges it (an operand’s own coplanar neighbours included: the 2026-10-10 census found a mesh import whose five such pairs the boolean fuses). A boolean passes the faces its operation touched and their neighbours (BooleanOptions::untouched_passthrough); the rest were validated by the assembler and left this pass as they came.
mesh_regions_to_brep
Rebuild a BrepSolid whose faces are the mesh’s segmented regions. The result always passes full topology validation (watertight edge pairing, Euler accounting, pcurve consistency) or the call returns Err — an invalid solid is never returned. See the module-level v1 scope notes.
mesh_to_faceted_brep
Build a faceted (planar-triangle) BREP solid from a triangle soup or an indexed triangle mesh — the STL/mesh import entry (§8.6 inverse: mesh → body). Vertices weld within tolerance (pass <= 0 to derive it from the bounding-box diagonal), duplicate and degenerate triangles are dropped, surplus sheets at non-manifold edges are pruned, and remaining boundary cycles are capped with a fan so the result closes watertight whenever the input is close to a manifold. Validation is authoritative: an input too broken to close returns an error, never a silently-invalid solid.
reconstruct_spherical_mesh_union
Attempt a small union of outward spheres and, optionally, one orthogonal box. Returns None for unsupported geometry or insufficient evidence.
repair_triangle_soup
The mesh half of mesh_to_faceted_brep: weld, drop degenerate and duplicate triangles, prune surplus sheets at non-manifold edges, and cap the remaining boundary cycles with a fan — returning the repaired triangle soup instead of a BREP.
resolve_face_crossing
Split two faces of ONE body that cross each other along their carriers’ exact intersection, drop the material the crossing encloses, and re-sew.
resolve_face_crossing_between
resolve_face_crossing for a pair this module has named itself rather than read off the scan.
segment_mesh_faces
Segment a triangle mesh into smooth regions and recognize each region’s analytic carrier. positions are xyz triples; indices is a triangle index buffer, or empty to treat positions as a raw soup of consecutive triangles (the STL layout of read_stl).
sew_rotated_copies
Sew count copies of cell’s faces kept_faces, copy k turned by k · step (radians, right-handed about axis_direction) about the axis through axis_origin, into one solid: the faces left out are the cell’s faces on the surfaces dividing it from its neighbours, where a copy meets the next. The soup is the cell’s kept faces per copy, ids offset per copy by one span past the cell’s largest id (copy k by (k + 1) · span), with the edges and vertices they use, sewn as sew_solid sews. Beside the solid and its report, the result’s face ids by copy (copy k at index k, each in the cell’s face order).
sew_solid
Best-effort sew of a solid’s open boundary edges.
solid_piece_by_plane
The piece of solid on one side of the plane through plane_point with normal plane_normal: the −n side when above is false, the +n side when it is true. The cutting box spans cover times the diagonal of the solid’s control-point box (at least 1; split_solid_by_plane uses 3), centred on that box’s centre projected onto the plane, so it covers every part of the solid on its side whenever the plane meets that box. Ok(None) when nothing of the solid lies on that side; an error only when the cut itself fails, so a caller can tell a plane that misses from a boolean that declined (which split_solid_by_plane reports alike).
split_pinched_vertices
Split PINCHED vertices — points where two (or more) umbrella fans of faces meet at a single vertex record. Local manifold checks (edge use counts, loop closure, orientation) cannot see a pinch; it surfaces only as an odd Euler characteristic. The link of a manifold boundary vertex is a single edge-connected fan: union incident edges through every loop CORNER at the vertex (consecutive coedges meeting there inside one face); more than one component means distinct fans sharing the record — give each extra fan its own vertex at the same point and reassign that fan’s edge endpoints. Geometry is untouched; only identity is repaired.
split_solid_by_face_surface
Split solid by the analytic carrier of a selected face surface (Golovanov §6.4). The face may be a plane, cylinder, cone, or sphere; the carrier is extended to fully span the body. Returns the two pieces ([below, above] for a plane, [inside, outside] otherwise). Errors on non-analytic / general-revolution faces, or when the carrier does not cleanly divide the body.
split_solid_by_plane
Split solid into two pieces by the plane through plane_point with normal plane_normal. Returns (below, above) where below is the piece on the −n side of the plane and above the piece on the +n side.
split_solid_by_surface
Split solid into pieces by an analytic tool surface (Golovanov §6.4).
take_crossing_repairs
Take every repair made on this thread since the last call, leaving the ledger empty. The history loop drains it after each feature so the repair is reported against the feature that made it.