refactor(engine): precompute hull angles during pair evaluation

Store hull edge angles in BestFitResult at evaluation time so they
don't need to be recomputed during the fill phase. Extract
GetHullEdgeAngles(Polygon) overload from FindHullEdgeAngles.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-13 21:14:25 -04:00
parent 1a9bd795a8
commit de70999975
3 changed files with 10 additions and 0 deletions

View File

@@ -14,6 +14,7 @@ namespace OpenNest.Engine.BestFit
public bool Keep { get; set; }
public string Reason { get; set; }
public double TrueArea { get; set; }
public List<double> HullAngles { get; set; }
public double Utilization
{

View File

@@ -42,6 +42,7 @@ namespace OpenNest.Engine.BestFit
// Find optimal bounding rectangle via rotating calipers
double bestArea, bestWidth, bestHeight, bestRotation;
List<double> hullAngles = null;
if (allPoints.Count >= 3)
{
@@ -51,6 +52,7 @@ namespace OpenNest.Engine.BestFit
bestWidth = result.Width;
bestHeight = result.Height;
bestRotation = result.Angle;
hullAngles = RotationAnalysis.GetHullEdgeAngles(hull);
}
else
{
@@ -59,6 +61,7 @@ namespace OpenNest.Engine.BestFit
bestWidth = combinedBox.Width;
bestHeight = combinedBox.Length;
bestRotation = 0;
hullAngles = new List<double> { 0 };
}
var trueArea = drawing.Area * 2;
@@ -71,6 +74,7 @@ namespace OpenNest.Engine.BestFit
BoundingHeight = bestHeight,
OptimalRotation = bestRotation,
TrueArea = trueArea,
HullAngles = hullAngles,
Keep = !overlaps,
Reason = overlaps ? "Overlap detected" : "Valid"
};

View File

@@ -80,6 +80,11 @@ namespace OpenNest
return new List<double> { 0 };
var hull = ConvexHull.Compute(points);
return GetHullEdgeAngles(hull);
}
public static List<double> GetHullEdgeAngles(Polygon hull)
{
var vertices = hull.Vertices;
var n = hull.IsClosed() ? vertices.Count - 1 : vertices.Count;