feat: add Pattern class for grouping parts with relative positions

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-07 00:52:11 -05:00
parent 949a9ffc7d
commit f4779b878c
2 changed files with 58 additions and 0 deletions

View File

@@ -45,6 +45,7 @@
<Compile Include="NestDirection.cs" />
<Compile Include="NestEngine.cs" />
<Compile Include="NestItem.cs" />
<Compile Include="Pattern.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RectanglePacking\Bin.cs" />
<Compile Include="RectanglePacking\FillBestFit.cs" />

View File

@@ -0,0 +1,57 @@
using System.Collections.Generic;
using OpenNest.Geometry;
namespace OpenNest
{
public class Pattern
{
public Pattern()
{
Parts = new List<Part>();
}
public List<Part> Parts { get; }
public Box BoundingBox { get; private set; }
public void UpdateBounds()
{
BoundingBox = Parts.GetBoundingBox();
}
public List<Line> GetLines(PushDirection facingDirection)
{
var lines = new List<Line>();
foreach (var part in Parts)
lines.AddRange(Helper.GetPartLines(part, facingDirection));
return lines;
}
public List<Line> GetOffsetLines(double spacing, PushDirection facingDirection)
{
var lines = new List<Line>();
foreach (var part in Parts)
lines.AddRange(Helper.GetOffsetPartLines(part, spacing, facingDirection));
return lines;
}
public Pattern Clone(Vector offset)
{
var pattern = new Pattern();
foreach (var part in Parts)
{
var clone = (Part)part.Clone();
clone.Offset(offset);
pattern.Parts.Add(clone);
}
pattern.UpdateBounds();
return pattern;
}
}
}