From 3de44a729329380e46198a830cd568c210ea5ac7 Mon Sep 17 00:00:00 2001 From: AJ Isaacs Date: Thu, 12 Mar 2026 23:53:25 -0400 Subject: [PATCH] feat: add Arc.SplitAt(Vector) splitting primitive --- OpenNest.Core/Geometry/Arc.cs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) 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. ///