Index: src/Common/NetTopologySuite/GeometriesGraph/PlanarGraph.cs
===================================================================
diff -u -r8f6ae890fed8e8eae3a32f9c0498a10f82e0ddf9 -r5fc71a385897af92ccb092f2f969b5709afab85a
--- src/Common/NetTopologySuite/GeometriesGraph/PlanarGraph.cs (.../PlanarGraph.cs) (revision 8f6ae890fed8e8eae3a32f9c0498a10f82e0ddf9)
+++ src/Common/NetTopologySuite/GeometriesGraph/PlanarGraph.cs (.../PlanarGraph.cs) (revision 5fc71a385897af92ccb092f2f969b5709afab85a)
@@ -18,23 +18,8 @@
/// Computing the intersections between all the edges and nodes of a single graph
/// Computing the intersections between the edges and nodes of two different graphs
///
- public class PlanarGraph
- {
- ///
- /// For nodes in the Collection, link the DirectedEdges at the node that are in the result.
- /// This allows clients to link only a subset of nodes in the graph, for
- /// efficiency (because they know that only a subset is of interest).
- ///
- ///
- public static void LinkResultDirectedEdges(IList nodes)
- {
- for (IEnumerator nodeit = nodes.GetEnumerator(); nodeit.MoveNext(); )
- {
- Node node = (Node) nodeit.Current;
- ((DirectedEdgeStar) node.Edges).LinkResultDirectedEdges();
- }
- }
-
+ public class PlanarGraph
+ {
///
///
///
@@ -62,61 +47,82 @@
///
///
///
- public PlanarGraph()
+ public PlanarGraph()
{
nodes = new NodeMap(new NodeFactory());
}
///
///
///
- ///
- public IEnumerator GetEdgeEnumerator()
+ public IList EdgeEnds
{
- return edges.GetEnumerator();
+ get
+ {
+ return edgeEndList;
+ }
}
///
///
///
- public IList EdgeEnds
+ public IList Nodes
{
get
{
- return edgeEndList;
+ return new ArrayList(nodes.Values);
}
}
+ ///
+ /// For nodes in the Collection, link the DirectedEdges at the node that are in the result.
+ /// This allows clients to link only a subset of nodes in the graph, for
+ /// efficiency (because they know that only a subset is of interest).
+ ///
+ ///
+ public static void LinkResultDirectedEdges(IList nodes)
+ {
+ for (IEnumerator nodeit = nodes.GetEnumerator(); nodeit.MoveNext();)
+ {
+ Node node = (Node) nodeit.Current;
+ ((DirectedEdgeStar) node.Edges).LinkResultDirectedEdges();
+ }
+ }
+
///
///
///
+ ///
+ public IEnumerator GetEdgeEnumerator()
+ {
+ return edges.GetEnumerator();
+ }
+
+ ///
+ ///
+ ///
///
///
///
public bool IsBoundaryNode(int geomIndex, ICoordinate coord)
{
Node node = nodes.Find(coord);
- if (node == null)
+ if (node == null)
+ {
return false;
+ }
Label label = node.Label;
- if (label != null && label.GetLocation(geomIndex) == Locations.Boundary)
+ if (label != null && label.GetLocation(geomIndex) == Locations.Boundary)
+ {
return true;
+ }
return false;
}
///
///
///
///
- protected void InsertEdge(Edge e)
- {
- edges.Add(e);
- }
-
- ///
- ///
- ///
- ///
public void Add(EdgeEnd e)
{
nodes.Add(e);
@@ -128,48 +134,37 @@
///
///
public IEnumerator GetNodeEnumerator()
- {
- return nodes.GetEnumerator();
- }
-
- ///
- ///
- ///
- public IList Nodes
{
- get
- {
- return new ArrayList(nodes.Values);
- }
+ return nodes.GetEnumerator();
}
///
///
///
///
///
- public Node AddNode(Node node)
- {
- return nodes.AddNode(node);
+ public Node AddNode(Node node)
+ {
+ return nodes.AddNode(node);
}
///
///
///
///
///
- public Node AddNode(ICoordinate coord)
+ public Node AddNode(ICoordinate coord)
{
- return nodes.AddNode(coord);
+ return nodes.AddNode(coord);
}
///
/// The node if found; null otherwise
///
///
- public Node Find(ICoordinate coord)
+ public Node Find(ICoordinate coord)
{
- return nodes.Find(coord);
+ return nodes.Find(coord);
}
///
@@ -180,7 +175,7 @@
public void AddEdges(IList edgesToAdd)
{
// create all the nodes for the edges
- for (IEnumerator it = edgesToAdd.GetEnumerator(); it.MoveNext(); )
+ for (IEnumerator it = edgesToAdd.GetEnumerator(); it.MoveNext();)
{
Edge e = (Edge) it.Current;
edges.Add(e);
@@ -202,7 +197,7 @@
///
public void LinkResultDirectedEdges()
{
- for (IEnumerator nodeit = nodes.GetEnumerator(); nodeit.MoveNext(); )
+ for (IEnumerator nodeit = nodes.GetEnumerator(); nodeit.MoveNext();)
{
Node node = (Node) nodeit.Current;
((DirectedEdgeStar) node.Edges).LinkResultDirectedEdges();
@@ -216,7 +211,7 @@
///
public void LinkAllDirectedEdges()
{
- for (IEnumerator nodeit = nodes.GetEnumerator(); nodeit.MoveNext(); )
+ for (IEnumerator nodeit = nodes.GetEnumerator(); nodeit.MoveNext();)
{
Node node = (Node) nodeit.Current;
((DirectedEdgeStar) node.Edges).LinkAllDirectedEdges();
@@ -231,11 +226,13 @@
/// The edge, if found null if the edge was not found.
public EdgeEnd FindEdgeEnd(Edge e)
{
- for (IEnumerator i = EdgeEnds.GetEnumerator(); i.MoveNext(); )
+ for (IEnumerator i = EdgeEnds.GetEnumerator(); i.MoveNext();)
{
EdgeEnd ee = (EdgeEnd) i.Current;
if (ee.Edge == e)
+ {
return ee;
+ }
}
return null;
}
@@ -248,12 +245,14 @@
/// The edge, if found null if the edge was not found.
public Edge FindEdge(ICoordinate p0, ICoordinate p1)
{
- for (int i = 0; i < edges.Count; i++)
+ for (int i = 0; i < edges.Count; i++)
{
Edge e = (Edge) edges[i];
ICoordinate[] eCoord = e.Coordinates;
if (p0.Equals(eCoord[0]) && p1.Equals(eCoord[1]))
+ {
return e;
+ }
}
return null;
}
@@ -267,19 +266,48 @@
/// The edge, if found null if the edge was not found.
public Edge FindEdgeInSameDirection(ICoordinate p0, ICoordinate p1)
{
- for (int i = 0; i < edges.Count; i++)
+ for (int i = 0; i < edges.Count; i++)
{
Edge e = (Edge) edges[i];
ICoordinate[] eCoord = e.Coordinates;
if (MatchInSameDirection(p0, p1, eCoord[0], eCoord[1]))
+ {
return e;
+ }
if (MatchInSameDirection(p0, p1, eCoord[eCoord.Length - 1], eCoord[eCoord.Length - 2]))
+ {
return e;
+ }
}
return null;
}
///
+ ///
+ ///
+ ///
+ public void WriteEdges(StreamWriter outstream)
+ {
+ outstream.WriteLine("Edges:");
+ for (int i = 0; i < edges.Count; i++)
+ {
+ outstream.WriteLine("edge " + i + ":");
+ Edge e = (Edge) edges[i];
+ e.Write(outstream);
+ e.EdgeIntersectionList.Write(outstream);
+ }
+ }
+
+ ///
+ ///
+ ///
+ ///
+ protected void InsertEdge(Edge e)
+ {
+ edges.Add(e);
+ }
+
+ ///
/// The coordinate pairs match if they define line segments lying in the same direction.
/// E.g. the segments are parallel and in the same quadrant
/// (as opposed to parallel and opposite!).
@@ -290,28 +318,16 @@
///
private bool MatchInSameDirection(ICoordinate p0, ICoordinate p1, ICoordinate ep0, ICoordinate ep1)
{
- if (! p0.Equals(ep0))
+ if (!p0.Equals(ep0))
+ {
return false;
- if (CGAlgorithms.ComputeOrientation(p0, p1, ep1) == CGAlgorithms.Collinear &&
- QuadrantOp.Quadrant(p0, p1) == QuadrantOp.Quadrant(ep0, ep1) )
+ }
+ if (CGAlgorithms.ComputeOrientation(p0, p1, ep1) == CGAlgorithms.Collinear &&
+ QuadrantOp.Quadrant(p0, p1) == QuadrantOp.Quadrant(ep0, ep1))
+ {
return true;
+ }
return false;
}
-
- ///
- ///
- ///
- ///
- public void WriteEdges(StreamWriter outstream)
- {
- outstream.WriteLine("Edges:");
- for (int i = 0; i < edges.Count; i++)
- {
- outstream.WriteLine("edge " + i + ":");
- Edge e = (Edge) edges[i];
- e.Write(outstream);
- e.EdgeIntersectionList.Write(outstream);
- }
- }
}
-}
+}
\ No newline at end of file