namespace Core.GIS.NetTopologySuite.Planargraph
{
///
/// Represents an undirected edge of a {PlanarGraph}. An undirected edge
/// in fact simply acts as a central point of reference for two opposite
/// DirectedEdges.
/// Usually a client using a PlanarGraph will subclass Edge
/// to add its own application-specific data and methods.
///
public class Edge : GraphComponent
{
///
/// The two DirectedEdges associated with this Edge.
///
protected DirectedEdge[] dirEdge;
///
/// Tests whether this component has been removed from its containing graph.
///
///
public override bool IsRemoved
{
get
{
return dirEdge == null;
}
}
///
/// Initializes this Edge's two DirectedEdges, and for each DirectedEdge: sets the
/// Edge, sets the symmetric DirectedEdge, and adds this Edge to its from-Node.
///
///
///
public void SetDirectedEdges(DirectedEdge de0, DirectedEdge de1)
{
dirEdge = new DirectedEdge[]
{
de0,
de1,
};
de0.Edge = this;
de1.Edge = this;
de0.Sym = de1;
de1.Sym = de0;
de0.FromNode.AddOutEdge(de0);
de1.FromNode.AddOutEdge(de1);
}
///
/// Returns one of the DirectedEdges associated with this Edge.
///
/// 0 or 1.
///
public DirectedEdge GetDirEdge(int i)
{
return dirEdge[i];
}
///
/// Returns the DirectedEdge that starts from the given node, or null if the
/// node is not one of the two nodes associated with this Edge.
///
///
///
public DirectedEdge GetDirEdge(Node fromNode)
{
if (dirEdge[0].FromNode == fromNode)
{
return dirEdge[0];
}
if (dirEdge[1].FromNode == fromNode)
{
return dirEdge[1];
}
// node not found
// possibly should throw an exception here?
return null;
}
///
/// If node is one of the two nodes associated with this Edge,
/// returns the other node; otherwise returns null.
///
///
///
public Node GetOppositeNode(Node node)
{
if (dirEdge[0].FromNode == node)
{
return dirEdge[0].ToNode;
}
if (dirEdge[1].FromNode == node)
{
return dirEdge[1].ToNode;
}
// node not found
// possibly should throw an exception here?
return null;
}
///
/// Removes this edge from its containing graph.
///
internal void Remove()
{
dirEdge = null;
}
}
}