From 47497f4153222ddabf798ec2e35e248a0c8c0101 Mon Sep 17 00:00:00 2001 From: AJ Isaacs Date: Sun, 29 Nov 2026 12:24:19 -0500 Subject: [PATCH] refactor(engine): share the strip edge loops in IterativeShrinkFiller Co-Authored-By: Claude Opus 5.5 --- OpenNest.Engine/Fill/IterativeShrinkFiller.cs | 48 +++++++++---------- 1 file changed, 22 insertions(+), 26 deletions(-) diff --git a/OpenNest.Engine/Fill/IterativeShrinkFiller.cs b/OpenNest.Engine/Fill/IterativeShrinkFiller.cs index f96a586c..5f328070 100644 --- a/OpenNest.Engine/Fill/IterativeShrinkFiller.cs +++ b/OpenNest.Engine/Fill/IterativeShrinkFiller.cs @@ -270,39 +270,35 @@ namespace OpenNest.Engine.Fill parts.AddRange(s); } - private static double MaxTop(List col) + private static double MaxTop(List col) => MaxEdge(col, static b => b.Top); + + private static double MaxRight(List col) => MaxEdge(col, static b => b.Right); + + private static double MinLeft(List col) => MinEdge(col, static b => b.Left); + + private static double MinBottom(List row) => MinEdge(row, static b => b.Bottom); + + private static double MaxEdge(List parts, Func edge) { var max = double.MinValue; - foreach (var p in col) - if (p.BoundingBox.Top > max) - max = p.BoundingBox.Top; + foreach (var p in parts) + { + var value = edge(p.BoundingBox); + if (value > max) + max = value; + } return max; } - private static double MaxRight(List col) - { - var max = double.MinValue; - foreach (var p in col) - if (p.BoundingBox.Right > max) - max = p.BoundingBox.Right; - return max; - } - - private static double MinLeft(List col) + private static double MinEdge(List parts, Func edge) { var min = double.MaxValue; - foreach (var p in col) - if (p.BoundingBox.Left < min) - min = p.BoundingBox.Left; - return min; - } - - private static double MinBottom(List row) - { - var min = double.MaxValue; - foreach (var p in row) - if (p.BoundingBox.Bottom < min) - min = p.BoundingBox.Bottom; + foreach (var p in parts) + { + var value = edge(p.BoundingBox); + if (value < min) + min = value; + } return min; } }