0083 — Profile caps use a certified ear clipper
- Status: Accepted
- Date: 2026-10-04
- Deciders: Friedrich, axiolid
- Supersedes: the
axiolid-constructpart of 0015
Context
ADR 0015 adopted earcut to triangulate profiles with holes after a hand-rolled ear clipper failed on two holes. It recorded the risk: earcut is not exactness-certified, and the hole case was covered by area conservation only.
That risk was real (#253). For a 4 x 4 profile with two 1 x 1 holes side by side in one horizontal band, earcut returned 12 triangles of the right total area where a polygon with 12 vertices and 2 holes needs 14. One triangle edge ran along the band's bottom line straight past both holes' inner corners: a T-junction. The plain extrusion of that profile had 8 boundary edges and failed its volume and closure checks. earcut drops nodes where the bridged ring runs straight on and lets only reflex nodes block an ear, so a vertex lying on a diagonal is not seen. Area conservation cannot catch this: a T-junction covers the right area.
Decision
axiolid-construct triangulates profile rings with its own ear clipper (ring_triangulation), every decision an exact orient2d sign, and certifies its own output before returning it.
- Validate. Rings that do not bound a polygon with holes are refused with
InvalidInputnaming the ring: a non-finite or repeated vertex, a ring folding back on or crossing itself, holes that overlap or touch each other or the outer ring, a hole outside the outer ring or inside another hole. Rings may come either way round; orientation is read exactly at each ring's lexicographically smallest vertex. Coordinates are ordered by value there and wherever the clipper picks or sorts by them,-0.0equal to0.0(#269): underf64::total_cmpa-0.0twin of the lowest corner'sx, which projecting a face onto plane axes writes, was taken for the lowest corner, and a straight one reversed the ring. - Bridge. Holes join the boundary in order of decreasing largest x, each from its rightmost vertex, so a mutually visible vertex exists on the boundary built so far. Candidates are tried nearest first; one is taken only when the bridge leaves both ends into the polygon and touches no edge of any ring or earlier bridge, a vertex on the segment included.
- Clip. An ear is refused if any node other than its corners lies in the closed triangle, so no diagonal runs through a vertex.
- Certify. Every triangle strictly counter-clockwise, every ring edge used exactly once from inside, every other edge exactly once in each direction. Positive triangles bounded exactly by the rings tile the polygon once, so this is the whole contract; a triangulation that fails it is refused with
Degenerate, never returned.
The ADR 0015 lesson is kept: the bookkeeping that defeated the first clipper is now checked by the certificate rather than trusted, and the tests sweep random hole layouts on a shared grid, where rays, columns and edge lines coincide constantly.
Alternatives considered
| Option | Why not |
|---|---|
| Keep earcut and repair T-junctions afterwards | Treats one symptom of an uncertified decision procedure; the next degeneracy surfaces as another open solid. |
axiolid-triangulate (constrained Delaunay) | A new internal edge for axiolid-construct, and its incremental build rebuilds adjacency per insertion, quadratic on a finely chorded profile. Delaunay quality is not needed for caps. |
| Report the certificate failure but still use earcut | Refuses valid profiles instead of triangulating them. |
Consequences
Positive
- Profiles with several holes compile to closed, consistently wound extrusions; polygonal input covers exactly outer minus holes.
- Invalid ring sets are refused by name instead of producing a solid.
axiolid-constructno longer depends onearcut.
Negative / costs
- More code owned here. The search grid keeps a 24,576-vertex profile at about 0.13 s in a release build; earcut was faster on such inputs.
- Rings that touch at a single vertex, which earcut accepted, are now refused: their extrusion is not a two-manifold. 2D and surface callers accept them through
PinchPolicy::Accept(amendment below, #262).
Follow-ups / risks to watch
axiolid-mesh-compilestill used earcut for planar faces; it moved to this clipper in #260 (amendment below), and ADR 0015 is superseded.
Relation to existing code
crates/algorithms/construction/construct/src/ring_triangulation.rsand itsvalidate,bridgeandclipsubmodules;pinch(#262) andseam(#270) underPinchPolicy::Accept;seal(#283) for planar faces of a shell (profile::triangulate_shell_face).crates/algorithms/construction/construct/src/profile.rs—triangulatedelegates here.crates/algorithms/construction/construct/tests/profile_holes.rs— the #253 cases and the random-layout properties.crates/algorithms/construction/construct/tests/oracle.rs— the hole-free differential gate againstaxiolid_reference::triangulate_simple.
Amendment 2026-10-04: pinch policy per caller (#262)
Refusing rings that touch at one vertex is right for a solid and wrong for a region. A consumer re-feeds overlay output as plan regions and surfaces: two rooms meeting at a corner as one union ring, an L-shaped room wrapped round a column corner, a corridor eroded to a point, the same pinch reported through even-odd fill as a figure eight, a room minus door zones touching its walls. Each bounds a valid region, and its triangulation is a valid surface patch whose edges are the ring edges.
- The caller states the policy.
profile::triangulate_with(rings, PinchPolicy);PinchPolicyis#[non_exhaustive].Refuseistriangulate, used by everything that must close into a two-manifold (extrusion and loft caps: a pinch extrudes to a wall edge shared by four faces).Acceptis for 2D regions and planar surface patches, including the planar faces of a B-rep (a pinch inside one face leaves every edge of the shell shared by two faces; the shell is at most pinched at a vertex, which the face did not create). - What is accepted. Two edges meeting at one point that is a vertex of at least one of them. A vertex inside another edge is inserted into it; coincident vertices become one, referenced by their first index in
outer ++ holes. Crossing, overlapping along a stretch, a hole outside the outer ring or inside another hole stay refused by name. - How. Each ring is split at its repeated vertices into simple loops; a loop's nesting depth (one probe vertex off the other loop decides, or, when every vertex is shared, the sector of the other loop that its first edge leaves into) orients it: even depths counter-clockwise, odd clockwise, so the region is the points inside an odd number of loops, and a figure eight through a vertex reads as its two lobes. Round every shared vertex the loops' edges, sorted by exact angle, must alternate leaving and arriving; each wedge from a leaving edge counter-clockwise to the next arriving one becomes one node. The nodes form the boundary cycles of the region's connected parts; a cycle bounds from outside when every visit of its lexicographically smallest vertex turns strictly left, and each hole cycle goes to the innermost outer cycle strictly around it. Each part is bridged and clipped as before; a bridge from a hole cycle that visits its rightmost vertex twice leaves from the visit whose sector it enters.
- Certificate. Unchanged in kind, over the split loops: strictly counter-clockwise triangles, every loop edge once from inside, every other edge twinned, and
n + 2h - 2ctriangles fornloop vertices (a pinch counted once per visit),hhole cycles andcparts. - Unchanged. Rings touching nowhere take the original path under both policies and triangulate identically.
| Option | Why not |
|---|---|
| Accept pinches everywhere | Extrusions of pinched caps are not two-manifolds; the solid path must keep refusing by name. |
| Split the pinch into separate ring pieces only | Covers two lobes of one ring, not a hole touching the outer ring, which has to merge with it rather than split. |
| Emit two solids touching at an edge for a pinched cap | No caller asked for it; a solid caller that wants it can split its profile and extrude the parts. |
Amendment 2026-10-04: mesh-compile's planar faces (#260)
axiolid-mesh-compile triangulated authored polygon faces, curve-bounded planes, planar B-rep faces and curved faces' parameter domains with earcut, so the T-junction above could open those meshes too, and the planar B-rep path checked nothing at all. They now go through this clipper (planar::clip_projected), over the dependency axiolid-mesh-compile already had on axiolid-construct; no crate edge changes and the clipper does not move.
- Policy:
PinchPolicy::Accepton every face. A face is a surface patch. A pinch inside one face of a closed solid leaves every edge of the shell shared by two faces: the face's ring edges are exactly the edges its neighbours share, whatever its rings touch. At worst the shell is pinched at that vertex, which the face did not create; the mesh's own closure audit still reports it. Only extrusion and loft caps, which build the walls themselves, refuse pinches. - Corners. A corner repeating its predecessor exactly (an exporter's closing point) is dropped first, as earcut dropped it; every other corner is a triangle corner, so curved faces no longer need their skipped trim samples put back.
- The certificate replaces the area cross-check the authored path ran on earcut's output, and closes the gap on planar B-rep faces, whose
Proven(0)and slab bounds assume a cover. Rings that bound no region are refused by name where earcut returned a partial cover. - The noise-band split stays. Export noise puts corners nanometres off the straight run they lie on; the clipper may cut a sliver across them whose diagonal a neighbouring face cuts too, using that edge four times.
split_invented_edgesstill removes such slivers on planar faces.
Amendment 2026-10-09: welding shared edges through inserted vertices (#265)
The #260 amendment claimed that under Accept "the face's ring edges are exactly the edges its neighbours share, whatever its rings touch". That holds for rings touching at a shared vertex, not for a vertex lying inside another ring's edge: the clipper inserts it into that edge, so the face runs along the edge in two pieces while the neighbouring face that shares it keeps it whole. The mesh had a T-junction, and mesh-compile still reported the B-rep as Solid (a consumer's closure audit caught it).
- Weld through.
profile::ring_touches(rings)returns every vertex the accepted triangulation inserts into an edge, from the same exact validation. Before triangulating, mesh-compile projects each planar B-rep or authored polygon face exactly as it will triangulate it, records each touch against the edge's two shared corners (topological vertex, position index), and inserts the recorded corners into every face's copy of that edge, in order along it. The touching face then sees the corner twice at one point, a pinch it accepts; the neighbour gains a corner on its edge. No position is moved or added, so the volume is unchanged and the shell is closed and two-manifold. - Check what is claimed. A mesh labelled
Solid(a declared B-rep solid, an operation's solid, a boolean result) is checked by index: every edge used exactly twice in opposite directions. Otherwise it isMeshClosure::OpenSolid, whichsolid_meshand booleans refuse by name. This catches what the weld cannot reach, such as a curved B-rep face, which samples its own edges, sharing an edge with a planar face whose corner lies inside it.
| Option | Why not |
|---|---|
| Refuse vertices inside edges on B-rep faces | Valid faceted exports have them (pockets touching a face edge); refusing them drops geometry that tessellates correctly once welded. |
| Repair T-junctions after triangulating | Needs a geometric "on this edge" decision on the welded mesh, separate from the clipper's exact one; the pre-pass reuses the clipper's own. |
Only demote to Surface | Loses the reason: a surface model and a broken solid are different findings for a consumer. |
Amendment 2026-10-09: keyholes on surface paths (#270)
A planar face can carry its hole in one ring: the outer boundary, a seam to the hole, the hole, and the same seam back. Exporters write IfcPolygonalFaceSet faces that way (a downstream triage found 216 such faces, all one shape, refused as "outer ring overlaps itself"). The ring is weakly simple and bounds the outer polygon minus the hole: it is the ring bridge builds before ear clipping, arriving with the bridge in place.
- What a seam is. An edge and a later edge of one ring between the same two points (compared by value) in opposite directions, used by no other edge of any ring, nesting with the ring's other seams like brackets along it. No other edge or seam may meet it except at its ends. Anything else stays an overlap or a crossing, refused by name: running back along part of an edge, one edge twice in one direction or three times, interleaving seams, an edge crossing, touching or running along a seam.
- How. Under
PinchPolicy::Acceptthe seams are removed and each ring falls into the parts they separate; the parts go through the pinch path as rings of their own, named after the ring they came from, so a hole loop is oriented by nesting (either winding is a hole), a seam between two loops side by side leaves two parts, and parts touching at points are pinches. A part with fewer than three vertices or folding back where its seam left it has no area; seams in a row leave their shared end in no part, where a triangle edge could pass it, so they are refused too. - Certificate. The pinch path's, over the parts. As boundary chains the seam's two copies cancel, so the parts' edges bound exactly what the ring bounds, and positive triangles bounded by them tile it once. The seam's ends are repeated vertices, each part keeping its own visit, and triangles use a point's first index in
outer ++ holes. A seam may end up a triangle edge, once each way, or not at all. Where it is not one, the faces that share the seam (a rim's two end faces at its cut) pair along it alone; where it is, the edge has four uses, paired by direction but not two-manifold, which mesh-compile's closure check of #265 reports. Some regions force it: a thin rim seamed at a corner has no triangulation on its own vertices without the seam, since any fan at the outer corner that skips the inner one covers it. - Touches.
profile::ring_touches(#265) validates a ring with seams the same way, without them, and lists the touches of its loops by the ring's own edge and vertex indices. No vertex lies inside a seam, and a seam's ends are shared vertices, not touches. - Solids refuse.
PinchPolicy::Refusenames the seam: an extruded keyhole puts two coincident wall faces on it.
| Option | Why not |
|---|---|
| Accept the bridged ring as given and ear clip it | The clipper's ring is weakly simple only where it built the bridges itself; an input seam crossing or running along other edges would have to be validated the same way, and a seam to a pinched hole needs the pinch path's cycles anyway. |
| Keep the seam as a forced triangle edge | Not needed for a tiling, and only one more edge for the neighbouring faces to share four times. |
| Accept on solids too | An extruded keyhole is not a two-manifold. |
Amendment 2026-10-09: the noise-band split keeps every corner (#278)
The #260 amendment kept mesh-compile's noise-band split (planar::split_invented_edges) after the clipper and said every corner other than an exporter's repeat is a triangle corner. The split broke that. It dropped each sliver whose apex lay within the band (1 um at a millimetre tolerance) of its invented long side, then split the remaining invented edges at every corner within the band of them, a second geometric test. The band is not transitive: on a real cap, v lay 0.4 um off a-b and a 1 um off p1-b, so both slivers (a, v, b) and (b, p1, a) went, but v was more than the band off p1-b, the edge left behind. v was in no triangle of that cap while the side faces kept it, and a closed faceted prism meshed open (OpenSolid since #265).
- The dropped triangles decide. A kept edge whose other side was a dropped sliver takes exactly the corners that sliver's short sides ran through, in order, expanding a short side the same way when the sliver across it was dropped too. The band is consulted once, to call a triangle a sliver, and never again for the corners it removed.
- Checked against the cover. The split is kept only if it bounds the clipper's certified cover along the same edges: every triangle wound as the cover's, each ring edge once in its direction, every other edge once each way, no directed edge twice. Otherwise the face keeps the cover, thin triangles included. The rule stated in #260 now holds again: every ring corner is a triangle corner, and no face drops a corner the faces sharing it keep.
| Option | Why not |
|---|---|
| Drop the split | The clipper's slivers along shared noisy runs put one diagonal into two faces, four uses of one edge (the reason the split stayed in #260). |
| Remove a near-collinear corner from every face sharing it | Moves the shell off its authored corners and needs the bound widened by the offset; keeping the corner costs nothing. |
| Widen or tighten the band | Any band is non-transitive at its edge; the failure depends on the arrangement, not on one distance. |
Amendment 2026-10-13: no seam edge on a face of a shell (#283)
The #270 amendment let a seam be a triangle edge, once each way, and named the cost: faces that also run along the seam (a rim's two end faces at its cut) then meet four triangle uses of that segment, and mesh-compile's closure check (#265) reports the solid as OpenSolid, authored polygons as a surface. Some regions force the seam on the face's own vertices: a thin rim seamed at its corner.
- Faces of a shell take the seam out.
profile::triangulate_shell_face(rings)is theAccepttriangulation followed byseal: for each seam that is a triangle edge, the two triangles on it,(p, q, c)and(q, p, d), are replaced by the other diagonalc dwhen the quadrilateralp d q cis strictly convex, and otherwise by four triangles around a Steiner point strictly inside it and off the seam's line. Every decision is an exactorient2dsign. mesh-compile triangulates planar B-rep faces and authored polygon faces this way (planar::clip_shell_face); 2D regions, surface paths and curve-bounded planes keepAccept, unchanged. - Where the point goes. The seam's midpoint
mlies strictly inside all four half-planes of the quadrilateral, so points near it do too. The candidates aremhalved towardscord, one to 60 times; the first that fits is halved once more, which keeps it inside by halfm's clearance rather than on a line through two corners that only a caller's rounded projection moved apart (the 4 x 4 keyhole projected about its centroid did exactly that: the first fit was collinear with two corners in space, a triangle of no area). If no candidate fits, the seam is refused by name. ASteinerPointis the chain of midpoints itself, so a caller places it in space with the same chain (SteinerPoint::place): on a face in an axis plane every midpoint of two points sharing that coordinate keeps it, and the point lies exactly in the plane. mesh-compile re-checks every triangle at the point, exactly, in the face's projection once placed, and refuses the face by name if one no longer turns counter-clockwise. - Reported, never silent. A face off the axis planes holds its Steiner points within rounding. mesh-compile reports them as the certified deviation
"point added inside a keyhole face, off an axis plane"(pathBRepFaceorAuthoredMesh), bounded by the slab width (#261) of the face's corners and Steiner points about its fit plane: the cover and the mesh both lie in that slab and are graphs over the same projected face, so they differ along the normal by at most its width. A face in an axis plane reports nothing. The bound is a slab width like a warped face's, so the flattened-operand measurement of a boolean (#266) treats it as one: carried by name through booleans, folded into the width the operand is flattened by, and a B-rep whose faces are planes, warped faces or keyhole faces with Steiner points is still measured as a polyhedron. - Certificate. The sealed triangles are certified against the cover they replace: every triangle strictly counter-clockwise, every directed edge once, the same net boundary (each directed edge's uses less its reverse's), two more triangles per Steiner point, and no triangle edge on a seam. Positive triangles with the boundary of a certified cover cover every point the same number of times, its winding number, so they tile the same region once: a Steiner point adds no area and moves no boundary. The noise-band split (#278) runs after it and is kept only if it puts no edge back on a seam.
- What was already closed. In a two-manifold shell no other face can use the seam: the keyhole face already uses its edge twice. There a seam triangle edge was only a diagonal of the face, used twice in opposite directions, and a box whose top face is a keyhole into a pocket compiled as a closed
Solidbefore this change too. The four uses need faces that run along the seam, such as coincident faces at a rim's cut; those shells now pair along it.
| Option | Why not |
|---|---|
| Duplicate the seam's ends in the output | Each copy of the seam is then a separate edge, but the faces sharing the seam pair with only one copy: edge pairing breaks. |
| Accept a seam used four times with balanced direction as closed | Weakens #265's guarantee that a Solid is two-manifold by index. |
| Place the Steiner point by lifting its plane position through the projection | The projection origin (an authored face's centroid) is rounded, so even a face in an axis plane would get the point off it. |
The mutation probe scripts/probe_keyhole_shell_mutants.py covers the seal, the certificate, the placement and report in mesh-compile, and the issue's related cleanup (pinch::find welding -0.0 with 0.0): 22 / 22 mutants killed on the first run.