fix(compactor): a tabbed part pushes away from a neighbor at the spacing

A part whose planned outside carries a perimeter tab could not be pushed
away from a neighbor it rested against at the part spacing, and the
neighbor could not be pushed away from it: the push returned 0 with open
sheet ahead. It showed whenever the neighbor's bounds wrapped the part
(an eared or C-shaped neighbor), since otherwise the broad phase skips an
obstacle that is wholly behind.

The tab stops the cut short of its entry, so with the leads dropped the
outside is an open chain. Its spacing-offset contour does not close, the
slide kernel cannot tell which side of it is material, and it blocks
every contact against a boundary it cannot resolve. The parts were never
closer than the spacing.

PartGeometry now closes a tabbed contour across its tab before any
offset: the trimmed last cut is restored along its own line or arc
(exact), a round outside cut as one arc becomes its circle, and a tab
that swallowed whole entities is bridged by its chord, as flattening to
a polygon already closes it. Only a single gap is closed; closed
material is returned untouched, so untabbed parts and the fills see the
same geometry as before. No kernel code or tolerance changed, so a push
into a neighbor still returns 0 and a contour cut in several pieces
still blocks.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
ajandClaude Fable 5.2 committed 2026-11-20 08:30:56 -05:00
1 parent e84542e5f6
commit 3544e924c1
5 files changed
+531 -3

No files matched your search

