using System.Collections;
using Core.Gis.GeoApi.Geometries;
namespace Core.GIS.NetTopologySuite.Planargraph
{
///
/// A sorted collection of DirectedEdges which leave a Node
/// in a PlanarGraph.
///
public class DirectedEdgeStar
{
///
/// The underlying list of outgoing DirectedEdges.
///
protected IList outEdges = new ArrayList();
private bool sorted = false;
///
/// Returns the number of edges around the Node associated with this DirectedEdgeStar.
///
public int Degree
{
get
{
return outEdges.Count;
}
}
///
/// Returns the coordinate for the node at wich this star is based.
///
public ICoordinate Coordinate
{
get
{
IEnumerator it = GetEnumerator();
if (!it.MoveNext())
{
return null;
}
DirectedEdge e = (DirectedEdge) it.Current;
return e.Coordinate;
}
}
///
/// Returns the DirectedEdges, in ascending order by angle with the positive x-axis.
///
public IList Edges
{
get
{
SortEdges();
return outEdges;
}
}
///
/// Adds a new member to this DirectedEdgeStar.
///
///
public void Add(DirectedEdge de)
{
outEdges.Add(de);
sorted = false;
}
///
/// Drops a member of this DirectedEdgeStar.
///
///
public void Remove(DirectedEdge de)
{
outEdges.Remove(de);
}
///
/// Returns an Iterator over the DirectedEdges, in ascending order by angle with the positive x-axis.
///
public IEnumerator GetEnumerator()
{
SortEdges();
return outEdges.GetEnumerator();
}
///
/// Returns the zero-based index of the given Edge, after sorting in ascending order
/// by angle with the positive x-axis.
///
///
///
public int GetIndex(Edge edge)
{
SortEdges();
for (int i = 0; i < outEdges.Count; i++)
{
DirectedEdge de = (DirectedEdge) outEdges[i];
if (de.Edge == edge)
{
return i;
}
}
return -1;
}
///
/// Returns the zero-based index of the given DirectedEdge, after sorting in ascending order
/// by angle with the positive x-axis.
///
///
///
public int GetIndex(DirectedEdge dirEdge)
{
SortEdges();
for (int i = 0; i < outEdges.Count; i++)
{
DirectedEdge de = (DirectedEdge) outEdges[i];
if (de == dirEdge)
{
return i;
}
}
return -1;
}
///
/// Returns the remainder when i is divided by the number of edges in this
/// DirectedEdgeStar.
///
///
///
public int GetIndex(int i)
{
int modi = i%outEdges.Count;
//I don't think modi can be 0 (assuming i is positive) [Jon Aquino 10/28/2003]
if (modi < 0)
{
modi += outEdges.Count;
}
return modi;
}
///
/// Returns the DirectedEdge on the left-hand side of the given DirectedEdge (which
/// must be a member of this DirectedEdgeStar).
///
///
///
public DirectedEdge GetNextEdge(DirectedEdge dirEdge)
{
int i = GetIndex(dirEdge);
return (DirectedEdge) outEdges[GetIndex(i + 1)];
}
///
///
///
private void SortEdges()
{
if (!sorted)
{
ArrayList list = (ArrayList) outEdges;
list.Sort();
sorted = true;
}
}
}
}