Index: src/Common/NetTopologySuite/Algorithm/SIRtreePointInRing.cs =================================================================== diff -u -r8f6ae890fed8e8eae3a32f9c0498a10f82e0ddf9 -r5fc71a385897af92ccb092f2f969b5709afab85a --- src/Common/NetTopologySuite/Algorithm/SIRtreePointInRing.cs (.../SIRtreePointInRing.cs) (revision 8f6ae890fed8e8eae3a32f9c0498a10f82e0ddf9) +++ src/Common/NetTopologySuite/Algorithm/SIRtreePointInRing.cs (.../SIRtreePointInRing.cs) (revision 5fc71a385897af92ccb092f2f969b5709afab85a) @@ -8,11 +8,11 @@ /// /// Implements PointInRing using a SIRtree index to increase performance. /// - public class SIRtreePointInRing : IPointInRing + public class SIRtreePointInRing : IPointInRing { - private ILinearRing ring; + private readonly ILinearRing ring; private SIRtree sirTree; - private int crossings = 0; // number of segment/ray crossings + private int crossings = 0; // number of segment/ray crossings /// /// @@ -27,32 +27,15 @@ /// /// /// - private void BuildIndex() - { - sirTree = new SIRtree(); - ICoordinate[] pts = ring.Coordinates; - for (int i = 1; i < pts.Length; i++) - { - if (pts[i - 1].Equals(pts[i])) - continue; - - LineSegment seg = new LineSegment(pts[i - 1], pts[i]); - sirTree.Insert(seg.P0.Y, seg.P1.Y, seg); - } - } - - /// - /// - /// /// /// public bool IsInside(ICoordinate pt) { crossings = 0; // test all segments intersected by vertical ray at pt - IList segs = sirTree.Query(pt.Y); - for(IEnumerator i = segs.GetEnumerator(); i.MoveNext(); ) + IList segs = sirTree.Query(pt.Y); + for (IEnumerator i = segs.GetEnumerator(); i.MoveNext();) { LineSegment seg = (LineSegment) i.Current; TestLineSegment(pt, seg); @@ -61,20 +44,41 @@ /* * p is inside if number of crossings is odd. */ - if ((crossings % 2) == 1) - return true; + if ((crossings%2) == 1) + { + return true; + } return false; } /// /// /// + private void BuildIndex() + { + sirTree = new SIRtree(); + ICoordinate[] pts = ring.Coordinates; + for (int i = 1; i < pts.Length; i++) + { + if (pts[i - 1].Equals(pts[i])) + { + continue; + } + + LineSegment seg = new LineSegment(pts[i - 1], pts[i]); + sirTree.Insert(seg.P0.Y, seg.P1.Y, seg); + } + } + + /// + /// + /// /// /// - private void TestLineSegment(ICoordinate p, LineSegment seg) + private void TestLineSegment(ICoordinate p, LineSegment seg) { - double xInt; // x intersection of segment with ray - double x1; // translated coordinates + double xInt; // x intersection of segment with ray + double x1; // translated coordinates double y1; double x2; double y2; @@ -89,19 +93,21 @@ x2 = p2.X - p.X; y2 = p2.Y - p.Y; - if (((y1 > 0) && (y2 <= 0)) || ((y2 > 0) && (y1 <= 0))) + if (((y1 > 0) && (y2 <= 0)) || ((y2 > 0) && (y1 <= 0))) { /* * segment straddles x axis, so compute intersection. */ - xInt = RobustDeterminant.SignOfDet2x2(x1, y1, x2, y2) / (y2 - y1); - + xInt = RobustDeterminant.SignOfDet2x2(x1, y1, x2, y2)/(y2 - y1); + /* * crosses ray if strictly positive intersection. */ - if (0.0 < xInt) - crossings++; + if (0.0 < xInt) + { + crossings++; + } } } } -} +} \ No newline at end of file