+4 -2
View File
@@ -11,12 +11,14 @@ namespace OpenNest
/// Nesting material of a program, without lead-ins and lead-outs: a lead is a cut
/// into scrap, not part material, and chaining it into the perimeter leaves an open
/// spur, so the offset contour no longer closes and every slide contact against it
/// blocks.
/// blocks. A perimeter tab leaves the same open chain, so the contour is closed
/// across it (<see cref="NestingMaterial.ClosedAcrossTab"/>).
/// </summary>
private static List<Entity> MaterialEntities(CNC.Program program) =>
ConvertProgram.ToGeometry(program)
.Where(e => e.Layer != SpecialLayers.Leadin && e.Layer != SpecialLayers.Leadout)
.ForNesting();
.ForNesting()
.ClosedAcrossTab();
public static List<Line> GetPartLines(Part part, double chordTolerance = 0.001)
{
@@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.Linq;
using OpenNest.Geometry;
using OpenNest.Math;
namespace OpenNest
{
@@ -25,5 +26,143 @@ namespace OpenNest
kept.AddRange(shape.Entities);
return kept;
}
/// <summary>
/// <paramref name="material"/> with a tabbed contour closed across its tab. A perimeter
/// tab stops the cut short of its entry, so a planned outside is an open chain, yet the
/// part's material still reaches across the gap. Offsetting the open chain gives a
/// contour that does not close, and the slide kernel blocks every contact against a
/// boundary it cannot close, freezing the part and its neighbors where they touch.
/// The trimmed last cut is restored along its own line or arc when the entry lies on
/// it, which is exact; when the tab swallowed whole entities the gap is bridged by its
/// chord, as flattening the contour to a polygon closes it. Only a single gap is
/// closed: material with no open chain is returned unchanged, and so is material with
/// several gaps (a contour cut in pieces) or a lone line.
/// </summary>
internal static List<Entity> ClosedAcrossTab(this List<Entity> material)
{
const double tolerance = Tolerance.ChainTolerance;
// Runs of entities chained end to start in list order. A planned contour is one
// run; regrouping by shape can split it where its first entity is an arc.
List<(int First, int Last, Vector Start, Vector End)> open = null;
for (var i = 0; i < material.Count; i++)
{
if (!EntityEndpoints.TryGet(material[i], out var start, out var end))
continue;
var first = i;
while (end.DistanceTo(start) > tolerance
&& i + 1 < material.Count
&& EntityEndpoints.TryGet(material[i + 1], out var nextStart, out var nextEnd)
&& nextStart.DistanceTo(end) <= tolerance)
{
end = nextEnd;
i++;
}
if (end.DistanceTo(start) > tolerance)
(open ??= new List<(int, int, Vector, Vector)>()).Add((first, i, start, end));
}
if (open == null)
return material;
// The tab gap runs from the one end no open run starts at to the one start no
// open run ends at; both must belong to the same chain of runs.
var tail = -1;
var head = -1;
for (var r = 0; r < open.Count; r++)
{
var run = open[r];
if (!open.Exists(other => other.Start.DistanceTo(run.End) <= tolerance))
{
if (tail >= 0)
return material;
tail = r;
}
if (!open.Exists(other => other.End.DistanceTo(run.Start) <= tolerance))
{
if (head >= 0)
return material;
head = r;
}
}
if (tail < 0 || head < 0)
return material;
var at = head;
for (var steps = 0; at != tail; steps++)
{
var from = open[at].End;
at = open.FindIndex(other => other.Start.DistanceTo(from) <= tolerance);
if (at < 0 || steps >= open.Count)
return material;
}
var index = open[tail].Last;
var last = material[index];
var gapStart = open[tail].End;
var gapEnd = open[head].Start;
var alone = head == tail && open[head].First == index;
switch (last)
{
case Line when alone:
return material;
// A round outside cut as one arc that stops short of its own start.
case Arc arc when alone && OnCircle(arc, gapEnd, tolerance):
material[index] = new Circle(arc.Center, arc.Radius)
{
Rotation = arc.IsReversed ? RotationType.CW : RotationType.CCW,
Layer = arc.Layer,
};
return material;
case Arc arc when OnCircle(arc, gapEnd, tolerance):
var extended = new Arc(arc.Center, arc.Radius, arc.StartAngle,
arc.Center.AngleTo(gapEnd), arc.IsReversed)
{
Layer = arc.Layer,
};
var added = extended.SweepAngle() - arc.SweepAngle();
if (added > 0 && added < System.Math.PI)
{
material[index] = extended;
return material;
}
break;
case Line line when Continues(line, gapEnd, tolerance):
material[index] = new Line(line.StartPoint, gapEnd) { Layer = line.Layer };
return material;
}
material.Insert(index + 1, new Line(gapStart, gapEnd) { Layer = last.Layer });
return material;
}
private static bool OnCircle(Arc arc, Vector point, double tolerance) =>
System.Math.Abs(arc.Center.DistanceTo(point) - arc.Radius) <= tolerance;
/// <summary>True when <paramref name="point"/> lies on the extension of
/// <paramref name="line"/> past its end.</summary>
private static bool Continues(Line line, Vector point, double tolerance)
{
var dx = line.EndPoint.X - line.StartPoint.X;
var dy = line.EndPoint.Y - line.StartPoint.Y;
var length = System.Math.Sqrt(dx * dx + dy * dy);
if (length <= tolerance)
return false;
var px = point.X - line.EndPoint.X;
var py = point.Y - line.EndPoint.Y;
return System.Math.Abs(dx * py - dy * px) / length <= tolerance
&& dx * px + dy * py > 0;
}
}
}
@@ -0,0 +1,208 @@
using System.Collections.Generic;
using System.Linq;
using OpenNest.CNC;
using OpenNest.Engine.Fill;
using OpenNest.Geometry;
using Xunit;
namespace OpenNest.Tests.Fill;
/// <summary>
/// A part whose planned outside stops short of its entry (a perimeter tab) pushes like any
/// other part. Its cut is an open chain; unless the contour is closed across the tab, its
/// spacing-offset contour does not close and the slide kernel blocks every contact, so the
/// part cannot leave a neighbor it rests against at the part spacing.
/// </summary>
public class CompactorTabbedPartTests
{
private const double Spacing = 0.25;
private const double Width = 3.4375;
private const double Height = 5.5;
private const double Radius = 0.1875;
private const double Tab = 0.03;
private static readonly Box WorkArea = new(0, 0, 40, 20);
// A rounded rectangle cut clockwise from the middle of its top-right corner, with a
// lead-in, a lead-out and a tab: the cut ends a tab short of where it started.
private static Part TabbedPart(double x, double y, bool tabbed = true)
{
var corner = new Vector(Width - Radius, Height - Radius);
var entryAngle = System.Math.PI / 4;
var endAngle = tabbed ? entryAngle + 2 * System.Math.Asin(Tab / (2 * Radius)) : entryAngle;
var entry = corner + new Vector(System.Math.Cos(entryAngle), System.Math.Sin(entryAngle)) * Radius;
var end = corner + new Vector(System.Math.Cos(endAngle), System.Math.Sin(endAngle)) * Radius;
var program = new Program();
program.Codes.Add(new RapidMove(entry + new Vector(0.15, 0.15)));
program.Codes.Add(new LinearMove(entry) { Layer = LayerType.Leadin });
program.Codes.Add(new ArcMove(new Vector(Width, Height - Radius), corner, RotationType.CW));
program.Codes.Add(new LinearMove(Width, Radius));
program.Codes.Add(new ArcMove(new Vector(Width - Radius, 0), new Vector(Width - Radius, Radius), RotationType.CW));
program.Codes.Add(new LinearMove(Radius, 0));
program.Codes.Add(new ArcMove(new Vector(0, Radius), new Vector(Radius, Radius), RotationType.CW));
program.Codes.Add(new LinearMove(0, Height - Radius));
program.Codes.Add(new ArcMove(new Vector(Radius, Height), new Vector(Radius, Height - Radius), RotationType.CW));
program.Codes.Add(new LinearMove(Width - Radius, Height));
program.Codes.Add(new ArcMove(end, corner, RotationType.CW));
program.Codes.Add(new LinearMove(end + new Vector(0.02, 0.1)) { Layer = LayerType.Leadout });
var part = new Part(new Drawing("tabbed", program)) { Location = new Vector(x, y) };
part.UpdateBounds();
return part;
}
// A C opening to the left: its body's left edge is at x = 10 and its ears reach left to
// x = 4 above and below the notch (y 2..12), so its bounds wrap a part resting in the notch.
private static Part EaredNeighbor()
{
var program = new Program();
program.Codes.Add(new RapidMove(4, 0));
program.Codes.Add(new LinearMove(14, 0));
program.Codes.Add(new LinearMove(14, 14));
program.Codes.Add(new LinearMove(4, 14));
program.Codes.Add(new LinearMove(4, 12));
program.Codes.Add(new LinearMove(10, 12));
program.Codes.Add(new LinearMove(10, 2));
program.Codes.Add(new LinearMove(4, 2));
program.Codes.Add(new LinearMove(4, 0));
var part = new Part(new Drawing("eared", program));
part.UpdateBounds();
return part;
}
/// <summary>The tabbed part in the notch, its right edge one spacing from the body.</summary>
private static Part RestingPart() => TabbedPart(10 - Spacing - Width, 4.25);
private static double Push(Part moving, Part obstacle, PushDirection direction) =>
Compactor.Push(new List<Part> { moving }, new List<Part> { obstacle }, WorkArea, Spacing, direction);
private static double MaterialGap(Part a, Part b)
{
var first = NativeContours.Of(new ShapeProfile(PartGeometry.GetPartEntities(a)), new Vector(0, 0));
var second = NativeContours.Of(new ShapeProfile(PartGeometry.GetPartEntities(b)), new Vector(0, 0));
Assert.False(first.TooClose(second, Spacing));
return PartGeometry.GetPartLines(a).Min(line =>
PartGeometry.GetPartLines(b).Min(other => System.Math.Min(
System.Math.Min(line.StartPoint.DistanceTo(other.ClosestPointTo(line.StartPoint)),
line.EndPoint.DistanceTo(other.ClosestPointTo(line.EndPoint))),
System.Math.Min(other.StartPoint.DistanceTo(line.ClosestPointTo(other.StartPoint)),
other.EndPoint.DistanceTo(line.ClosestPointTo(other.EndPoint))))));
}
[Fact]
public void TabbedPartHasAClosedSpacingContour()
{
var part = RestingPart();
var offset = PartGeometry.GetOffsetPerimeterEntities(part, Spacing / 2);
Assert.True(SlideContactGeometry.Prepare(offset).IsResolved);
var all = PartGeometry.GetOffsetPartEntities(part, Spacing / 2);
Assert.Equal(offset.Count, all.Count);
Assert.True(SlideContactGeometry.Prepare(all).IsResolved);
}
[Fact]
public void PushAwayFromANeighborAtTheSpacingMoves()
{
var neighbor = EaredNeighbor();
var part = RestingPart();
Assert.Equal(Spacing, MaterialGap(part, neighbor), 6);
// The neighbor's bounds wrap the part, so the broad phase cannot skip it as behind.
Assert.True(neighbor.BoundingBox.Left < part.BoundingBox.Left);
var expected = part.BoundingBox.Left - WorkArea.Left;
var moved = Push(part, neighbor, PushDirection.Left);
Assert.Equal(expected, moved, 6);
}
[Fact]
public void NeighborPushesAwayFromATabbedPartAtTheSpacing()
{
var neighbor = EaredNeighbor();
var part = RestingPart();
var expected = WorkArea.Right - neighbor.BoundingBox.Right;
var moved = Push(neighbor, part, PushDirection.Right);
Assert.Equal(expected, moved, 6);
}
[Theory]
[InlineData(PushDirection.Up)]
[InlineData(PushDirection.Down)]
public void PushAlongANeighborAtTheSpacingSlidesToItsEar(PushDirection direction)
{
var neighbor = EaredNeighbor();
var part = RestingPart();
var moved = Push(part, neighbor, direction);
// 2.25 of room to each ear, less the spacing.
Assert.Equal(2.0, moved, 6);
Assert.Equal(Spacing, MaterialGap(part, neighbor), 6);
}
[Fact]
public void PushIntoANeighborAtTheSpacingStaysPut()
{
var neighbor = EaredNeighbor();
var part = RestingPart();
Assert.Equal(0, Push(part, neighbor, PushDirection.Right));
Assert.Equal(0, Push(neighbor, part, PushDirection.Left));
}
[Fact]
public void PushTowardANeighborStopsAtTheSpacing()
{
var neighbor = EaredNeighbor();
var part = RestingPart();
part.Offset(-2, 0);
var moved = Push(part, neighbor, PushDirection.Right);
Assert.Equal(2.0, moved, 6);
Assert.Equal(Spacing, MaterialGap(part, neighbor), 6);
}
[Theory]
[InlineData(PushDirection.Left)]
[InlineData(PushDirection.Right)]
[InlineData(PushDirection.Up)]
[InlineData(PushDirection.Down)]
public void OverlappingTabbedPartPushesLikeAnUntabbedOne(PushDirection direction)
{
var neighbor = EaredNeighbor();
// Material in material: the part's right side is inside the neighbor's body.
var tabbed = TabbedPart(10 - Width + 1, 4.25);
var untabbed = TabbedPart(10 - Width + 1, 4.25, tabbed: false);
Assert.Equal(Push(untabbed, neighbor, direction), Push(tabbed, neighbor, direction), 6);
}
[Fact]
public void MaterialAcrossTheTabStopsAPush()
{
// A rectangle entered on its right edge with a half-inch tab there, and a small block
// level with the tab: the uncut span is still material and must keep the spacing.
var program = new Program();
program.Codes.Add(new RapidMove(3, 2.25));
program.Codes.Add(new LinearMove(3, 0));
program.Codes.Add(new LinearMove(0, 0));
program.Codes.Add(new LinearMove(0, 5));
program.Codes.Add(new LinearMove(3, 5));
program.Codes.Add(new LinearMove(3, 2.75));
var part = new Part(new Drawing("wide tab", program));
part.UpdateBounds();
var block = new Part(TestHelpers.MakeRectDrawing(0.2, 0.2)) { Location = new Vector(8, 2.4) };
block.UpdateBounds();
var moved = Push(part, block, PushDirection.Right);
Assert.Equal(8 - 3 - Spacing, moved, 6);
}
}
@@ -0,0 +1,177 @@
using System.Collections.Generic;
using OpenNest.Geometry;
using Xunit;
namespace OpenNest.Tests.TabbedCutouts;
/// <summary>
/// <see cref="NestingMaterial.ClosedAcrossTab"/>: a contour whose cut stops short of its
/// start is closed across that one gap, and nothing else is touched.
/// </summary>
public class TabClosureTests
{
private static Line L(double x1, double y1, double x2, double y2) =>
new(new Vector(x1, y1), new Vector(x2, y2)) { Layer = SpecialLayers.Cut };
private static void AssertClosedLoop(List<Entity> entities)
{
var shapes = ShapeBuilder.GetShapes(entities);
Assert.Single(shapes);
Assert.True(shapes[0].IsClosed());
Assert.True(SlideContactGeometry.Prepare(shapes[0].Entities).IsResolved);
}
[Fact]
public void ClosedContourIsReturnedUnchanged()
{
var entities = new List<Entity> { L(0, 0, 4, 0), L(4, 0, 4, 3), L(4, 3, 0, 3), L(0, 3, 0, 0) };
var before = entities.ToArray();
var closed = entities.ClosedAcrossTab();
Assert.Same(entities, closed);
Assert.Equal(before, closed);
}
[Fact]
public void TrimmedLineIsExtendedToTheEntry()
{
// Entered mid-edge at (2, 3), cut clockwise, stopping 0.03 short of the entry.
var entities = new List<Entity>
{
L(2, 3, 4, 3), L(4, 3, 4, 0), L(4, 0, 0, 0), L(0, 0, 0, 3), L(0, 3, 1.97, 3),
};
var closed = entities.ClosedAcrossTab();
Assert.Equal(5, closed.Count);
var last = Assert.IsType<Line>(closed[4]);
Assert.Equal(new Vector(0, 3), last.StartPoint);
Assert.Equal(new Vector(2, 3), last.EndPoint);
Assert.Same(SpecialLayers.Cut, last.Layer);
AssertClosedLoop(closed);
}
[Fact]
public void TrimmedArcIsExtendedAlongItsCircle()
{
// A quarter-round corner entered at 45 degrees and cut clockwise; the cut returns
// along the same corner and stops at 60 degrees.
var center = new Vector(3, 2);
var entry = Angle(45);
var entities = new List<Entity>
{
new Arc(center, 1, entry, 0, true) { Layer = SpecialLayers.Cut },
L(4, 2, 4, 0), L(4, 0, 0, 0), L(0, 0, 0, 3), L(0, 3, 3, 3),
new Arc(center, 1, Angle(90), Angle(60), true) { Layer = SpecialLayers.Cut },
};
var closed = entities.ClosedAcrossTab();
Assert.Equal(6, closed.Count);
var last = Assert.IsType<Arc>(closed[5]);
Assert.True(last.IsReversed);
Assert.Equal(Angle(90), last.StartAngle, 12);
Assert.Equal(entry, last.EndAngle, 12);
Assert.Equal(1, last.Radius);
AssertClosedLoop(closed);
}
[Theory]
[InlineData(true)]
[InlineData(false)]
public void RoundOutsideCutAsOneArcBecomesACircle(bool clockwise)
{
var arc = new Arc(new Vector(5, 5), 2, 1, clockwise ? 1.02 : 0.98, clockwise) { Layer = SpecialLayers.Cut };
Assert.True(arc.SweepAngle() > 6);
var entities = new List<Entity> { arc };
var closed = entities.ClosedAcrossTab();
var circle = Assert.IsType<Circle>(Assert.Single(closed));
Assert.Equal(new Vector(5, 5), circle.Center);
Assert.Equal(2, circle.Radius);
Assert.Equal(clockwise ? RotationType.CW : RotationType.CCW, circle.Rotation);
Assert.Same(SpecialLayers.Cut, circle.Layer);
}
[Fact]
public void TabThatSwallowsACornerIsBridgedByItsChord()
{
// Entered 0.01 past the top-left corner: the tab removed the corner's last stub and
// trimmed the left edge, so the gap is not on the last cut's own line.
var entities = new List<Entity>
{
L(0.01, 3, 4, 3), L(4, 3, 4, 0), L(4, 0, 0, 0), L(0, 0, 0, 2.98),
};
var closed = entities.ClosedAcrossTab();
Assert.Equal(5, closed.Count);
var bridge = Assert.IsType<Line>(closed[4]);
Assert.Equal(new Vector(0, 2.98), bridge.StartPoint);
Assert.Equal(new Vector(0.01, 3), bridge.EndPoint);
AssertClosedLoop(closed);
}
[Fact]
public void ContourSplitByShapeGroupingIsStillClosed()
{
// The contour's first arc listed after the chain it leads into, as regrouping by
// shape leaves it: two open runs, one gap.
var center = new Vector(3, 2);
var entities = new List<Entity>
{
L(4, 2, 4, 0), L(4, 0, 0, 0), L(0, 0, 0, 3), L(0, 3, 3, 3),
new Arc(center, 1, Angle(90), Angle(60), true) { Layer = SpecialLayers.Cut },
new Arc(center, 1, Angle(45), 0, true) { Layer = SpecialLayers.Cut },
};
var closed = entities.ClosedAcrossTab();
Assert.Equal(6, closed.Count);
Assert.Equal(Angle(45), Assert.IsType<Arc>(closed[4]).EndAngle, 12);
AssertClosedLoop(closed);
}
[Fact]
public void OtherClosedContoursAreKept()
{
var hole = new Circle(new Vector(2, 1.5), 0.5) { Layer = SpecialLayers.Cut };
var entities = new List<Entity>
{
hole, L(2, 3, 4, 3), L(4, 3, 4, 0), L(4, 0, 0, 0), L(0, 0, 0, 3), L(0, 3, 1.97, 3),
};
var closed = entities.ClosedAcrossTab();
Assert.Equal(6, closed.Count);
Assert.Same(hole, closed[0]);
Assert.Equal(new Vector(2, 3), Assert.IsType<Line>(closed[5]).EndPoint);
}
[Fact]
public void ContourCutInPiecesIsLeftAlone()
{
// Two gaps: which ends belong together is not a tab's question.
var entities = new List<Entity>
{
L(2, 3, 4, 3), L(4, 3, 4, 1), L(4, 0, 0, 0), L(0, 0, 0, 3), L(0, 3, 1.97, 3),
};
var before = entities.ToArray();
var closed = entities.ClosedAcrossTab();
Assert.Equal(before, closed);
}
[Fact]
public void LoneLineIsLeftAlone()
{
var entities = new List<Entity> { L(0, 0, 4, 0) };
Assert.Equal(new[] { entities[0] }, entities.ClosedAcrossTab());
}
private static double Angle(double degrees) => degrees * System.Math.PI / 180;
}
+3 -1
View File
@@ -6,7 +6,7 @@ For initially non-overlapping closed material boundaries, a directional slide st
`SpatialQuery.DirectionalDistance` overloads and CPU best-fit batches use the same event sources and contact resolver. Events carry both contact points in their initial world frames, rather than only a snapped distance. The classifier uses closed-loop material sectors, native-curve containment for hole depth, and the curvature of the supporting boundary at a tangential contact. A full-circle arc has no physical corner at its seam. Raw ray helpers remain first-touch primitives, not material-aware slide queries.
Open/incomplete chains and ambiguous contacts conservatively block. Loops are recovered with ShapeBuilder's `Tolerance.ChainTolerance`, so a source contour that closes within it (PEP-rounded drawings can miss by 1e-6) stays a closed loop; a stricter closure test would leave the whole part unresolved and freeze any part resting against it. Rounded arc centers also tilt a joint's tangents (about gap / radius), so two parts touching along a shared edge can give a contact cone a hair wider than a half-plane; the classifier reads a cone up to `SlideContact.TangentSlack` (1e-4 rad) past a half-plane as a noisy half-plane and treats directions within that excess of its boundary as tangential, so a part can still slide along its neighbor. A wider cone is real overlap and blocks. This is not an overlap-repair operation or a general replacement for layout validation. Caller-provided contact topology must represent the same boundaries and offsets as the query. Prepared geometry must not be mutated; prepare a classifier before sharing it between parallel queries. Edge-array queries still sort their arrays, and recover loop order from private copies before classifying contacts.
Open/incomplete chains and ambiguous contacts conservatively block. Loops are recovered with ShapeBuilder's `Tolerance.ChainTolerance`, so a source contour that closes within it (PEP-rounded drawings can miss by 1e-6) stays a closed loop; a stricter closure test would leave the whole part unresolved and freeze any part resting against it. Rounded arc centers also tilt a joint's tangents (about gap / radius), so two parts touching along a shared edge can give a contact cone a hair wider than a half-plane; the classifier reads a cone up to `SlideContact.TangentSlack` (1e-4 rad) past a half-plane as a noisy half-plane and treats directions within that excess of its boundary as tangential, so a part can still slide along its neighbor. A wider cone is real overlap and blocks. A planned outside with a perimeter tab is such an open chain (the cut stops a tab short of its entry), so `PartGeometry` closes it across the tab before offsetting (`NestingMaterial.ClosedAcrossTab`): the trimmed last cut is restored along its own line or arc, which is exact, or the gap is bridged by its chord when the tab swallowed whole entities, as flattening to a polygon closes it. Only a single gap is closed; a contour cut in several pieces still blocks. Without the closure a tabbed part cannot be pushed away from a neighbor it rests against, and neither can the neighbor. This is not an overlap-repair operation or a general replacement for layout validation. Caller-provided contact topology must represent the same boundaries and offsets as the query. Prepared geometry must not be mutated; prepare a classifier before sharing it between parallel queries. Edge-array queries still sort their arrays, and recover loop order from private copies before classifying contacts.
## Callers
@@ -26,6 +26,8 @@ Open/incomplete chains and ambiguous contacts conservatively block. Loops are re
`CompactorTests` covers the reported sequence (push left with spacing, then right/up/down), genuine zero-distance blocking, zero/nonzero-spacing later hooks, and inside-hole pushes through both direct and plate entry points. Physical spacing is measured from raw outlines rather than the inflated contours used by the solver.
`CompactorTabbedPartTests` covers a tabbed, lead-carrying part resting at the spacing in the notch of an eared neighbor whose bounds wrap it: pushes away (either part moving), along, into and from a distance, an overlapping start compared with an untabbed twin, and a block level with a wide tab. `TabClosureTests` covers the closure itself: line and arc restoration, a round outside cut as one arc, a swallowed corner, a contour regrouped by shape, and the cases left alone.
`CrescentPairSpacingTests` covers an arc-only part with round spacing caps on two sharp tips: the first contact of a small convex cap against a large convex arc away from every vertex, and every pair the best-fit search builds at five part 2 rotations. Its spacing oracle flattens material entities only; counting a program's opening rapid as outline reports false violations (see [pair-spacing checks](pair-spacing.md)).
Verification commands: