perf: pre-allocate tile list capacity and remove redundant bbox walks
Pre-size TilePattern result list from estimated copy count to avoid resizing. Remove redundant Program.BoundingBox() call and UpdateBounds() in MakeSeedPattern — the Part's BoundingBox is already correct. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -244,16 +244,18 @@ namespace OpenNest
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private List<Part> TilePattern(Pattern basePattern, NestDirection direction, PartBoundary[] boundaries)
|
private List<Part> TilePattern(Pattern basePattern, NestDirection direction, PartBoundary[] boundaries)
|
||||||
{
|
{
|
||||||
var result = new List<Part>();
|
|
||||||
var copyDistance = FindPatternCopyDistance(basePattern, direction, boundaries);
|
var copyDistance = FindPatternCopyDistance(basePattern, direction, boundaries);
|
||||||
|
|
||||||
if (copyDistance <= 0)
|
if (copyDistance <= 0)
|
||||||
return result;
|
return new List<Part>();
|
||||||
|
|
||||||
var dim = GetDimension(basePattern.BoundingBox, direction);
|
var dim = GetDimension(basePattern.BoundingBox, direction);
|
||||||
var start = GetStart(basePattern.BoundingBox, direction);
|
var start = GetStart(basePattern.BoundingBox, direction);
|
||||||
var limit = GetLimit(direction);
|
var limit = GetLimit(direction);
|
||||||
|
|
||||||
|
var estimatedCopies = (int)((limit - start - dim) / copyDistance);
|
||||||
|
var result = new List<Part>(estimatedCopies * basePattern.Parts.Count);
|
||||||
|
|
||||||
var count = 1;
|
var count = 1;
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
@@ -309,9 +311,7 @@ namespace OpenNest
|
|||||||
if (!rotationAngle.IsEqualTo(0))
|
if (!rotationAngle.IsEqualTo(0))
|
||||||
template.Rotate(rotationAngle);
|
template.Rotate(rotationAngle);
|
||||||
|
|
||||||
var bbox = template.Program.BoundingBox();
|
template.Offset(WorkArea.Location - template.BoundingBox.Location);
|
||||||
template.Offset(WorkArea.Location - bbox.Location);
|
|
||||||
template.UpdateBounds();
|
|
||||||
|
|
||||||
if (template.BoundingBox.Width > WorkArea.Width + Tolerance.Epsilon ||
|
if (template.BoundingBox.Width > WorkArea.Width + Tolerance.Epsilon ||
|
||||||
template.BoundingBox.Height > WorkArea.Height + Tolerance.Epsilon)
|
template.BoundingBox.Height > WorkArea.Height + Tolerance.Epsilon)
|
||||||
|
|||||||
Reference in New Issue
Block a user