using System.Collections;
using System.Collections.Generic;
using Wintellect.PowerCollections;
namespace Core.GIS.NetTopologySuite.Planargraph
{
///
/// A subgraph of a .
/// A subgraph may contain any subset of s
/// from the parent graph.
/// It will also automatically contain all s
/// and s associated with those edges.
/// No new objects are created when edges are added -
/// all associated components must already exist in the parent graph.
///
public class Subgraph
{
///
///
///
protected PlanarGraph parentGraph;
///
///
///
protected Set edges = new Set();
///
///
///
protected IList dirEdges = new List();
///
///
///
protected NodeMap nodeMap = new NodeMap();
///
/// Creates a new subgraph of the given .
///
///
public Subgraph(PlanarGraph parentGraph)
{
this.parentGraph = parentGraph;
}
///
/// Gets the which this subgraph is part of.
///
///
public PlanarGraph GetParent()
{
return parentGraph;
}
///
/// Adds an to the subgraph.
/// The associated s and s are also added.
///
/// The to add.
public void Add(Edge e)
{
if (edges.Contains(e))
{
return;
}
edges.Add(e);
dirEdges.Add(e.GetDirEdge(0));
dirEdges.Add(e.GetDirEdge(1));
nodeMap.Add(e.GetDirEdge(0).FromNode);
nodeMap.Add(e.GetDirEdge(1).FromNode);
}
///
/// Returns an over the s in this graph,
/// in the order in which they were added.
///
///
public IEnumerator GetDirEdgeEnumerator()
{
return dirEdges.GetEnumerator();
}
///
/// Returns an over the s in this graph,
/// in the order in which they were added.
///
///
public IEnumerator GetEdgeEnumerator()
{
return edges.GetEnumerator();
}
///
/// Returns an over the s in this graph.
///
///
public IEnumerator GetNodeEnumerator()
{
return nodeMap.GetEnumerator();
}
///
/// Tests whether an is contained in this subgraph.
///
/// The to test.
/// true if the is contained in this subgraph.
public bool Contains(Edge e)
{
return edges.Contains(e);
}
}
}