mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-11-06 10:05:46 -05:00
fix(ui): scale part label search precision to material width
The plate view searched for each part's label point with PolyLabel's fixed 0.5" precision, a third of a 1.5" part, so the search stopped on the first interior cell and put labels near edges instead of in the thickest spot. Precision is now 5% of the part's mean material width (2 x net area over total outline length), so small, slender or heavily cut-out parts refine further while large solid ones stay cheap. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
add94dff6c
commit
3d1270a860
3 files changed
+76
-1
No files matched your search
@@ -24,6 +24,43 @@ namespace OpenNest.Geometry
|
||||
public static Vector Find(Polygon outer, IList<Polygon> holes, double precision, int maxCells) =>
|
||||
Find(outer, holes, precision, maxCells, out _);
|
||||
|
||||
/// <summary>
|
||||
/// A precision proportional to the shape's mean material width (twice the net area over
|
||||
/// the total outline length, holes included), so small or slender shapes refine further
|
||||
/// than large solid ones. A fixed precision near the shape's size stops at the first
|
||||
/// interior cell.
|
||||
/// </summary>
|
||||
public static double ThicknessPrecision(Polygon outer, IList<Polygon> holes = null, double fraction = 0.05)
|
||||
{
|
||||
var area = outer.Area();
|
||||
var length = ClosedLength(outer);
|
||||
|
||||
if (holes != null)
|
||||
{
|
||||
for (var i = 0; i < holes.Count; i++)
|
||||
{
|
||||
area -= holes[i].Area();
|
||||
length += ClosedLength(holes[i]);
|
||||
}
|
||||
}
|
||||
|
||||
if (!(area > 0) || !(length > 0))
|
||||
return 1e-9;
|
||||
|
||||
return System.Math.Max(fraction * 2 * area / length, 1e-9);
|
||||
}
|
||||
|
||||
private static double ClosedLength(Polygon polygon)
|
||||
{
|
||||
var verts = polygon.Vertices;
|
||||
var sum = 0.0;
|
||||
|
||||
for (int i = 0, j = verts.Count - 1; i < verts.Count; j = i++)
|
||||
sum += verts[j].DistanceTo(verts[i]);
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
internal static Vector Find(
|
||||
Polygon outer,
|
||||
IList<Polygon> holes,
|
||||
|
||||
Reference in new issue
Block a user