fix: correct Width/Length axis mapping and add spiral center-fill

Box constructor and derived properties (Right, Top, Center, Translate, Offset)
had Width and Length swapped — Length is X axis, Width is Y axis. Corrected
across Core geometry, plate bounding box, rectangle packing, fill algorithms,
tests, and UI renderers.

Added FillSpiral with center remnant detection and recursive FillBest on
the gap between the 4 spiral quadrants. RectFill.FillBest now compares
spiral+center vs full best-fit fairly. BestCombination returns a
CombinationResult record instead of out params.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-03 21:22:55 -04:00
parent e50a7c82cf
commit c5943e22eb
55 changed files with 433 additions and 257 deletions

View File

@@ -16,11 +16,11 @@ namespace OpenNest.RectanglePacking
public override void Pack(List<Item> items)
{
items = items.OrderBy(i => -i.Length).ToList();
items = items.OrderBy(i => -i.Width).ToList();
foreach (var item in items)
{
if (item.Length > Bin.Length)
if (item.Width > Bin.Width)
continue;
var level = FindLevel(item);
@@ -36,10 +36,10 @@ namespace OpenNest.RectanglePacking
{
foreach (var level in levels)
{
if (level.Height < item.Length)
if (level.Height < item.Width)
continue;
if (level.RemainingWidth < item.Width)
if (level.RemainingLength < item.Length)
continue;
return level;
@@ -58,12 +58,12 @@ namespace OpenNest.RectanglePacking
var remaining = Bin.Top - y;
if (remaining < item.Length)
if (remaining < item.Width)
return null;
var level = new Level(Bin);
level.Y = y;
level.Height = item.Length;
level.Height = item.Width;
levels.Add(level);
@@ -93,9 +93,9 @@ namespace OpenNest.RectanglePacking
set { NextItemLocation.Y = value; }
}
public double Width
public double LevelLength
{
get { return Parent.Width; }
get { return Parent.Length; }
}
public double Height { get; set; }
@@ -105,9 +105,9 @@ namespace OpenNest.RectanglePacking
get { return Y + Height; }
}
public double RemainingWidth
public double RemainingLength
{
get { return X + Width - NextItemLocation.X; }
get { return X + LevelLength - NextItemLocation.X; }
}
public void AddItem(Item item)
@@ -115,7 +115,7 @@ namespace OpenNest.RectanglePacking
item.Location = NextItemLocation;
Parent.Items.Add(item);
NextItemLocation = new Vector(NextItemLocation.X + item.Width, NextItemLocation.Y);
NextItemLocation = new Vector(NextItemLocation.X + item.Length, NextItemLocation.Y);
}
}
}