fix(engine): don't drop the topmost part when no other drawing is waiting

RemnantFiller removes the topmost placed part to keep a clean rectangular
obstacle for the next drawing, but the envelope then walls that slot off,
so the part was lost for nothing (4 squares on a 9x9 plate became 3).
Only remove it while another drawing still has demand.

Fixes the mixed-stock NestRunner tests.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
aj
2026-09-21 11:07:45 -04:00
co-authored by Claude Sonnet 5
parent a764a70e52
commit 630d514b0e
2 changed files with 47 additions and 1 deletions
@@ -103,4 +103,30 @@ public class RemnantFillerTests2
// Should not throw, returns whatever was placed
Assert.NotNull(result);
}
[Fact]
public void FillItems_SingleDrawing_KeepsEveryPlacedPart()
{
// With no other drawing waiting for space there is nothing to keep clear, so a full
// grid fill must not lose its topmost part.
var workArea = new Box(0, 0, 100, 100);
var filler = new RemnantFiller(workArea, 0);
var items = new List<NestItem>
{
new NestItem { Drawing = MakeSquareDrawing(10), Quantity = 4 },
};
Func<NestItem, Box, List<Part>> fillFunc = (ni, b) =>
new List<Part>
{
TestHelpers.MakePartAt(0, 0, 10),
TestHelpers.MakePartAt(10, 0, 10),
TestHelpers.MakePartAt(0, 10, 10),
TestHelpers.MakePartAt(10, 10, 10),
};
var placed = filler.FillItems(items, fillFunc);
Assert.Equal(4, placed.Count);
}
}