From ae88c34361d445749c85f42571afbbbde6b82826 Mon Sep 17 00:00:00 2001 From: AJ Isaacs Date: Fri, 20 Mar 2026 14:43:45 -0400 Subject: [PATCH] fix: prioritize width-fitting candidates in PairFiller strip mode In strip mode, build candidate list entirely from pairs whose ShortestSide fits the narrow work area dimension, sorted by estimated tile count. Previously, the top-50 utilization cut ran first, excluding good strip candidates like #183. Co-Authored-By: Claude Opus 4.6 (1M context) --- OpenNest.Engine/Fill/PairFiller.cs | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/OpenNest.Engine/Fill/PairFiller.cs b/OpenNest.Engine/Fill/PairFiller.cs index ba620b6..18dc1c6 100644 --- a/OpenNest.Engine/Fill/PairFiller.cs +++ b/OpenNest.Engine/Fill/PairFiller.cs @@ -168,35 +168,30 @@ namespace OpenNest.Engine.Fill private List SelectPairCandidates(List bestFits, Box workArea) { var kept = bestFits.Where(r => r.Keep).ToList(); - var top = kept.Take(MaxTopCandidates).ToList(); var workShortSide = System.Math.Min(workArea.Width, workArea.Length); var plateShortSide = System.Math.Min(plateSize.Width, plateSize.Length); if (workShortSide < plateShortSide * 0.5) { - var stripCandidates = bestFits + // Strip mode: prioritize candidates that fit the narrow dimension. + var stripCandidates = kept .Where(r => r.ShortestSide <= workShortSide + Tolerance.Epsilon && r.Utilization >= MinStripUtilization) - .OrderByDescending(r => r.Utilization); + .ToList(); - var existing = new HashSet(top); + SortByEstimatedCount(stripCandidates, workArea); - foreach (var r in stripCandidates) - { - if (top.Count >= MaxStripCandidates) - break; - - if (existing.Add(r)) - top.Add(r); - } + var top = stripCandidates.Take(MaxStripCandidates).ToList(); Debug.WriteLine($"[PairFiller] Strip mode: {top.Count} candidates (shortSide <= {workShortSide:F1})"); + return top; } - SortByEstimatedCount(top, workArea); + var result = kept.Take(MaxTopCandidates).ToList(); + SortByEstimatedCount(result, workArea); - return top; + return result; } private void SortByEstimatedCount(List candidates, Box workArea)