diff --git a/OpenNest.Core/Geometry/Arc.cs b/OpenNest.Core/Geometry/Arc.cs index e63b652..d48792f 100644 --- a/OpenNest.Core/Geometry/Arc.cs +++ b/OpenNest.Core/Geometry/Arc.cs @@ -155,6 +155,28 @@ namespace OpenNest.Geometry Center.Y + Radius * System.Math.Sin(EndAngle)); } + /// + /// Splits the arc at the given point, returning two sub-arcs. + /// Either half may be null if the split point coincides with an endpoint. + /// + /// The point at which to split the arc. + /// A tuple of (first, second) sub-arcs. + 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); + } + /// /// Returns true if the given arc has the same center point and radius as this. ///