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:
@@ -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>();
|
||||
|
||||
Reference in New Issue
Block a user