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