using System.Collections;
using System.IO;
using GeoAPI.Geometries;
using Wintellect.PowerCollections;
namespace GisSharpBlog.NetTopologySuite.GeometriesGraph
{
///
/// A map of nodes, indexed by the coordinate of the node.
///
public class NodeMap
{
private readonly IDictionary nodeMap = new OrderedDictionary();
private readonly NodeFactory nodeFact;
///
///
///
///
public NodeMap(NodeFactory nodeFact)
{
this.nodeFact = nodeFact;
}
///
///
///
public IList Values
{
get
{
return new ArrayList(nodeMap.Values);
}
}
///
/// This method expects that a node has a coordinate value.
///
///
public Node AddNode(ICoordinate coord)
{
Node node = (Node) nodeMap[coord];
if (node == null)
{
node = nodeFact.CreateNode(coord);
nodeMap.Add(coord, node);
}
return node;
}
///
///
///
///
///
public Node AddNode(Node n)
{
Node node = (Node) nodeMap[n.Coordinate];
if (node == null)
{
nodeMap.Add(n.Coordinate, n);
return n;
}
node.MergeLabel(n);
return node;
}
///
/// Adds a node for the start point of this EdgeEnd
/// (if one does not already exist in this map).
/// Adds the EdgeEnd to the (possibly new) node.
///
///
public void Add(EdgeEnd e)
{
ICoordinate p = e.Coordinate;
Node n = AddNode(p);
n.Add(e);
}
///
/// The node if found; null otherwise.
///
///
public Node Find(ICoordinate coord)
{
return (Node) nodeMap[coord];
}
///
///
///
///
public IEnumerator GetEnumerator()
{
return nodeMap.Values.GetEnumerator();
}
///
///
///
///
///
public IList GetBoundaryNodes(int geomIndex)
{
IList bdyNodes = new ArrayList();
for (IEnumerator i = GetEnumerator(); i.MoveNext();)
{
Node node = (Node) i.Current;
if (node.Label.GetLocation(geomIndex) == Locations.Boundary)
{
bdyNodes.Add(node);
}
}
return bdyNodes;
}
///
///
///
///
public void Write(StreamWriter outstream)
{
for (IEnumerator i = GetEnumerator(); i.MoveNext();)
{
Node n = (Node) i.Current;
n.Write(outstream);
}
}
}
}