From 7622d6355656fb77c5017ea89c28457ff85a7128 Mon Sep 17 00:00:00 2001 From: AJ Isaacs Date: Wed, 7 Oct 2026 15:12:06 -0400 Subject: [PATCH] test(cutting): cover facing starts and safe fallbacks --- .../PerimeterLookAheadTests.cs | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/OpenNest.Tests/CuttingPlanning/PerimeterLookAheadTests.cs b/OpenNest.Tests/CuttingPlanning/PerimeterLookAheadTests.cs index cd00268..570f230 100644 --- a/OpenNest.Tests/CuttingPlanning/PerimeterLookAheadTests.cs +++ b/OpenNest.Tests/CuttingPlanning/PerimeterLookAheadTests.cs @@ -86,6 +86,38 @@ public class PerimeterLookAheadTests Assert.True(entry.X >= 10.0 - 1e-9, $"first entry {entry} faces away from the next part"); } + [Fact] + public void ManyVertices_FacingCornerSurvivesBeyondTheDrawingOrderEntryCap() + { + // Start at the leftmost vertex and travel clockwise. The initial sixteen + // drawing-order catalogue entries only cover the upper-left part of the ring; + // the useful lower-right corner appears later and must survive until ranking. + var source = new Program(); + var vertices = Enumerable.Range(0, 32).Select(i => + { + var angle = System.Math.PI - i * 2 * System.Math.PI / 32; + return new Vector(10 + 10 * System.Math.Cos(angle), 10 + 10 * System.Math.Sin(angle)); + }).ToArray(); + source.MoveTo(vertices[0].X, vertices[0].Y); + foreach (var point in vertices.Skip(1).Append(vertices[0])) + source.LineTo(point.X, point.Y); + var parameters = Parameters(); + var polygon = new Part(new Drawing("many-vertex", source)) { CuttingParameters = parameters }; + var next = Square(25, parameters); + var before = ExplicitContourTests.Fingerprint(polygon.Program); + + var result = CuttingPlanService.Plan(Request([polygon, next], parameters)); + + Assert.True(result.Status == CuttingPlanStatus.Ready, Describe(result)); + Assert.True(result.IndependentlyReplayed); + Assert.Equal(new[] { 0, 1 }, result.ProposedOrder.Select(p => p.SourceOrdinal)); + var chosen = result.ProposedOrder[0]; + var entry = Assert.Single(chosen.ContourChoices).Point + chosen.Location; + Assert.True(entry.X > 15 && entry.Y < 5, $"entry {entry} lost the lower-right facing corner to an early cap"); + Assert.Contains(vertices, vertex => vertex.DistanceTo(entry) < 1e-6); + Assert.Equal(before, ExplicitContourTests.Fingerprint(polygon.Program)); + } + [Fact] public void EmittedRapidsNoWorseThanTheMeasuredLegacyLayout() {