using System.Collections;
using System.Linq;
using Core.Gis.GeoApi.Geometries;
using Wintellect.PowerCollections;
namespace Core.GIS.NetTopologySuite.Planargraph
{
///
/// A node in a PlanarGraph is a location where 0 or more Edges
/// meet. A node is connected to each of its incident Edges via an outgoing
/// DirectedEdge. Some clients using a PlanarGraph may want to
/// subclass Node to add their own application-specific
/// data and methods.
///
public class Node : GraphComponent
{
///
/// The location of this Node.
///
protected ICoordinate pt;
///
/// The collection of DirectedEdges that leave this Node.
///
protected DirectedEdgeStar deStar;
///
/// Constructs a Node with the given location.
///
///
public Node(ICoordinate pt) : this(pt, new DirectedEdgeStar()) {}
///
/// Constructs a Node with the given location and collection of outgoing DirectedEdges.
///
///
///
public Node(ICoordinate pt, DirectedEdgeStar deStar)
{
this.pt = pt;
this.deStar = deStar;
}
///
/// Tests whether this component has been removed from its containing graph.
///
///
public override bool IsRemoved
{
get
{
return pt == null;
}
}
///
/// Returns the location of this Node.
///
public ICoordinate Coordinate
{
get
{
return pt;
}
}
///
/// Returns the collection of DirectedEdges that leave this Node.
///
public DirectedEdgeStar OutEdges
{
get
{
return deStar;
}
}
///
/// Returns the number of edges around this Node.
///
public int Degree
{
get
{
return deStar.Degree;
}
}
///
/// Returns all Edges that connect the two nodes (which are assumed to be different).
///
///
///
///
public static IList getEdgesBetween(Node node0, Node node1)
{
IList edges0 = DirectedEdge.ToEdges(node0.OutEdges.Edges);
Set commonEdges = new Set(edges0.Cast());
IList edges1 = DirectedEdge.ToEdges(node1.OutEdges.Edges);
commonEdges.RemoveMany(edges1.Cast());
return new ArrayList(commonEdges);
}
///
/// Adds an outgoing DirectedEdge to this Node.
///
///
public void AddOutEdge(DirectedEdge de)
{
deStar.Add(de);
}
///
/// 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)
{
return deStar.GetIndex(edge);
}
///
///
///
///
public override string ToString()
{
return "NODE: " + pt.ToString() + ": " + Degree;
}
///
/// Removes this node from its containing graph.
///
internal void Remove()
{
pt = null;
}
}
}