mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-12-04 07:19:24 -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
@@ -449,6 +449,36 @@ public class ClampZoneInteractiveFillTests
|
||||
Assert.Equal(58, parts.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GroupFillTakesTheGapsItsDroppedCopiesLeave()
|
||||
{
|
||||
// A copy of the two-part group that straddles a clamp is dropped whole; the room that
|
||||
// leaves beside the clamps must take whole copies again.
|
||||
var plate = RailPlate(out var zones);
|
||||
var group = new List<Part>
|
||||
{
|
||||
new(RectDrawing(7, 7)),
|
||||
new(RectDrawing(7, 7), new Vector(7 + PartSpacing, 0)),
|
||||
};
|
||||
var footprint = group.Select(part => part.BoundingBox).ToList().GetBoundingBox();
|
||||
|
||||
var parts = PlateFillService.FillGroup("Fill", plate, group, plate.WorkArea(),
|
||||
null, CancellationToken.None);
|
||||
|
||||
// The service holds parts off a clamp by the validator's keep-out, which the fillers'
|
||||
// edge tolerance may reach into by less than the spacing slack.
|
||||
var keepOuts = zones.Select(zone => Inflated(zone, Edge - NestTolerances.SpacingSlack));
|
||||
Assert.DoesNotContain(parts, part =>
|
||||
keepOuts.Any(keepOut => Overlaps(part.BoundingBox, keepOut)));
|
||||
Assert.Equal(0, parts.Count % group.Count);
|
||||
var obstacles = zones.Select(zone => Inflated(zone, Edge))
|
||||
.Concat(parts.Select(part => part.BoundingBox.Offset(PartSpacing))).ToList();
|
||||
var gaps = new RemnantFinder(plate.WorkArea(), obstacles).FindRemnants();
|
||||
Assert.DoesNotContain(gaps, gap =>
|
||||
(gap.Length >= footprint.Length - 1e-6 && gap.Width >= footprint.Width - 1e-6)
|
||||
|| (gap.Length >= footprint.Width - 1e-6 && gap.Width >= footprint.Length - 1e-6));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TheClampedRowLinesUpBetweenTheClamps()
|
||||
{
|
||||
|
||||
@@ -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