From de70999975ed485bdad9171d8ce43e1938387ffb Mon Sep 17 00:00:00 2001 From: AJ Isaacs Date: Fri, 13 Mar 2026 21:14:25 -0400 Subject: [PATCH] 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 --- OpenNest.Engine/BestFit/BestFitResult.cs | 1 + OpenNest.Engine/BestFit/PairEvaluator.cs | 4 ++++ OpenNest.Engine/RotationAnalysis.cs | 5 +++++ 3 files changed, 10 insertions(+) diff --git a/OpenNest.Engine/BestFit/BestFitResult.cs b/OpenNest.Engine/BestFit/BestFitResult.cs index 169f478..97ce07c 100644 --- a/OpenNest.Engine/BestFit/BestFitResult.cs +++ b/OpenNest.Engine/BestFit/BestFitResult.cs @@ -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 HullAngles { get; set; } public double Utilization { diff --git a/OpenNest.Engine/BestFit/PairEvaluator.cs b/OpenNest.Engine/BestFit/PairEvaluator.cs index 5224820..bffc7c6 100644 --- a/OpenNest.Engine/BestFit/PairEvaluator.cs +++ b/OpenNest.Engine/BestFit/PairEvaluator.cs @@ -42,6 +42,7 @@ namespace OpenNest.Engine.BestFit // Find optimal bounding rectangle via rotating calipers double bestArea, bestWidth, bestHeight, bestRotation; + List 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 { 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" }; diff --git a/OpenNest.Engine/RotationAnalysis.cs b/OpenNest.Engine/RotationAnalysis.cs index 65dac9d..8aa7aa5 100644 --- a/OpenNest.Engine/RotationAnalysis.cs +++ b/OpenNest.Engine/RotationAnalysis.cs @@ -80,6 +80,11 @@ namespace OpenNest return new List { 0 }; var hull = ConvexHull.Compute(points); + return GetHullEdgeAngles(hull); + } + + public static List GetHullEdgeAngles(Polygon hull) + { var vertices = hull.Vertices; var n = hull.IsClosed() ? vertices.Count - 1 : vertices.Count;