diff --git a/OpenNest.Core/Geometry/Line.cs b/OpenNest.Core/Geometry/Line.cs index fde2123..0145f9e 100644 --- a/OpenNest.Core/Geometry/Line.cs +++ b/OpenNest.Core/Geometry/Line.cs @@ -414,6 +414,25 @@ namespace OpenNest.Geometry return OffsetEntity(distance, side); } + /// + /// Splits the line at the given point, returning two sub-lines. + /// Either half may be null if the split point coincides with an endpoint. + /// + /// The point at which to split the line. + /// A tuple of (first, second) sub-lines. + public (Line first, Line second) SplitAt(Vector point) + { + var first = point.DistanceTo(StartPoint) < Tolerance.Epsilon + ? null + : new Line(StartPoint, point); + + var second = point.DistanceTo(EndPoint) < Tolerance.Epsilon + ? null + : new Line(point, EndPoint); + + return (first, second); + } + /// /// Gets the closest point on the line to the given point. ///