refactor: replace ComputeRemainderWithin with RemnantFinder in Nest()

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-16 12:51:25 -04:00
parent 2b578fa006
commit 4d30178752
+6 -17
View File
@@ -88,8 +88,12 @@ namespace OpenNest
{ {
allParts.AddRange(parts); allParts.AddRange(parts);
item.Quantity = System.Math.Max(0, item.Quantity - parts.Count); item.Quantity = System.Math.Max(0, item.Quantity - parts.Count);
var placedBox = parts.Cast<IBoundable>().GetBoundingBox(); var placedObstacles = parts.Select(p => p.BoundingBox.Offset(Plate.PartSpacing)).ToList();
workArea = ComputeRemainderWithin(workArea, placedBox, Plate.PartSpacing); var finder = new RemnantFinder(workArea, placedObstacles);
var remnants = finder.FindRemnants();
if (remnants.Count == 0)
break;
workArea = remnants[0]; // Largest remnant
} }
} }
@@ -117,21 +121,6 @@ namespace OpenNest
return allParts; return allParts;
} }
protected static Box ComputeRemainderWithin(Box workArea, Box usedBox, double spacing)
{
var hWidth = workArea.Right - usedBox.Right - spacing;
var hStrip = hWidth > 0
? new Box(usedBox.Right + spacing, workArea.Y, hWidth, workArea.Length)
: Box.Empty;
var vHeight = workArea.Top - usedBox.Top - spacing;
var vStrip = vHeight > 0
? new Box(workArea.X, usedBox.Top + spacing, workArea.Width, vHeight)
: Box.Empty;
return hStrip.Area() >= vStrip.Area() ? hStrip : vStrip;
}
// --- FillExact (non-virtual, delegates to virtual Fill) --- // --- FillExact (non-virtual, delegates to virtual Fill) ---
public List<Part> FillExact(NestItem item, Box workArea, public List<Part> FillExact(NestItem item, Box workArea,