using System.Collections; using GeoAPI.Geometries; using GisSharpBlog.NetTopologySuite.Algorithm; using GisSharpBlog.NetTopologySuite.Index.Chain; namespace GisSharpBlog.NetTopologySuite.Noding { /// /// Finds proper and interior intersections in a set of s, /// and adds them as nodes. /// public class IntersectionFinderAdder : ISegmentIntersector { private readonly IList interiorIntersections = null; private readonly LineIntersector li = null; /// /// Creates an intersection finder which finds all proper intersections. /// /// The to use. public IntersectionFinderAdder(LineIntersector li) { this.li = li; interiorIntersections = new ArrayList(); } /// /// /// public IList InteriorIntersections { get { return interiorIntersections; } } /// /// This method is called by clients /// of the class to process /// intersections for two segments of the s being intersected. /// Note that some clients (such as s) may optimize away /// this call for segment pairs which they have determined do not intersect /// (e.g. by an disjoint envelope test). /// /// /// /// /// public void ProcessIntersections(SegmentString e0, int segIndex0, SegmentString e1, int segIndex1) { // don't bother intersecting a segment with itself if (e0 == e1 && segIndex0 == segIndex1) { return; } ICoordinate p00 = e0.Coordinates[segIndex0]; ICoordinate p01 = e0.Coordinates[segIndex0 + 1]; ICoordinate p10 = e1.Coordinates[segIndex1]; ICoordinate p11 = e1.Coordinates[segIndex1 + 1]; li.ComputeIntersection(p00, p01, p10, p11); if (li.HasIntersection) { if (li.IsInteriorIntersection()) { for (int intIndex = 0; intIndex < li.IntersectionNum; intIndex++) { interiorIntersections.Add(li.GetIntersection(intIndex)); } e0.AddIntersections(li, segIndex0, 0); e1.AddIntersections(li, segIndex1, 1); } } } } }