mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-12-05 05:59:25 -05:00
fix(fill): refill clamp gaps in multi-part group fills
A group fill dropped every copy that hit a clamp and left the room it freed empty. The gaps are now filled with whole copies, through the gap search the single-part fill already used. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
5bc39be8ca
commit
096cf9d663
2 files changed
+56
-9
No files matched your search
@@ -228,9 +228,23 @@ public static partial class PlateFillService
|
||||
private static void FillGapsBesideClamps(
|
||||
Func<NestItem, Box, IProgress<NestProgress>, List<Part>> fill, Plate plate,
|
||||
NestItem item, List<NestItem> demand, Box area, List<Part> result,
|
||||
CancellationToken token)
|
||||
CancellationToken token) =>
|
||||
FillGaps(plate, area, item.Drawing.Program.BoundingBox(), result, 1, demand,
|
||||
() => item.Quantity > 0 && result.Count >= item.Quantity,
|
||||
gap => fill(item.WithQuantity(
|
||||
item.Quantity > 0 ? item.Quantity - result.Count : item.Quantity), gap, null),
|
||||
token);
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="FillGapsBesideClamps"/> for any unit: <paramref name="fillGap"/> proposes
|
||||
/// copies of a unit of <paramref name="groupSize"/> parts whose footprint is
|
||||
/// <paramref name="size"/> in each free rectangle that can hold one, and each copy is
|
||||
/// certified whole. Stops once <paramref name="satisfied"/> holds.
|
||||
/// </summary>
|
||||
private static void FillGaps(Plate plate, Box area, Box size, List<Part> result,
|
||||
int groupSize, List<NestItem> demand, Func<bool> satisfied,
|
||||
Func<Box, List<Part>> fillGap, CancellationToken token)
|
||||
{
|
||||
var size = item.Drawing.Program.BoundingBox();
|
||||
var keepOuts = InteractiveClamps.ClearanceRectangles(plate);
|
||||
for (var round = 0; round < MaxGapFillRounds; round++)
|
||||
{
|
||||
@@ -241,13 +255,11 @@ public static partial class PlateFillService
|
||||
.Select(part => part.BoundingBox.Offset(plate.PartSpacing)));
|
||||
foreach (var gap in new RemnantFinder(area, obstacles).FindRemnants())
|
||||
{
|
||||
if (token.IsCancellationRequested
|
||||
|| (item.Quantity > 0 && result.Count >= item.Quantity))
|
||||
if (token.IsCancellationRequested || satisfied())
|
||||
return;
|
||||
if (!Fits(gap, size))
|
||||
continue;
|
||||
var remaining = item.Quantity > 0 ? item.Quantity - result.Count : item.Quantity;
|
||||
AddClear(result, fill(item.WithQuantity(remaining), gap, null), plate, gap, demand);
|
||||
AddClear(result, fillGap(gap), plate, gap, demand, groupSize: groupSize);
|
||||
}
|
||||
if (result.Count == before)
|
||||
return;
|
||||
@@ -342,13 +354,18 @@ public static partial class PlateFillService
|
||||
return FillItem(strategy, plate, new NestItem { Drawing = groupParts[0].BaseDrawing },
|
||||
workArea, progress, token);
|
||||
|
||||
// As FillItem; a copy is dropped whole when any member hits a clamp.
|
||||
// As FillItem; a copy is dropped whole when any member hits a clamp, and the gaps
|
||||
// the dropped copies leave are filled with whole copies.
|
||||
var groupSize = groupParts.Count;
|
||||
var size = groupParts.Select(part => part.BoundingBox).ToList().GetBoundingBox();
|
||||
return FillBesideClamps(filler, plate, workArea, progress, token, (area, sink) =>
|
||||
{
|
||||
var proposed = filler.Fill(groupParts, area, sink, token);
|
||||
var result = new List<Part>();
|
||||
AddClear(result, filler.Fill(groupParts, area, sink, token), plate, area,
|
||||
groupSize: groupSize);
|
||||
AddClear(result, proposed, plate, area, groupSize: groupSize);
|
||||
if (result.Count < proposed.Count - proposed.Count % groupSize)
|
||||
FillGaps(plate, area, size, result, groupSize, null, () => false,
|
||||
gap => filler.Fill(groupParts, gap, null, token), token);
|
||||
return result;
|
||||
}, null, groupSize);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user