Part.Clone() re-clones from the drawing's unrotated program, re-rotates, and walks all CNC codes twice for bounding box — 4 O(c) passes per clone. CloneAtOffset clones from the already-rotated program and computes the bounding box arithmetically, reducing to 1 O(c) pass per clone. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
34 lines
680 B
C#
34 lines
680 B
C#
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 Pattern Clone(Vector offset)
|
|
{
|
|
var pattern = new Pattern();
|
|
|
|
foreach (var part in Parts)
|
|
pattern.Parts.Add(part.CloneAtOffset(offset));
|
|
|
|
pattern.UpdateBounds();
|
|
return pattern;
|
|
}
|
|
}
|
|
}
|