Index: src/Common/NetTopologySuite/Noding/Snapround/SimpleSnapRounder.cs =================================================================== diff -u -r8f6ae890fed8e8eae3a32f9c0498a10f82e0ddf9 -r5fc71a385897af92ccb092f2f969b5709afab85a --- src/Common/NetTopologySuite/Noding/Snapround/SimpleSnapRounder.cs (.../SimpleSnapRounder.cs) (revision 8f6ae890fed8e8eae3a32f9c0498a10f82e0ddf9) +++ src/Common/NetTopologySuite/Noding/Snapround/SimpleSnapRounder.cs (.../SimpleSnapRounder.cs) (revision 5fc71a385897af92ccb092f2f969b5709afab85a) @@ -7,7 +7,6 @@ namespace GisSharpBlog.NetTopologySuite.Noding.Snapround { - /// /// Uses Snap Rounding to compute a rounded, /// fully noded arrangement from a set of s. @@ -23,23 +22,60 @@ /// /// public class SimpleSnapRounder : INoder - { - private LineIntersector li = null; + { private readonly double scaleFactor; + private readonly LineIntersector li = null; private IList nodedSegStrings = null; /// /// Initializes a new instance of the class. /// /// The to use. - public SimpleSnapRounder(PrecisionModel pm) - { + public SimpleSnapRounder(PrecisionModel pm) + { li = new RobustLineIntersector(); li.PrecisionModel = pm; scaleFactor = pm.Scale; } /// + /// Computes nodes introduced as a result of + /// snapping segments to vertices of other segments. + /// + /// + public void ComputeVertexSnaps(IList edges) + { + foreach (SegmentString edge0 in edges) + { + foreach (SegmentString edge1 in edges) + { + ComputeVertexSnaps(edge0, edge1); + } + } + } + + /// + /// Adds a new node (equal to the snap pt) to the segment + /// if the segment passes through the hot pixel. + /// + /// + /// + /// + /// + public static bool AddSnappedNode(HotPixel hotPix, SegmentString segStr, int segIndex) + { + ICoordinate p0 = segStr.GetCoordinate(segIndex); + ICoordinate p1 = segStr.GetCoordinate(segIndex + 1); + + if (hotPix.Intersects(p0, p1)) + { + segStr.AddIntersection(hotPix.Coordinate, segIndex); + return true; + } + return false; + } + + /// /// Returns a of fully noded s. /// The s have the same context as their parent. /// @@ -57,8 +93,8 @@ /// public void ComputeNodes(IList inputSegmentStrings) { - this.nodedSegStrings = inputSegmentStrings; - SnapRound(inputSegmentStrings, li); + nodedSegStrings = inputSegmentStrings; + SnapRound(inputSegmentStrings, li); } /// @@ -73,7 +109,10 @@ { nv.CheckValid(); } - catch (Exception ex) { Trace.WriteLine(ex.ToString()); } + catch (Exception ex) + { + Trace.WriteLine(ex.ToString()); + } } /// @@ -99,7 +138,7 @@ private IList FindInteriorIntersections(IList segStrings, LineIntersector li) { IntersectionFinderAdder intFinderAdder = new IntersectionFinderAdder(li); - SinglePassNoder noder = new MCIndexNoder(intFinderAdder); + SinglePassNoder noder = new MCIndexNoder(intFinderAdder); noder.ComputeNodes(segStrings); return intFinderAdder.InteriorIntersections; } @@ -112,7 +151,9 @@ private void ComputeSnaps(IList segStrings, IList snapPts) { foreach (SegmentString ss in segStrings) - ComputeSnaps(ss, snapPts); + { + ComputeSnaps(ss, snapPts); + } } /// @@ -126,23 +167,13 @@ { HotPixel hotPixel = new HotPixel(snapPt, scaleFactor, li); for (int i = 0; i < ss.Count - 1; i++) + { AddSnappedNode(hotPixel, ss, i); + } } } /// - /// Computes nodes introduced as a result of - /// snapping segments to vertices of other segments. - /// - /// - public void ComputeVertexSnaps(IList edges) - { - foreach (SegmentString edge0 in edges) - foreach (SegmentString edge1 in edges) - ComputeVertexSnaps(edge0, edge1); - } - - /// /// Performs a brute-force comparison of every segment in each . /// This has n^2 performance. /// @@ -159,36 +190,21 @@ { // don't snap a vertex to itself if (e0 == e1) - if (i0 == i1) + { + if (i0 == i1) + { continue; - + } + } + bool isNodeAdded = AddSnappedNode(hotPixel, e1, i1); // if a node is created for a vertex, that vertex must be noded too if (isNodeAdded) - e0.AddIntersection(pts0[i0], i0); + { + e0.AddIntersection(pts0[i0], i0); + } } } } - - /// - /// Adds a new node (equal to the snap pt) to the segment - /// if the segment passes through the hot pixel. - /// - /// - /// - /// - /// - public static bool AddSnappedNode(HotPixel hotPix, SegmentString segStr, int segIndex) - { - ICoordinate p0 = segStr.GetCoordinate(segIndex); - ICoordinate p1 = segStr.GetCoordinate(segIndex + 1); - - if (hotPix.Intersects(p0, p1)) - { - segStr.AddIntersection(hotPix.Coordinate, segIndex); - return true; - } - return false; - } } -} +} \ No newline at end of file