feat: add Arc.SplitAt(Vector) splitting primitive
This commit is contained in:
@@ -155,6 +155,28 @@ namespace OpenNest.Geometry
|
|||||||
Center.Y + Radius * System.Math.Sin(EndAngle));
|
Center.Y + Radius * System.Math.Sin(EndAngle));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Splits the arc at the given point, returning two sub-arcs.
|
||||||
|
/// Either half may be null if the split point coincides with an endpoint.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="point">The point at which to split the arc.</param>
|
||||||
|
/// <returns>A tuple of (first, second) sub-arcs.</returns>
|
||||||
|
public (Arc first, Arc second) SplitAt(Vector point)
|
||||||
|
{
|
||||||
|
if (point.DistanceTo(StartPoint()) < Tolerance.Epsilon)
|
||||||
|
return (null, new Arc(Center, Radius, StartAngle, EndAngle, IsReversed));
|
||||||
|
|
||||||
|
if (point.DistanceTo(EndPoint()) < Tolerance.Epsilon)
|
||||||
|
return (new Arc(Center, Radius, StartAngle, EndAngle, IsReversed), null);
|
||||||
|
|
||||||
|
var splitAngle = Angle.NormalizeRad(Center.AngleTo(point));
|
||||||
|
|
||||||
|
var firstArc = new Arc(Center, Radius, StartAngle, splitAngle, IsReversed);
|
||||||
|
var secondArc = new Arc(Center, Radius, splitAngle, EndAngle, IsReversed);
|
||||||
|
|
||||||
|
return (firstArc, secondArc);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns true if the given arc has the same center point and radius as this.
|
/// Returns true if the given arc has the same center point and radius as this.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user