private Coordinate[] Snap(Coordinate[] coords) { var snapCoords = new CoordinateList(); for (int i = 0; i < coords.Length; i++) { var pt = snapIndex.Snap(coords[i]); snapCoords.Add(pt, false); } return(snapCoords.ToCoordinateArray()); }
/// <summary> /// This method is called by clients /// of the <see cref="ISegmentIntersector"/> class to process /// intersections for two segments of the <see cref="ISegmentString"/>s being intersected. /// Note that some clients (such as <c>MonotoneChain</c>s) may optimize away /// this call for segment pairs which they have determined do not intersect /// (e.g. by an disjoint envelope test). /// </summary> public void ProcessIntersections( ISegmentString seg0, int segIndex0, ISegmentString seg1, int segIndex1 ) { // don't bother intersecting a segment with itself if (seg0 == seg1 && segIndex0 == segIndex1) { return; } var p00 = seg0.Coordinates[segIndex0]; var p01 = seg0.Coordinates[segIndex0 + 1]; var p10 = seg1.Coordinates[segIndex1]; var p11 = seg1.Coordinates[segIndex1 + 1]; /* * Don't node intersections which are just * due to the shared vertex of adjacent segments. */ if (!IsAdjacent(seg0, segIndex0, seg1, segIndex1)) { _li.ComputeIntersection(p00, p01, p10, p11); //if (_li.HasIntersection && _li.IsProper) System.Diagnostics.Debug.WriteLine(_li); /* * Process single point intersections only. * Two-point (colinear) ones will be handled by the near-vertex code */ if (_li.HasIntersection && _li.IntersectionNum == 1) { var intPt = _li.GetIntersection(0); var snapPt = _snapPointIndex.Snap(intPt); ((NodedSegmentString)seg0).AddIntersection(snapPt, segIndex0); ((NodedSegmentString)seg1).AddIntersection(snapPt, segIndex1); } } /* * The segments must also be snapped to the other segment endpoints. */ ProcessNearVertex(seg0, segIndex0, p00, seg1, segIndex1, p10, p11); ProcessNearVertex(seg0, segIndex0, p01, seg1, segIndex1, p10, p11); ProcessNearVertex(seg1, segIndex1, p10, seg0, segIndex0, p00, p01); ProcessNearVertex(seg1, segIndex1, p11, seg0, segIndex0, p00, p01); }