From 5fc16e9dae25e3696b5eef0d49c2654d1955dacd Mon Sep 17 00:00:00 2001 From: AJ Isaacs Date: Mon, 9 Mar 2026 22:17:24 -0400 Subject: [PATCH] perf: halve rotating calipers edge iterations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Opposite hull edges (180° apart) produce identical bounding rectangles (width/height swapped), so only half the edges need to be checked to find the minimum area. Applied to the unconstrained overload only. Co-Authored-By: Claude Opus 4.6 --- OpenNest.Core/Geometry/RotatingCalipers.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/OpenNest.Core/Geometry/RotatingCalipers.cs b/OpenNest.Core/Geometry/RotatingCalipers.cs index 4ae29c6..15742fd 100644 --- a/OpenNest.Core/Geometry/RotatingCalipers.cs +++ b/OpenNest.Core/Geometry/RotatingCalipers.cs @@ -48,9 +48,14 @@ namespace OpenNest.Geometry return new BoundingRectangleResult(angle, length, 0); } + // Only need half the edges — opposite edges produce the same + // bounding rectangle (width/height swapped), so the minimum + // area repeats every 180°. + var edgeCount = (n + 1) / 2; + BoundingRectangleResult best = null; - for (int i = 0; i < n; i++) + for (int i = 0; i < edgeCount; i++) { int next = (i + 1) % n; var edgeX = vertices[next].X - vertices[i].X;