diff --git a/OpenNest.Engine/RectanglePacking/FillNoRotation.cs b/OpenNest.Engine/RectanglePacking/FillNoRotation.cs deleted file mode 100644 index 8410e70..0000000 --- a/OpenNest.Engine/RectanglePacking/FillNoRotation.cs +++ /dev/null @@ -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) - ); - } - } -} diff --git a/OpenNest.Engine/RectanglePacking/FillSameRotation.cs b/OpenNest.Engine/RectanglePacking/FillSameRotation.cs deleted file mode 100644 index f58ab25..0000000 --- a/OpenNest.Engine/RectanglePacking/FillSameRotation.cs +++ /dev/null @@ -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); - } - } -} diff --git a/OpenNest.Engine/RectanglePacking/PackFirstFitDecreasing.cs b/OpenNest.Engine/RectanglePacking/PackFirstFitDecreasing.cs deleted file mode 100644 index 94f9f71..0000000 --- a/OpenNest.Engine/RectanglePacking/PackFirstFitDecreasing.cs +++ /dev/null @@ -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 levels; - - public FirstFitDecreasing(Bin bin) - : base(bin) - { - levels = new List(); - } - - public override void Pack(List 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); - } - } - } -}