perf: halve rotating calipers edge iterations

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 <noreply@anthropic.com>
This commit is contained in:
2026-03-09 22:17:24 -04:00
parent 91908c1732
commit 5fc16e9dae

View File

@@ -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;