using System; using System.IO; using GeoAPI.Geometries; using GisSharpBlog.NetTopologySuite.Geometries; namespace GisSharpBlog.NetTopologySuite.GeometriesGraph { /// /// An EdgeIntersection represents a point on an /// edge which intersects with another edge. /// The intersection may either be a single point, or a line segment /// (in which case this point is the start of the line segment) /// The label attached to this intersection point applies to /// the edge from this point forwards, until the next /// intersection or the end of the edge. /// The intersection point must be precise. /// public class EdgeIntersection : IComparable { private ICoordinate coordinate; /// /// The point of intersection. /// public ICoordinate Coordinate { get { return coordinate; } set { coordinate = value; } } private int segmentIndex; /// /// The index of the containing line segment in the parent edge. /// public int SegmentIndex { get { return segmentIndex; } set { segmentIndex = value; } } private double dist; /// /// The edge distance of this point along the containing line segment. /// public double Distance { get { return dist; } set { dist = value; } } /// /// /// /// /// /// public EdgeIntersection(ICoordinate coord, int segmentIndex, double dist) { this.coordinate = new Coordinate(coord); this.segmentIndex = segmentIndex; this.dist = dist; } /// /// /// /// /// public int CompareTo(object obj) { EdgeIntersection other = (EdgeIntersection) obj; return Compare(other.SegmentIndex, other.Distance); } /// /// /// /// /// /// /// -1 this EdgeIntersection is located before the argument location, /// 0 this EdgeIntersection is at the argument location, /// 1 this EdgeIntersection is located after the argument location. /// public int Compare(int segmentIndex, double dist) { if (this.SegmentIndex < segmentIndex) return -1; if (this.SegmentIndex > segmentIndex) return 1; if (this.Distance < dist) return -1; if (this.Distance > dist) return 1; return 0; } /// /// /// /// /// public bool IsEndPoint(int maxSegmentIndex) { if (SegmentIndex == 0 && Distance == 0.0) return true; if (SegmentIndex == maxSegmentIndex) return true; return false; } /// /// /// /// public void Write(StreamWriter outstream) { outstream.Write(Coordinate); outstream.Write(" seg # = " + SegmentIndex); outstream.WriteLine(" dist = " + Distance); } } }