feat: adaptive arc segmentation based on chord tolerance

Add SegmentsForTolerance(double) to Arc and Circle that calculates the
minimum segments needed to keep sagitta within the given tolerance.
Add Shape.ToPolygonWithTolerance() that uses it per arc/circle.

Push distance now uses 0.08" chord tolerance instead of a fixed segment
count, giving appropriate resolution for each arc based on its radius.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-06 18:59:30 -05:00
parent ec5eff4884
commit 28238cc246
4 changed files with 72 additions and 3 deletions

View File

@@ -122,6 +122,19 @@ namespace OpenNest.Geometry
return Center.DistanceTo(pt) <= Radius;
}
/// <summary>
/// Returns the minimum number of segments needed so that the chord-to-arc
/// deviation (sagitta) does not exceed the given tolerance.
/// </summary>
public int SegmentsForTolerance(double tolerance)
{
if (tolerance >= Radius)
return 3;
var maxAngle = 2.0 * System.Math.Acos(1.0 - tolerance / Radius);
return System.Math.Max(3, (int)System.Math.Ceiling(Angle.TwoPI / maxAngle));
}
public List<Vector> ToPoints(int segments = 1000)
{
var points = new List<Vector>();