From 2721375e8b8574bafd73add64eee178539f09b58 Mon Sep 17 00:00:00 2001 From: AJ Isaacs Date: Tue, 3 Nov 2026 10:03:13 -0500 Subject: [PATCH] fix(ui): dash a cut-off's head-locked overcut past the sheet edge The cut-off line renderer paired codes as rapid/cut at even indices. A head-locked far-edge segment carries lock and unlock comments between its cuts, so its overcut was never dashed and later segments could fall out of step. Past the sheet only the dark part outline showed, which read as the line having lost its orange-red color. Walk the motions instead and draw each cut from the previous point. Co-Authored-By: Claude Opus 5.5 --- OpenNest.WinForms.Tests/CutOffDisplayTests.cs | 29 +++++++++++++++++++ OpenNest/Controls/PlateRenderer.cs | 18 +++++++----- 2 files changed, 39 insertions(+), 8 deletions(-) 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; } }