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:
@@ -48,9 +48,14 @@ namespace OpenNest.Geometry
|
|||||||
return new BoundingRectangleResult(angle, length, 0);
|
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;
|
BoundingRectangleResult best = null;
|
||||||
|
|
||||||
for (int i = 0; i < n; i++)
|
for (int i = 0; i < edgeCount; i++)
|
||||||
{
|
{
|
||||||
int next = (i + 1) % n;
|
int next = (i + 1) % n;
|
||||||
var edgeX = vertices[next].X - vertices[i].X;
|
var edgeX = vertices[next].X - vertices[i].X;
|
||||||
|
|||||||
Reference in New Issue
Block a user