using System;
using System.IO;
using Core.Gis.GeoApi.Geometries;
using Core.GIS.NetTopologySuite.Geometries;
namespace Core.GIS.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
{
///
///
///
///
///
///
public EdgeIntersection(ICoordinate coord, int segmentIndex, double dist)
{
Coordinate = new Coordinate(coord);
SegmentIndex = segmentIndex;
Distance = dist;
}
///
/// The point of intersection.
///
public ICoordinate Coordinate { get; set; }
///
/// The index of the containing line segment in the parent edge.
///
public int SegmentIndex { get; set; }
///
/// The edge distance of this point along the containing line segment.
///
public double Distance { get; set; }
///
///
///
///
///
///
/// -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 (SegmentIndex < segmentIndex)
{
return -1;
}
if (SegmentIndex > segmentIndex)
{
return 1;
}
if (Distance < dist)
{
return -1;
}
if (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);
}
///
///
///
///
///
public int CompareTo(object obj)
{
EdgeIntersection other = (EdgeIntersection) obj;
return Compare(other.SegmentIndex, other.Distance);
}
}
}