From 079a44052cc0d7edc0a2587fb5ed4b10ebe82586 Mon Sep 17 00:00:00 2001 From: AJ Isaacs Date: Mon, 9 Mar 2026 23:13:22 -0400 Subject: [PATCH] perf: pre-allocate tile list capacity and remove redundant bbox walks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- OpenNest.Engine/FillLinear.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/OpenNest.Engine/FillLinear.cs b/OpenNest.Engine/FillLinear.cs index 2778732..f619434 100644 --- a/OpenNest.Engine/FillLinear.cs +++ b/OpenNest.Engine/FillLinear.cs @@ -244,16 +244,18 @@ namespace OpenNest /// private List TilePattern(Pattern basePattern, NestDirection direction, PartBoundary[] boundaries) { - var result = new List(); var copyDistance = FindPatternCopyDistance(basePattern, direction, boundaries); if (copyDistance <= 0) - return result; + return new List(); var dim = GetDimension(basePattern.BoundingBox, direction); var start = GetStart(basePattern.BoundingBox, direction); var limit = GetLimit(direction); + var estimatedCopies = (int)((limit - start - dim) / copyDistance); + var result = new List(estimatedCopies * basePattern.Parts.Count); + var count = 1; while (true) @@ -309,9 +311,7 @@ namespace OpenNest if (!rotationAngle.IsEqualTo(0)) template.Rotate(rotationAngle); - var bbox = template.Program.BoundingBox(); - template.Offset(WorkArea.Location - bbox.Location); - template.UpdateBounds(); + template.Offset(WorkArea.Location - template.BoundingBox.Location); if (template.BoundingBox.Width > WorkArea.Width + Tolerance.Epsilon || template.BoundingBox.Height > WorkArea.Height + Tolerance.Epsilon)