perf: add CloneAtOffset to skip re-rotation and bbox walk on part clones
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>
This commit is contained in:
@@ -208,5 +208,29 @@ namespace OpenNest
|
||||
|
||||
return part;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an offset copy of the part. Clones from the already-rotated
|
||||
/// program (skips re-rotation) and computes the bounding box arithmetically
|
||||
/// (skips Program.BoundingBox walk).
|
||||
/// </summary>
|
||||
public Part CloneAtOffset(Vector offset)
|
||||
{
|
||||
var clonedProgram = Program.Clone() as Program;
|
||||
var part = new Part(BaseDrawing, clonedProgram,
|
||||
location + offset,
|
||||
new Box(BoundingBox.X + offset.X, BoundingBox.Y + offset.Y,
|
||||
BoundingBox.Width, BoundingBox.Height));
|
||||
|
||||
return part;
|
||||
}
|
||||
|
||||
private Part(Drawing baseDrawing, Program program, Vector location, Box boundingBox)
|
||||
{
|
||||
BaseDrawing = baseDrawing;
|
||||
Program = program;
|
||||
this.location = location;
|
||||
BoundingBox = boundingBox;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user