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§
- Boolean
Options - Crossing
Repair Record - One self-crossing this module REPAIRED rather than refused.
- Edge
Split Record - Face
Fragment Record - Face
Imprints - FaceKey
- Face
Pcurve - Fragment
Coedge - Fragment
Loop - Fragment
Order - 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.
- Imprint
Options - Imprint
Piece Record - Imprint
Result Record - Not exhaustive: a new field is not a breaking change. Outside this crate,
start from
ImprintResultRecord::default()and set the fields you need. - Imprint
Vertex - Mesh
Region - One smooth region of the mesh with its recognized carrier and fit
residuals (residuals are zero for
Freeformregions — no fit). - Mesh
Repair Report - What
repair_triangle_souphad to change to close the input. - Mesh
Segmentation - Segmentation result:
triangle_region_ids[t]is the region id of input trianglet(index intoregions;UNASSIGNED_REGIONfor degenerate triangles with no assignable neighbor). - Oracle
Report - Outcome of
boolean_semantic_disagreement. - Residual
Fusable - One
boolean_residual_fusablesfinding. - Segment
Options - 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. - Semantic
Disagreement - One point where the result’s membership contradicts the CSG expectation.
- SewReport
- Tangent
Section Record - One extended tangential contact the imprint recognised (see
ImprintResultRecord::tangent_sections).
Enums§
- Boolean
Operation - Fragment
Edge Source - Region
Carrier - Recognized analytic carrier of a region. Axis directions are unit
vectors;
senseis+1when the mesh normals point along the carrier’s outward normal (away from the axis/center) and-1for a cavity. - Residual
Kind - A single residual fusable — coincident geometry the assembler left unwelded.
- Split
Surface - 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_soundfor a lane whose INPUTS may themselves self-intersect.- accept_
sound_ against_ scoped accept_sound_againstreading only the faces incandidates: 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_splitsplus 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
operandsin ONE imprint+fragment pass (Golovanov T4.4). Additive: does not touch the binary path. - boolean_
operation_ nary_ with_ options boolean_operation_naryunder the caller’sBooleanOptions: the tolerance, the coplanar-face merge and itskeep_unmerged_name_substrslist 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_diagnosticswith both operands translated byoffsetfor 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
resultthat is coincident withintolyet 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 foroperation. 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 alloperands, 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-firstandNNN-secondstagesBREP_BOOLEAN_DUMPwrites, 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_solidbuilds it once and callsfragment_face_indexeddirectly. - 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
groupthat ride the same carrier — the pairsmerge_same_surface_faceswould merge, at the sametolerance, 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 (seeMergeLanes) — and nothing else: a face outsidegroupis never touched, however cosurface with a neighbour. - merge_
same_ surface_ faces - merge_
same_ surface_ faces_ excluding - Like
merge_same_surface_faces, but any face whosenameCONTAINS one ofkeep_unmergedis pinned: it never merges with a coplanar/cosurface neighbour and is emitted unchanged, while every other face merges exactly asmerge_same_surface_faceswould. An emptykeep_unmergedis identical to the plain call. - merge_
same_ surface_ faces_ scoped merge_same_surface_faces_excludingwhose closing validation reads the geometry of the faces inscopeand 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
BrepSolidwhose faces are the mesh’s segmented regions. The result always passes full topology validation (watertight edge pairing, Euler accounting, pcurve consistency) or the call returnsErr— 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<= 0to 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
Nonefor 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_crossingfor 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.
positionsare xyz triples;indicesis a triangle index buffer, or empty to treatpositionsas a raw soup of consecutive triangles (the STL layout ofread_stl). - sew_
rotated_ copies - Sew
countcopies ofcell’s faceskept_faces, copykturned byk · step(radians, right-handed aboutaxis_direction) about the axis throughaxis_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 (copykby(k + 1) · span), with the edges and vertices they use, sewn assew_solidsews. Beside the solid and its report, the result’s face ids by copy (copykat indexk, 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
solidon one side of the plane throughplane_pointwith normalplane_normal: the −n side whenaboveis false, the +n side when it is true. The cutting box spanscovertimes the diagonal of the solid’s control-point box (at least 1;split_solid_by_planeuses 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. - 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
solidby the analytic carrier of a selected facesurface(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
solidinto two pieces by the plane throughplane_pointwith normalplane_normal. Returns(below, above)wherebelowis the piece on the −n side of the plane andabovethe piece on the +n side. - split_
solid_ by_ surface - Split
solidinto 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.
- without_
perturbation - Runs
actionwith this thread’s booleans refusing a degenerate exact arrangement where they would retry it on rigidly perturbed operands (the perturbation ladder, the last resort after the exact recoveries, which still run): for a caller with a fallback of its own (another layout of the same cut), which comes back with the ladder only where every fallback refused.