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>
55 lines
1.3 KiB
C#
55 lines
1.3 KiB
C#
using OpenNest.Geometry;
|
|
using OpenNest.Math;
|
|
using System.Collections.Generic;
|
|
|
|
namespace OpenNest.RectanglePacking
|
|
{
|
|
internal class Item : Box
|
|
{
|
|
public int Id { get; set; }
|
|
|
|
public bool IsRotated { get; private set; }
|
|
|
|
public void Rotate()
|
|
{
|
|
Generic.Swap(ref Size.Width, ref Size.Length);
|
|
IsRotated = !IsRotated;
|
|
}
|
|
|
|
public object Clone()
|
|
{
|
|
return new Item
|
|
{
|
|
IsRotated = this.IsRotated,
|
|
Location = this.Location,
|
|
Size = this.Size,
|
|
Id = this.Id
|
|
};
|
|
}
|
|
}
|
|
|
|
internal static class ItemListExtensions
|
|
{
|
|
public static Box GetBoundingBox(this IList<Item> items)
|
|
{
|
|
if (items.Count == 0)
|
|
return Box.Empty;
|
|
|
|
double minX = items[0].X;
|
|
double minY = items[0].Y;
|
|
double maxX = items[0].Right;
|
|
double maxY = items[0].Top;
|
|
|
|
foreach (var box in items)
|
|
{
|
|
if (box.Left < minX) minX = box.Left;
|
|
if (box.Right > maxX) maxX = box.Right;
|
|
if (box.Bottom < minY) minY = box.Bottom;
|
|
if (box.Top > maxY) maxY = box.Top;
|
|
}
|
|
|
|
return new Box(minX, minY, maxX - minX, maxY - minY);
|
|
}
|
|
}
|
|
}
|