refactor(packing): remove unused rectangle fill and pack engines

FillNoRotation, FillSameRotation and FirstFitDecreasing had no callers
in production code or tests.
This commit is contained in:
aj committed 2026-09-30 22:11:12 -04:00
1 parent a854e34a3d
commit e9c312b9fb
3 files changed
-251

No files matched your search

@@ -1,65 +0,0 @@
using OpenNest.Geometry;
using OpenNest.Math;
namespace OpenNest.Engine.RectanglePacking
{
internal class FillNoRotation : FillEngine
{
public FillNoRotation(Bin bin)
: base(bin) { }
public NestDirection NestDirection { get; set; }
public override void Fill(Item item)
{
var ycount = (int)System.Math.Floor((Bin.Width + Tolerance.Epsilon) / item.Width);
var xcount = (int)System.Math.Floor((Bin.Length + Tolerance.Epsilon) / item.Length);
for (int i = 0; i < xcount; i++)
{
var x = item.Length * i + Bin.X;
for (int j = 0; j < ycount; j++)
{
var y = item.Width * j + Bin.Y;
var addedItem = item.Clone() as Item;
addedItem.Location = new Vector(x, y);
Bin.Items.Add(addedItem);
}
}
}
public override void Fill(Item item, int maxCount)
{
var ycount = (int)System.Math.Floor((Bin.Width + Tolerance.Epsilon) / item.Width);
var xcount = (int)System.Math.Floor((Bin.Length + Tolerance.Epsilon) / item.Length);
var count = ycount * xcount;
if (count <= maxCount)
{
Fill(item);
return;
}
var columns = 0;
var rows = 0;
if (NestDirection == NestDirection.Vertical)
{
columns = (int)System.Math.Ceiling((double)maxCount / ycount);
rows = (int)System.Math.Ceiling((double)maxCount / columns);
}
else
{
rows = (int)System.Math.Ceiling((double)maxCount / xcount);
columns = (int)System.Math.Ceiling((double)maxCount / rows);
}
Bin.Items.AddRange(
FillGrid(item, rows, columns, maxCount, columnMajor: item.Width > item.Length)
);
}
}
}
@@ -1,64 +0,0 @@
using OpenNest.Math;
namespace OpenNest.Engine.RectanglePacking
{
internal class FillSameRotation : FillEngine
{
public FillSameRotation(Bin bin)
: base(bin) { }
public override void Fill(Item item)
{
var bin1 = Bin.Clone() as Bin;
var bin2 = Bin.Clone() as Bin;
var engine = new FillNoRotation(bin1);
engine.Fill(item);
item.Rotate();
engine.Bin = bin2;
engine.Fill(item);
var density1 = bin1.Density();
var density2 = bin2.Density();
if (density1.IsEqualTo(density2))
{
var bounds1 = bin1.Items.GetBoundingBox();
var bounds2 = bin2.Items.GetBoundingBox();
if (bounds2.Right < bounds1.Right)
Bin.Items.AddRange(bin2.Items);
else
Bin.Items.AddRange(bin1.Items);
}
else if (density1 > density2)
Bin.Items.AddRange(bin1.Items);
else
Bin.Items.AddRange(bin2.Items);
}
public override void Fill(Item item, int maxCount)
{
var bin1 = Bin.Clone() as Bin;
var bin2 = Bin.Clone() as Bin;
var engine = new FillNoRotation(bin1);
engine.Fill(item, maxCount);
item.Rotate();
engine.Bin = bin2;
engine.Fill(item, maxCount);
var bounds1 = bin1.Items.GetBoundingBox();
var bounds2 = bin2.Items.GetBoundingBox();
if (bounds2.Right < bounds1.Right)
Bin.Items.AddRange(bin2.Items);
else
Bin.Items.AddRange(bin1.Items);
}
}
}
@@ -1,122 +0,0 @@
using System.Collections.Generic;
using System.Linq;
using OpenNest.Geometry;
namespace OpenNest.Engine.RectanglePacking
{
internal class FirstFitDecreasing : PackEngine
{
private readonly List<Level> levels;
public FirstFitDecreasing(Bin bin)
: base(bin)
{
levels = new List<Level>();
}
public override void Pack(List<Item> items)
{
items = items.OrderBy(i => -i.Width).ToList();
foreach (var item in items)
{
if (item.Width > Bin.Width)
continue;
var level = FindLevel(item);
if (level == null)
continue;
level.AddItem(item);
}
}
private Level FindLevel(Item item)
{
foreach (var level in levels)
{
if (level.Height < item.Width)
continue;
if (level.RemainingLength < item.Length)
continue;
return level;
}
return CreateNewLevel(item);
}
private Level CreateNewLevel(Item item)
{
var y = Bin.Y;
var lastLevel = levels.LastOrDefault();
if (lastLevel != null)
y = lastLevel.Y + lastLevel.Height;
var remaining = Bin.Top - y;
if (remaining < item.Width)
return null;
var level = new Level(Bin);
level.Y = y;
level.Height = item.Width;
levels.Add(level);
return level;
}
private class Level
{
public Level(Bin parent)
{
Parent = parent;
NextItemLocation = parent.Location;
}
public Bin Parent { get; set; }
private Vector NextItemLocation;
public double X
{
get { return Parent.X; }
}
public double Y
{
get { return NextItemLocation.Y; }
set { NextItemLocation.Y = value; }
}
public double LevelLength
{
get { return Parent.Length; }
}
public double Height { get; set; }
public double Top
{
get { return Y + Height; }
}
public double RemainingLength
{
get { return X + LevelLength - NextItemLocation.X; }
}
public void AddItem(Item item)
{
item.Location = NextItemLocation;
Parent.Items.Add(item);
NextItemLocation = new Vector(NextItemLocation.X + item.Length, NextItemLocation.Y);
}
}
}
}