Files
OpenNest/OpenNest.Engine/Fill/PatternTiler.cs
AJ Isaacs 0e1e619f0a refactor(engine): move fill and strategy code to dedicated namespaces
Move fill algorithms to OpenNest.Engine.Fill namespace:
FillLinear, FillExtents, PairFiller, ShrinkFiller, Compactor,
RemnantFiller, RemnantFinder, FillScore, Pattern, PatternTiler,
PartBoundary, RotationAnalysis, AngleCandidateBuilder, and
AccumulatingProgress.

Move strategy layer to OpenNest.Engine.Strategies namespace:
IFillStrategy, FillContext, FillStrategyRegistry, FillHelpers,
and all built-in strategy implementations.

Add using directives to all consuming files across Engine, UI,
MCP, and Tests projects.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-18 16:46:11 -04:00

53 lines
1.7 KiB
C#

using OpenNest.Geometry;
using System.Collections.Generic;
namespace OpenNest.Engine.Fill
{
public static class PatternTiler
{
public static List<Part> Tile(List<Part> cell, Size plateSize, double partSpacing)
{
if (cell == null || cell.Count == 0)
return new List<Part>();
var cellBox = cell.GetBoundingBox();
var halfSpacing = partSpacing / 2;
var cellWidth = cellBox.Width + partSpacing;
var cellHeight = cellBox.Length + partSpacing;
if (cellWidth <= 0 || cellHeight <= 0)
return new List<Part>();
// Size.Width = X-axis, Size.Length = Y-axis
var cols = (int)System.Math.Floor(plateSize.Width / cellWidth);
var rows = (int)System.Math.Floor(plateSize.Length / cellHeight);
if (cols <= 0 || rows <= 0)
return new List<Part>();
// Shift cell so parts start at halfSpacing inset, ensuring symmetric
// spacing between adjacent tiled cells on all sides.
var cellOrigin = cellBox.Location;
var baseOffset = new Vector(halfSpacing - cellOrigin.X, halfSpacing - cellOrigin.Y);
var result = new List<Part>(cols * rows * cell.Count);
for (var row = 0; row < rows; row++)
{
for (var col = 0; col < cols; col++)
{
var tileOffset = baseOffset + new Vector(col * cellWidth, row * cellHeight);
foreach (var part in cell)
{
result.Add(part.CloneAtOffset(tileOffset));
}
}
}
return result;
}
}
}