diff --git a/OpenNest.WinForms.Tests/CutOffDisplayTests.cs b/OpenNest.WinForms.Tests/CutOffDisplayTests.cs index 096e1b5c..1453ba2e 100644 --- a/OpenNest.WinForms.Tests/CutOffDisplayTests.cs +++ b/OpenNest.WinForms.Tests/CutOffDisplayTests.cs @@ -77,6 +77,35 @@ public class CutOffDisplayTests } }, TimeSpan.FromMinutes(1), "Cut-off display test timed out."); + [Fact] + public void HeadLockedOvercutPastTheSheetIsDashedOrange() => StaTestThread.Run(() => + { + // Quadrant 4's far edge for a vertical cut-off is the bottom (graph row 100); a 10 + // overcut runs on to row 110, past the sheet. + var (view, cutoff) = BuildPlateWithCutOff(); + using (view) + using (var image = new Bitmap(100, 130)) + using (var g = Graphics.FromImage(image)) + { + cutoff.HeadLockOvercut = 10; + view.Plate.RegenerateCutOffs(new CutOffSettings()); + g.Clear(Color.White); + view.Renderer.DrawCutOffs(g); + + var overcut = 0; + for (var y = 102; y <= 109; y++) + for (var x = 48; x <= 52; x++) + { + var c = image.GetPixel(x, y); + if (c.R >= 200 && c.G <= 120 && c.B <= 80) + overcut++; + } + Assert.True(overcut >= 4, $"Expected the orange dash on the overcut, found {overcut} pixels."); + var (orange, _, _, _) = CountLinePixels(image); + Assert.True(orange >= 10, $"Expected the orange dash on the sheet, found {orange} pixels."); + } + }, TimeSpan.FromMinutes(1), "Head-locked cut-off display test timed out."); + [Fact] public void SelectedCutOffKeepsSolidBlueHighlight() => StaTestThread.Run(() => { diff --git a/OpenNest/Controls/PlateRenderer.cs b/OpenNest/Controls/PlateRenderer.cs index 32b6a6c9..04765be6 100644 --- a/OpenNest/Controls/PlateRenderer.cs +++ b/OpenNest/Controls/PlateRenderer.cs @@ -382,17 +382,19 @@ namespace OpenNest.Controls } } + // Walk the motions rather than pairing rapid/cut codes: a head-locked far-edge segment + // carries lock comments between its cuts, and its overcut past the sheet must dash too. private void DrawCutOffSegments(Graphics g, Program program, Vector offset, Pen pen) { - for (var i = 0; i < program.Codes.Count - 1; i += 2) + Vector? position = null; + foreach (var code in program.Codes) { - if ( - program.Codes[i] is RapidMove rapid - && program.Codes[i + 1] is LinearMove linear - ) - { - DrawLine(g, rapid.EndPoint + offset, linear.EndPoint + offset, pen); - } + if (code is not Motion motion) + continue; + var end = motion.EndPoint + offset; + if (motion is LinearMove && position is { } start) + DrawLine(g, start, end, pen); + position = end; } }