Files
OpenNest/OpenNest.Engine/RectanglePacking/FillNoRotation.cs
AJ Isaacs 612b540d9d refactor: rename Size.Height to Size.Length across codebase
"Length" is more natural than "height" for flat plate materials.
Renames the field on OpenNest.Geometry.Size, Box.Height property,
and all references across 38 files.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-12 22:01:40 -04:00

67 lines
2.0 KiB
C#

using System;
using OpenNest.Geometry;
using OpenNest.Math;
namespace OpenNest.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.Length + Tolerance.Epsilon) / item.Length);
var xcount = (int)System.Math.Floor((Bin.Width + Tolerance.Epsilon) / item.Width);
for (int i = 0; i < xcount; i++)
{
var x = item.Width * i + Bin.X;
for (int j = 0; j < ycount; j++)
{
var y = item.Length * 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.Length + Tolerance.Epsilon) / item.Length);
var xcount = (int)System.Math.Floor((Bin.Width + Tolerance.Epsilon) / item.Width);
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));
}
}
}