Index: src/Common/NetTopologySuite/Noding/SegmentNodeList.cs =================================================================== diff -u -r8f6ae890fed8e8eae3a32f9c0498a10f82e0ddf9 -r5fc71a385897af92ccb092f2f969b5709afab85a --- src/Common/NetTopologySuite/Noding/SegmentNodeList.cs (.../SegmentNodeList.cs) (revision 8f6ae890fed8e8eae3a32f9c0498a10f82e0ddf9) +++ src/Common/NetTopologySuite/Noding/SegmentNodeList.cs (.../SegmentNodeList.cs) (revision 5fc71a385897af92ccb092f2f969b5709afab85a) @@ -14,7 +14,7 @@ public class SegmentNodeList : IEnumerable { private readonly IDictionary nodeMap = new OrderedDictionary(); - private readonly SegmentString edge; // the parent edge + private readonly SegmentString edge; // the parent edge /// /// Initializes a new instance of the class. @@ -29,9 +29,12 @@ /// /// /// - public SegmentString Edge + public SegmentString Edge { - get { return edge; } + get + { + return edge; + } } /// @@ -48,7 +51,7 @@ if (ei != null) { // debugging sanity check - Assert.IsTrue(ei.Coordinate.Equals2D(intPt), "Found equal nodes with different coordinates"); + Assert.IsTrue(ei.Coordinate.Equals2D(intPt), "Found equal nodes with different coordinates"); return ei; } // node does not exist, so create it @@ -57,12 +60,53 @@ } /// + /// Creates new edges for all the edges that the intersections in this + /// list split the parent edge into. + /// Adds the edges to the provided argument list + /// (this is so a single list can be used to accumulate all split edges + /// for a set of s). + /// + /// + public void AddSplitEdges(IList edgeList) + { + // ensure that the list has entries for the first and last point of the edge + AddEndPoints(); + AddCollapsedNodes(); + + // there should always be at least two entries in the list, since the endpoints are nodes + var ie = GetEnumerator(); + ie.MoveNext(); + var eiPrev = (SegmentNode) ie.Current; + while (ie.MoveNext()) + { + var ei = (SegmentNode) ie.Current; + var newEdge = CreateSplitEdge(eiPrev, ei); + edgeList.Add(newEdge); + eiPrev = ei; + } + } + + /// + /// + /// + /// + public void Write(StreamWriter outstream) + { + outstream.Write("Intersections:"); + foreach (var obj in this) + { + var ei = (SegmentNode) obj; + ei.Write(outstream); + } + } + + /// /// Returns an iterator of SegmentNodes. /// /// An iterator of SegmentNodes. - public IEnumerator GetEnumerator() - { - return nodeMap.Values.GetEnumerator(); + public IEnumerator GetEnumerator() + { + return nodeMap.Values.GetEnumerator(); } /// @@ -90,9 +134,9 @@ FindCollapsesFromExistingVertices(collapsedVertexIndexes); // node the collapses - foreach(var obj in collapsedVertexIndexes) + foreach (var obj in collapsedVertexIndexes) { - var vertexIndex = (int)obj; + var vertexIndex = (int) obj; Add(edge.GetCoordinate(vertexIndex), vertexIndex); } } @@ -109,8 +153,10 @@ var p0 = edge.GetCoordinate(i); var p1 = edge.GetCoordinate(i + 1); var p2 = edge.GetCoordinate(i + 2); - if (p0.Equals2D(p2)) // add base of collapse as node - collapsedVertexIndexes.Add(i + 1); + if (p0.Equals2D(p2)) // add base of collapse as node + { + collapsedVertexIndexes.Add(i + 1); + } } } @@ -125,18 +171,20 @@ private void FindCollapsesFromInsertedNodes(IList collapsedVertexIndexes) { var collapsedVertexIndex = new int[1]; - - var ie = GetEnumerator(); - ie.MoveNext(); + var ie = GetEnumerator(); + ie.MoveNext(); + // there should always be at least two entries in the list, since the endpoints are nodes var eiPrev = (SegmentNode) ie.Current; while (ie.MoveNext()) { var ei = (SegmentNode) ie.Current; var isCollapsed = FindCollapseIndex(eiPrev, ei, collapsedVertexIndex); if (isCollapsed) + { collapsedVertexIndexes.Add(collapsedVertexIndex[0]); + } eiPrev = ei; } } @@ -151,11 +199,15 @@ private bool FindCollapseIndex(SegmentNode ei0, SegmentNode ei1, int[] collapsedVertexIndex) { // only looking for equal nodes - if (!ei0.Coordinate.Equals2D(ei1.Coordinate)) + if (!ei0.Coordinate.Equals2D(ei1.Coordinate)) + { return false; + } var numVerticesBetween = ei1.SegmentIndex - ei0.SegmentIndex; if (!ei1.IsInterior) + { numVerticesBetween--; + } // if there is a single vertex between the two equal nodes, this is a collapse if (numVerticesBetween == 1) { @@ -166,33 +218,6 @@ } /// - /// Creates new edges for all the edges that the intersections in this - /// list split the parent edge into. - /// Adds the edges to the provided argument list - /// (this is so a single list can be used to accumulate all split edges - /// for a set of s). - /// - /// - public void AddSplitEdges(IList edgeList) - { - // ensure that the list has entries for the first and last point of the edge - AddEndPoints(); - AddCollapsedNodes(); - - // there should always be at least two entries in the list, since the endpoints are nodes - var ie = GetEnumerator(); - ie.MoveNext(); - var eiPrev = (SegmentNode) ie.Current; - while (ie.MoveNext()) - { - var ei = (SegmentNode) ie.Current; - var newEdge = CreateSplitEdge(eiPrev, ei); - edgeList.Add(newEdge); - eiPrev = ei; - } - } - - /// /// /// /// @@ -204,13 +229,17 @@ var split0 = (SegmentString) splitEdges[0]; var pt0 = split0.GetCoordinate(0); if (!pt0.Equals2D(edgePts[0])) + { throw new Exception("bad split edge start point at " + pt0); + } - var splitn = (SegmentString)splitEdges[splitEdges.Count - 1]; + var splitn = (SegmentString) splitEdges[splitEdges.Count - 1]; var splitnPts = splitn.Coordinates; var ptn = splitnPts[splitnPts.Length - 1]; if (!ptn.Equals2D(edgePts[edgePts.Length - 1])) + { throw new Exception("bad split edge end point at " + ptn); + } } /// @@ -221,7 +250,7 @@ /// /// /// - SegmentString CreateSplitEdge(SegmentNode ei0, SegmentNode ei1) + private SegmentString CreateSplitEdge(SegmentNode ei0, SegmentNode ei1) { var npts = ei1.SegmentIndex - ei0.SegmentIndex + 2; @@ -230,43 +259,35 @@ // (This check is needed because the distance metric is not totally reliable!) // The check for point equality is 2D only - Z values are ignored var useIntPt1 = ei1.IsInterior || !ei1.Coordinate.Equals2D(lastSegStartPt); - if(!useIntPt1) + if (!useIntPt1) + { npts--; + } var pts = new ICoordinate[npts]; var ipt = 0; pts[ipt++] = new Coordinate(ei0.Coordinate); for (var i = ei0.SegmentIndex + 1; i <= ei1.SegmentIndex; i++) - pts[ipt++] = edge.GetCoordinate(i); - if (useIntPt1) + { + pts[ipt++] = edge.GetCoordinate(i); + } + if (useIntPt1) + { pts[ipt] = ei1.Coordinate; + } return new SegmentString(pts, edge.Data); } - - /// - /// - /// - /// - public void Write(StreamWriter outstream) - { - outstream.Write("Intersections:"); - foreach(var obj in this) - { - var ei = (SegmentNode) obj; - ei.Write(outstream); - } - } } /// /// /// - class NodeVertexIterator : IEnumerator + internal class NodeVertexIterator : IEnumerator { + private readonly IEnumerator nodeIt; private SegmentNodeList nodeList; private SegmentString edge; - private readonly IEnumerator nodeIt; private SegmentNode currNode = null; private SegmentNode nextNode = null; private int currSegIndex = 0; @@ -275,21 +296,22 @@ /// /// /// - NodeVertexIterator(SegmentNodeList nodeList) + private NodeVertexIterator(SegmentNodeList nodeList) { this.nodeList = nodeList; edge = nodeList.Edge; - nodeIt = nodeList.GetEnumerator(); + nodeIt = nodeList.GetEnumerator(); } /// /// /// - private void ReadNextNode() + public object Current { - if (nodeIt.MoveNext()) - nextNode = (SegmentNode) nodeIt.Current; - else nextNode = null; + get + { + return currNode; + } } /// @@ -305,14 +327,6 @@ /// /// /// - public object Current - { - get { return currNode; } - } - - /// - /// - /// /// public bool MoveNext() { @@ -325,8 +339,10 @@ } // check for trying to read too far - if (nextNode == null) + if (nextNode == null) + { return false; + } if (nextNode.SegmentIndex == currNode.SegmentIndex) { @@ -336,10 +352,7 @@ return true; } - if (nextNode.SegmentIndex > currNode.SegmentIndex) - { - - } + if (nextNode.SegmentIndex > currNode.SegmentIndex) {} return false; } @@ -348,7 +361,22 @@ /// public void Reset() { - nodeIt.Reset(); + nodeIt.Reset(); } + + /// + /// + /// + private void ReadNextNode() + { + if (nodeIt.MoveNext()) + { + nextNode = (SegmentNode) nodeIt.Current; + } + else + { + nextNode = null; + } + } } -} +} \ No newline at end of file