mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-11-17 04:35:33 -05:00
The spiral packed its four blocks tight to the bin origin, so a center gap just short of a part stayed empty while slack sat at the far edges. Move the far blocks (Q3/Q4 along X, Q2/Q4 along Y) into that slack, only as far as the best center count needs; with no gain they stay put. Combination selection counts the spread center too. An 11.8 x 3.8 rectangle on a 60 x 120 sheet above the clamp rails goes from 134 to 135 parts. The 12 x 6.1 clamp case now fills the clamp-free strip with 83 parts (was 82 beside the clamps), so the dropped-clamp gap-fill test moves to 15 x 7 parts, where the gap fill still adds one (57 -> 58). The mixed-items Vertical Remnant layout keeps its 35 parts with a new digest: the full-sheet fill is trimmed to demand afterward, so its notched parts now take the spread spiral. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
47 lines
1.8 KiB
C#
47 lines
1.8 KiB
C#
using OpenNest.Engine.RectanglePacking;
|
|
using OpenNest.Geometry;
|
|
|
|
namespace OpenNest.Engine.Tests.RectanglePacking;
|
|
|
|
public class RectFillTests
|
|
{
|
|
private const double Eps = 1e-9;
|
|
|
|
// 11.8 x 3.8 rectangles at 0.25 spacing on a 60 x 120 sheet whose work area starts above
|
|
// the clamp rails (0.25 edge + 0.625 rail). Packed tight to the origin, the spiral leaves a
|
|
// 3.55 wide center gap a 4.05 part cannot use while 2.8 of slack sits at the far edge;
|
|
// moving the far blocks out by 0.5 fits one more part in the center.
|
|
[Fact]
|
|
public void FillBest_SpreadsTheSpiralWhenSlackFitsAnotherPartInTheCenter()
|
|
{
|
|
const double spacing = 0.25;
|
|
var bin = new Bin { Location = new Vector(0.25, 0.875), Size = new Size(58.875 + spacing, 119.5 + spacing) };
|
|
var item = new Item { Size = new Size(3.8 + spacing, 11.8 + spacing) };
|
|
|
|
RectFill.FillBest(bin, item);
|
|
|
|
Assert.Equal(135, bin.Items.Count);
|
|
AssertInsideAndApart(bin);
|
|
}
|
|
|
|
private static void AssertInsideAndApart(Bin bin)
|
|
{
|
|
foreach (var it in bin.Items)
|
|
Assert.True(
|
|
it.Left >= bin.Left - Eps && it.Bottom >= bin.Bottom - Eps
|
|
&& it.Right <= bin.Right + Eps && it.Top <= bin.Top + Eps,
|
|
$"item at ({it.Left},{it.Bottom})-({it.Right},{it.Top}) is outside the bin"
|
|
);
|
|
|
|
for (var i = 0; i < bin.Items.Count; i++)
|
|
for (var j = i + 1; j < bin.Items.Count; j++)
|
|
{
|
|
var a = bin.Items[i];
|
|
var b = bin.Items[j];
|
|
var gapX = System.Math.Max(b.Left - a.Right, a.Left - b.Right);
|
|
var gapY = System.Math.Max(b.Bottom - a.Top, a.Bottom - b.Top);
|
|
Assert.True(System.Math.Max(gapX, gapY) >= -Eps, $"items {i} and {j} overlap");
|
|
}
|
|
}
|
|
}
|