Files
OpenNest/OpenNest.Engine/RectanglePacking/FillEngine.cs
AJ Isaacs c5943e22eb 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>
2026-04-03 21:22:55 -04:00

46 lines
1.2 KiB
C#

using OpenNest.Geometry;
using System.Collections.Generic;
namespace OpenNest.RectanglePacking
{
internal abstract class FillEngine
{
public FillEngine(Bin bin)
{
Bin = bin;
}
public Bin Bin { get; set; }
public abstract void Fill(Item item);
public abstract void Fill(Item item, int maxCount);
protected List<Item> FillGrid(Item item, int rows, int columns, int maxCount, bool columnMajor = true)
{
var items = new List<Item>();
var outerCount = columnMajor ? columns : rows;
var innerCount = columnMajor ? rows : columns;
for (var i = 0; i < outerCount; i++)
{
for (var j = 0; j < innerCount; j++)
{
var x = (columnMajor ? i : j) * item.Length + item.X;
var y = (columnMajor ? j : i) * item.Width + item.Y;
var clone = item.Clone() as Item;
clone.Location = new Vector(x, y);
items.Add(clone);
if (items.Count == maxCount)
return items;
}
}
return items;
}
}
}