diff --git a/OpenNest.Engine.Tests/Jobs/ClampZoneInteractiveFillTests.cs b/OpenNest.Engine.Tests/Jobs/ClampZoneInteractiveFillTests.cs index 89dcaac8..54d82994 100644 --- a/OpenNest.Engine.Tests/Jobs/ClampZoneInteractiveFillTests.cs +++ b/OpenNest.Engine.Tests/Jobs/ClampZoneInteractiveFillTests.cs @@ -247,6 +247,28 @@ public class ClampZoneInteractiveFillTests AssertClearOfClamps(parts, new Box(5, 0, 1, 0.5)); } + [Fact] + public void FillAreaKeepsToleranceOverhangAtAnInnerEdgeHeldOffByPartSpacing() + { + // A fill's interlocked partner can end a few millionths past the selected box (the + // fillers' geometry tolerance); with clamps on the sheet both partners were dropped. + var plate = MakePlate(new ClampZone("front-1", ZoneA)); + var area = new Box(30, 5, 4, 10); + var overhang = OpenNest.Math.Tolerance.Epsilon * 0.5; + var drawing = RectDrawing(2, 2); + var item = new NestItem { Drawing = drawing }; + var proposed = new List + { + new(drawing, new Vector(area.Left, area.Bottom)), + new(drawing, new Vector(area.Right - 2 + overhang, area.Bottom + 3)), + }; + + var parts = PlateFillService.FillDroppingClampHits((_, _, _) => proposed.ToList(), + plate, item, new List { item }, area, null, CancellationToken.None); + + Assert.Equal(2, parts.Count); + } + [Fact] public void PackAreaNeverPacksInsideClampKeepOut() { diff --git a/OpenNest.Engine/Jobs/Placement/PlateFillService.cs b/OpenNest.Engine/Jobs/Placement/PlateFillService.cs index d0adf63e..ec88c16e 100644 --- a/OpenNest.Engine/Jobs/Placement/PlateFillService.cs +++ b/OpenNest.Engine/Jobs/Placement/PlateFillService.cs @@ -541,10 +541,15 @@ public static partial class PlateFillService { var bounds = part.BoundingBox; var full = plate.WorkArea(); - // The packer permits a tiny overhang only at a real sheet edge, - // never across a remnant boundary cut by a clamp or another part. - double Slack(double edge, double sheet) => System.Math.Abs(edge - sheet) < 1e-9 + // The fillers permit the geometry tolerance's overhang at every edge of their area. A + // sheet edge always allows it. An inner edge is an occupant (or cut-off) held off by the + // part spacing, or a clamp keep-out inflated by at least the spacing slack, so the + // overhang stays inside that margin when the spacing is at least the slack; the material + // checks below still confirm occupants and clamps. Without that margin, hold the edge. + var innerSlack = plate.PartSpacing >= NestTolerances.SpacingSlack ? NestTolerances.WorkAreaSlack : 1e-6; + double Slack(double edge, double sheet) => System.Math.Abs(edge - sheet) < 1e-9 + ? NestTolerances.WorkAreaSlack : innerSlack; if (bounds.Left < area.Left - Slack(area.Left, full.Left) || bounds.Right > area.Right + Slack(area.Right, full.Right) || bounds.Bottom < area.Bottom - Slack(area.Bottom, full.Bottom)