Index: src/Common/NetTopologySuite/Noding/Snapround/HotPixel.cs =================================================================== diff -u -r8f6ae890fed8e8eae3a32f9c0498a10f82e0ddf9 -r5fc71a385897af92ccb092f2f969b5709afab85a --- src/Common/NetTopologySuite/Noding/Snapround/HotPixel.cs (.../HotPixel.cs) (revision 8f6ae890fed8e8eae3a32f9c0498a10f82e0ddf9) +++ src/Common/NetTopologySuite/Noding/Snapround/HotPixel.cs (.../HotPixel.cs) (revision 5fc71a385897af92ccb092f2f969b5709afab85a) @@ -6,7 +6,6 @@ namespace GisSharpBlog.NetTopologySuite.Noding.Snapround { - /// /// Implements a "hot pixel" as used in the Snap Rounding algorithm. /// A hot pixel contains the interior of the tolerance square and the boundary @@ -16,15 +15,15 @@ /// public class HotPixel { - private LineIntersector li = null; + private readonly LineIntersector li = null; - private ICoordinate pt = null; - private ICoordinate originalPt = null; + private readonly ICoordinate pt = null; + private readonly ICoordinate originalPt = null; - private ICoordinate p0Scaled = null; - private ICoordinate p1Scaled = null; + private readonly ICoordinate p0Scaled = null; + private readonly ICoordinate p1Scaled = null; - private double scaleFactor; + private readonly double scaleFactor; private double minx; private double maxx; @@ -36,7 +35,7 @@ * 10 * 23 */ - private ICoordinate[] corner = new ICoordinate[4]; + private readonly ICoordinate[] corner = new ICoordinate[4]; private Envelope safeEnv = null; @@ -51,7 +50,7 @@ originalPt = pt; this.pt = pt; this.scaleFactor = scaleFactor; - this.li = li; + this.li = li; if (scaleFactor != 1.0) { this.pt = new Coordinate(Scale(pt.X), Scale(pt.Y)); @@ -80,7 +79,7 @@ { if (safeEnv == null) { - double safeTolerance = 0.75 / scaleFactor; + double safeTolerance = 0.75/scaleFactor; safeEnv = new Envelope(originalPt.X - safeTolerance, originalPt.X + safeTolerance, originalPt.Y - safeTolerance, originalPt.Y + safeTolerance); } @@ -90,6 +89,48 @@ /// /// /// + /// + /// + /// + public bool Intersects(ICoordinate p0, ICoordinate p1) + { + if (scaleFactor == 1.0) + { + return IntersectsScaled(p0, p1); + } + + CopyScaled(p0, p0Scaled); + CopyScaled(p1, p1Scaled); + return IntersectsScaled(p0Scaled, p1Scaled); + } + + /// + /// + /// + /// + /// + /// + public bool IntersectsScaled(ICoordinate p0, ICoordinate p1) + { + double segMinx = Math.Min(p0.X, p1.X); + double segMaxx = Math.Max(p0.X, p1.X); + double segMiny = Math.Min(p0.Y, p1.Y); + double segMaxy = Math.Max(p0.Y, p1.Y); + + bool isOutsidePixelEnv = maxx < segMinx || minx > segMaxx || + maxy < segMiny || miny > segMaxy; + if (isOutsidePixelEnv) + { + return false; + } + bool intersects = IntersectsToleranceSquare(p0, p1); + Assert.IsTrue(!(isOutsidePixelEnv && intersects), "Found bad envelope test"); + return intersects; + } + + /// + /// + /// /// private void InitCorners(ICoordinate pt) { @@ -112,28 +153,12 @@ /// private double Scale(double val) { - return (double) Math.Round(val * scaleFactor); + return (double) Math.Round(val*scaleFactor); } /// /// /// - /// - /// - /// - public bool Intersects(ICoordinate p0, ICoordinate p1) - { - if (scaleFactor == 1.0) - return IntersectsScaled(p0, p1); - - CopyScaled(p0, p0Scaled); - CopyScaled(p1, p1Scaled); - return IntersectsScaled(p0Scaled, p1Scaled); - } - - /// - /// - /// /// /// private void CopyScaled(ICoordinate p, ICoordinate pScaled) @@ -143,28 +168,6 @@ } /// - /// - /// - /// - /// - /// - public bool IntersectsScaled(ICoordinate p0, ICoordinate p1) - { - double segMinx = Math.Min(p0.X, p1.X); - double segMaxx = Math.Max(p0.X, p1.X); - double segMiny = Math.Min(p0.Y, p1.Y); - double segMaxy = Math.Max(p0.Y, p1.Y); - - bool isOutsidePixelEnv = maxx < segMinx || minx > segMaxx || - maxy < segMiny || miny > segMaxy; - if (isOutsidePixelEnv) - return false; - bool intersects = IntersectsToleranceSquare(p0, p1); - Assert.IsTrue(!(isOutsidePixelEnv && intersects), "Found bad envelope test"); - return intersects; - } - - /// /// Tests whether the segment p0-p1 intersects the hot pixel tolerance square. /// Because the tolerance square point set is partially open (along the /// top and right) the test needs to be more sophisticated than @@ -185,23 +188,50 @@ bool intersectsBottom = false; li.ComputeIntersection(p0, p1, corner[0], corner[1]); - if(li.IsProper) return true; + if (li.IsProper) + { + return true; + } li.ComputeIntersection(p0, p1, corner[1], corner[2]); - if(li.IsProper) return true; - if(li.HasIntersection) intersectsLeft = true; + if (li.IsProper) + { + return true; + } + if (li.HasIntersection) + { + intersectsLeft = true; + } li.ComputeIntersection(p0, p1, corner[2], corner[3]); - if(li.IsProper) return true; - if(li.HasIntersection) intersectsBottom = true; + if (li.IsProper) + { + return true; + } + if (li.HasIntersection) + { + intersectsBottom = true; + } li.ComputeIntersection(p0, p1, corner[3], corner[0]); - if(li.IsProper) return true; + if (li.IsProper) + { + return true; + } - if(intersectsLeft && intersectsBottom) return true; + if (intersectsLeft && intersectsBottom) + { + return true; + } - if(p0.Equals(pt)) return true; - if(p1.Equals(pt)) return true; + if (p0.Equals(pt)) + { + return true; + } + if (p1.Equals(pt)) + { + return true; + } return false; } @@ -219,14 +249,26 @@ private bool IntersectsPixelClosure(ICoordinate p0, ICoordinate p1) { li.ComputeIntersection(p0, p1, corner[0], corner[1]); - if(li.HasIntersection) return true; + if (li.HasIntersection) + { + return true; + } li.ComputeIntersection(p0, p1, corner[1], corner[2]); - if(li.HasIntersection) return true; + if (li.HasIntersection) + { + return true; + } li.ComputeIntersection(p0, p1, corner[2], corner[3]); - if(li.HasIntersection) return true; + if (li.HasIntersection) + { + return true; + } li.ComputeIntersection(p0, p1, corner[3], corner[0]); - if(li.HasIntersection) return true; + if (li.HasIntersection) + { + return true; + } return false; } } -} +} \ No newline at end of file