fix(engine): compute remainder from just-placed parts within current work area

ComputeRemainderStrip used the bounding box of ALL plate parts against
the full plate, missing large interior gaps between drawing groups.
Now computes remainder within the current work area based on only the
parts that were just placed. This lets subsequent drawings fill the
gap between previous drawing groups instead of being forced into a
tiny strip at the plate edge.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-15 13:43:33 -04:00
parent 2042c7d3f2
commit 4525be302c
3 changed files with 26 additions and 40 deletions

View File

@@ -354,10 +354,11 @@ static class NestConsole
if (parts.Count > 0)
{
plate.Parts.AddRange(parts);
Compactor.Compact(parts, plate);
// TODO: Compactor.Compact(parts, plate);
item.Quantity = System.Math.Max(0, item.Quantity - parts.Count);
success = true;
workArea = ComputeRemainderStrip(plate);
var placedBox = parts.Cast<IBoundable>().GetBoundingBox();
workArea = ComputeRemainderWithin(workArea, placedBox, plate.PartSpacing);
}
}
@@ -385,22 +386,16 @@ static class NestConsole
return (success, sw.ElapsedMilliseconds);
}
static Box ComputeRemainderStrip(Plate plate)
static Box ComputeRemainderWithin(Box workArea, Box usedBox, double spacing)
{
if (plate.Parts.Count == 0)
return plate.WorkArea();
var usedBox = plate.Parts.Cast<IBoundable>().GetBoundingBox();
var fullArea = plate.WorkArea();
var hWidth = fullArea.Right - usedBox.Right - plate.PartSpacing;
var hWidth = workArea.Right - usedBox.Right - spacing;
var hStrip = hWidth > 0
? new Box(usedBox.Right + plate.PartSpacing, fullArea.Y, hWidth, fullArea.Length)
? new Box(usedBox.Right + spacing, workArea.Y, hWidth, workArea.Length)
: Box.Empty;
var vHeight = fullArea.Top - usedBox.Top - plate.PartSpacing;
var vHeight = workArea.Top - usedBox.Top - spacing;
var vStrip = vHeight > 0
? new Box(fullArea.X, usedBox.Top + plate.PartSpacing, fullArea.Width, vHeight)
? new Box(workArea.X, usedBox.Top + spacing, workArea.Width, vHeight)
: Box.Empty;
return hStrip.Area() >= vStrip.Area() ? hStrip : vStrip;

View File

@@ -258,10 +258,11 @@ namespace OpenNest.Mcp.Tools
if (parts.Count > 0)
{
plate.Parts.AddRange(parts);
Compactor.Compact(parts, plate);
// TODO: Compactor.Compact(parts, plate);
item.Quantity = System.Math.Max(0, item.Quantity - parts.Count);
totalPlaced += parts.Count;
workArea = ComputeRemainderStrip(plate);
var placedBox = parts.Cast<IBoundable>().GetBoundingBox();
workArea = ComputeRemainderWithin(workArea, placedBox, plate.PartSpacing);
}
}
@@ -289,22 +290,16 @@ namespace OpenNest.Mcp.Tools
return sb.ToString();
}
private static Box ComputeRemainderStrip(Plate plate)
private static Box ComputeRemainderWithin(Box workArea, Box usedBox, double spacing)
{
if (plate.Parts.Count == 0)
return plate.WorkArea();
var usedBox = plate.Parts.Cast<IBoundable>().GetBoundingBox();
var fullArea = plate.WorkArea();
var hWidth = fullArea.Right - usedBox.Right - plate.PartSpacing;
var hWidth = workArea.Right - usedBox.Right - spacing;
var hStrip = hWidth > 0
? new Box(usedBox.Right + plate.PartSpacing, fullArea.Y, hWidth, fullArea.Length)
? new Box(usedBox.Right + spacing, workArea.Y, hWidth, workArea.Length)
: Box.Empty;
var vHeight = fullArea.Top - usedBox.Top - plate.PartSpacing;
var vHeight = workArea.Top - usedBox.Top - spacing;
var vStrip = vHeight > 0
? new Box(fullArea.X, usedBox.Top + plate.PartSpacing, fullArea.Width, vHeight)
? new Box(workArea.X, usedBox.Top + spacing, workArea.Width, vHeight)
: Box.Empty;
return hStrip.Area() >= vStrip.Area() ? hStrip : vStrip;

View File

@@ -807,14 +807,16 @@ namespace OpenNest.Forms
if (parts.Count > 0)
{
plate.Parts.AddRange(parts);
Compactor.Compact(parts, plate);
// TODO: Compactor.Compact(parts, plate);
activeForm.PlateView.Invalidate();
anyPlaced = true;
item.Quantity = System.Math.Max(0, item.Quantity - parts.Count);
// Compute remainder strip for the next drawing.
workArea = ComputeRemainderStrip(plate);
// Compute remainder within the current work area based on
// what was just placed — not the full plate bounding box.
var placedBox = parts.Cast<IBoundable>().GetBoundingBox();
workArea = ComputeRemainderWithin(workArea, placedBox, plate.PartSpacing);
}
}
@@ -867,22 +869,16 @@ namespace OpenNest.Forms
}
}
private static Box ComputeRemainderStrip(Plate plate)
private static Box ComputeRemainderWithin(Box workArea, Box usedBox, double spacing)
{
if (plate.Parts.Count == 0)
return plate.WorkArea();
var usedBox = plate.Parts.Cast<IBoundable>().GetBoundingBox();
var fullArea = plate.WorkArea();
var hWidth = fullArea.Right - usedBox.Right - plate.PartSpacing;
var hWidth = workArea.Right - usedBox.Right - spacing;
var hStrip = hWidth > 0
? new Box(usedBox.Right + plate.PartSpacing, fullArea.Y, hWidth, fullArea.Length)
? new Box(usedBox.Right + spacing, workArea.Y, hWidth, workArea.Length)
: Box.Empty;
var vHeight = fullArea.Top - usedBox.Top - plate.PartSpacing;
var vHeight = workArea.Top - usedBox.Top - spacing;
var vStrip = vHeight > 0
? new Box(fullArea.X, usedBox.Top + plate.PartSpacing, fullArea.Width, vHeight)
? new Box(workArea.X, usedBox.Top + spacing, workArea.Width, vHeight)
: Box.Empty;
return hStrip.Area() >= vStrip.Area() ? hStrip : vStrip;