Method Join
- Namespace
- GeometryHelper.Core
- Assembly
- GeometryHelper.dll
Join(IEnumerable<GeoLine2>)
Joins a collection of segments into polylines by matching endpoints, using the default tolerance.
public static GeoPolyline2[] Join(IEnumerable<GeoLine2> lines)
Parameters
linesIEnumerable<GeoLine2>
Returns
Join(IEnumerable<GeoLine2>, Tolerance)
Joins a collection of line segments into polylines by matching endpoints, similar to AutoCAD's JOIN command. Non-collinear connected segments form polylines, and collinear segments are simplified by removing redundant junctions.
public static GeoPolyline2[] Join(IEnumerable<GeoLine2> lines, Tolerance tolerance)
Parameters
linesIEnumerable<GeoLine2>The line segments to join.
toleranceToleranceThe tolerance.
Returns
- GeoPolyline2[]
An array of joined polylines.
Remarks
Unlike ConsecutiveLines(IEnumerable<GeoLine2>, Tolerance) the segments arrive in no particular order and pointing in no particular direction, so a run is grown outwards from a seed segment in both directions at once, turning round whatever it picks up when that is what makes it fit.
Which segment a run takes up where three or more meet at a point is settled by input order, there being no geometric reason at a fork to prefer one branch over another. The answer is the same every time for a given input, but reordering the input can move a branch from one run to another.
Segments are found through a grid keyed on their endpoints rather than by trying every pair, so the cost follows the number of segments instead of its square. The grid cannot be a plain lookup on the point, since two ends near enough to count as touching need not be identical and would hash apart; cells one tolerance wide put any two such points in the same cell or in adjoining ones, so the cell only narrows the field and the tolerance comparison still decides.
Exceptions
- ArgumentNullException
Thrown when
linesis null.