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:
@@ -14,6 +14,7 @@ namespace OpenNest.Engine.BestFit
|
|||||||
public bool Keep { get; set; }
|
public bool Keep { get; set; }
|
||||||
public string Reason { get; set; }
|
public string Reason { get; set; }
|
||||||
public double TrueArea { get; set; }
|
public double TrueArea { get; set; }
|
||||||
|
public List<double> HullAngles { get; set; }
|
||||||
|
|
||||||
public double Utilization
|
public double Utilization
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ namespace OpenNest.Engine.BestFit
|
|||||||
|
|
||||||
// Find optimal bounding rectangle via rotating calipers
|
// Find optimal bounding rectangle via rotating calipers
|
||||||
double bestArea, bestWidth, bestHeight, bestRotation;
|
double bestArea, bestWidth, bestHeight, bestRotation;
|
||||||
|
List<double> hullAngles = null;
|
||||||
|
|
||||||
if (allPoints.Count >= 3)
|
if (allPoints.Count >= 3)
|
||||||
{
|
{
|
||||||
@@ -51,6 +52,7 @@ namespace OpenNest.Engine.BestFit
|
|||||||
bestWidth = result.Width;
|
bestWidth = result.Width;
|
||||||
bestHeight = result.Height;
|
bestHeight = result.Height;
|
||||||
bestRotation = result.Angle;
|
bestRotation = result.Angle;
|
||||||
|
hullAngles = RotationAnalysis.GetHullEdgeAngles(hull);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -59,6 +61,7 @@ namespace OpenNest.Engine.BestFit
|
|||||||
bestWidth = combinedBox.Width;
|
bestWidth = combinedBox.Width;
|
||||||
bestHeight = combinedBox.Length;
|
bestHeight = combinedBox.Length;
|
||||||
bestRotation = 0;
|
bestRotation = 0;
|
||||||
|
hullAngles = new List<double> { 0 };
|
||||||
}
|
}
|
||||||
|
|
||||||
var trueArea = drawing.Area * 2;
|
var trueArea = drawing.Area * 2;
|
||||||
@@ -71,6 +74,7 @@ namespace OpenNest.Engine.BestFit
|
|||||||
BoundingHeight = bestHeight,
|
BoundingHeight = bestHeight,
|
||||||
OptimalRotation = bestRotation,
|
OptimalRotation = bestRotation,
|
||||||
TrueArea = trueArea,
|
TrueArea = trueArea,
|
||||||
|
HullAngles = hullAngles,
|
||||||
Keep = !overlaps,
|
Keep = !overlaps,
|
||||||
Reason = overlaps ? "Overlap detected" : "Valid"
|
Reason = overlaps ? "Overlap detected" : "Valid"
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -80,6 +80,11 @@ namespace OpenNest
|
|||||||
return new List<double> { 0 };
|
return new List<double> { 0 };
|
||||||
|
|
||||||
var hull = ConvexHull.Compute(points);
|
var hull = ConvexHull.Compute(points);
|
||||||
|
return GetHullEdgeAngles(hull);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<double> GetHullEdgeAngles(Polygon hull)
|
||||||
|
{
|
||||||
var vertices = hull.Vertices;
|
var vertices = hull.Vertices;
|
||||||
var n = hull.IsClosed() ? vertices.Count - 1 : vertices.Count;
|
var n = hull.IsClosed() ? vertices.Count - 1 : vertices.Count;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user