using System;
using System.IO;
using GeoAPI.Geometries;
using GisSharpBlog.NetTopologySuite.Geometries;
namespace GisSharpBlog.NetTopologySuite.Noding
{
///
/// Represents an intersection point between two s.
///
public class SegmentNode : IComparable
{
///
///
///
public readonly ICoordinate Coordinate; // the point of intersection
///
///
///
public readonly int SegmentIndex; // the index of the containing line segment in the parent edge
private readonly SegmentString segString = null;
private readonly Octants segmentOctant = Octants.Null;
private readonly bool isInterior;
///
/// Initializes a new instance of the class.
///
///
///
///
///
public SegmentNode(SegmentString segString, ICoordinate coord, int segmentIndex, Octants segmentOctant)
{
Coordinate = null;
this.segString = segString;
Coordinate = new Coordinate(coord);
SegmentIndex = segmentIndex;
this.segmentOctant = segmentOctant;
isInterior = !coord.Equals2D(segString.GetCoordinate(segmentIndex));
}
///
///
///
///
public bool IsInterior
{
get
{
return isInterior;
}
}
///
///
///
///
///
public bool IsEndPoint(int maxSegmentIndex)
{
if (SegmentIndex == 0 && !isInterior)
{
return true;
}
return SegmentIndex == maxSegmentIndex;
}
///
///
///
///
public void Write(StreamWriter outstream)
{
outstream.Write(Coordinate);
outstream.Write(" seg # = " + SegmentIndex);
}
///
///
///
///
/// -1 this SegmentNode is located before the argument location, or
/// 0 this SegmentNode is at the argument location, or
/// 1 this SegmentNode is located after the argument location.
///
public int CompareTo(object obj)
{
var other = (SegmentNode) obj;
if (SegmentIndex < other.SegmentIndex)
{
return -1;
}
if (SegmentIndex > other.SegmentIndex)
{
return 1;
}
if (Coordinate.Equals2D(other.Coordinate))
{
return 0;
}
return SegmentPointComparator.Compare(segmentOctant, Coordinate, other.Coordinate);
}
}
}