Index: src/Common/NetTopologySuite/Algorithm/PointLocator.cs =================================================================== diff -u -r8f6ae890fed8e8eae3a32f9c0498a10f82e0ddf9 -r5fc71a385897af92ccb092f2f969b5709afab85a --- src/Common/NetTopologySuite/Algorithm/PointLocator.cs (.../PointLocator.cs) (revision 8f6ae890fed8e8eae3a32f9c0498a10f82e0ddf9) +++ src/Common/NetTopologySuite/Algorithm/PointLocator.cs (.../PointLocator.cs) (revision 5fc71a385897af92ccb092f2f969b5709afab85a) @@ -13,13 +13,13 @@ /// public class PointLocator { - private bool isIn; // true if the point lies in or on any Geometry element - private int numBoundaries; // the number of sub-elements whose boundaries the point lies in + private bool isIn; // true if the point lies in or on any Geometry element + private int numBoundaries; // the number of sub-elements whose boundaries the point lies in /// /// Initializes a new instance of the class. /// - public PointLocator() { } + public PointLocator() {} /// /// Convenience method to test a point for intersection with a Geometry @@ -41,19 +41,29 @@ public Locations Locate(ICoordinate p, IGeometry geom) { if (geom.IsEmpty) + { return Locations.Exterior; - if (geom is ILineString) - return Locate(p, (ILineString) geom); - else if (geom is IPolygon) + } + if (geom is ILineString) + { + return Locate(p, (ILineString) geom); + } + else if (geom is IPolygon) + { return Locate(p, (IPolygon) geom); - + } + isIn = false; numBoundaries = 0; ComputeLocation(p, geom); - if(GeometryGraph.IsInBoundary(numBoundaries)) + if (GeometryGraph.IsInBoundary(numBoundaries)) + { return Locations.Boundary; - if(numBoundaries > 0 || isIn) + } + if (numBoundaries > 0 || isIn) + { return Locations.Interior; + } return Locations.Exterior; } @@ -64,30 +74,40 @@ /// private void ComputeLocation(ICoordinate p, IGeometry geom) { - if (geom is ILineString) - UpdateLocationInfo(Locate(p, (ILineString) geom)); - else if(geom is Polygon) - UpdateLocationInfo(Locate(p, (IPolygon) geom)); - else if(geom is IMultiLineString) + if (geom is ILineString) { + UpdateLocationInfo(Locate(p, (ILineString) geom)); + } + else if (geom is Polygon) + { + UpdateLocationInfo(Locate(p, (IPolygon) geom)); + } + else if (geom is IMultiLineString) + { IMultiLineString ml = (IMultiLineString) geom; - foreach (ILineString l in ml.Geometries) - UpdateLocationInfo(Locate(p, l)); + foreach (ILineString l in ml.Geometries) + { + UpdateLocationInfo(Locate(p, l)); + } } - else if(geom is IMultiPolygon) + else if (geom is IMultiPolygon) { IMultiPolygon mpoly = (IMultiPolygon) geom; - foreach (IPolygon poly in mpoly.Geometries) + foreach (IPolygon poly in mpoly.Geometries) + { UpdateLocationInfo(Locate(p, poly)); + } } - else if (geom is IGeometryCollection) + else if (geom is IGeometryCollection) { IEnumerator geomi = new GeometryCollectionEnumerator((IGeometryCollection) geom); - while(geomi.MoveNext()) + while (geomi.MoveNext()) { IGeometry g2 = (IGeometry) geomi.Current; if (g2 != geom) + { ComputeLocation(p, g2); + } } } } @@ -98,10 +118,14 @@ /// private void UpdateLocationInfo(Locations loc) { - if(loc == Locations.Interior) + if (loc == Locations.Interior) + { isIn = true; - if(loc == Locations.Boundary) + } + if (loc == Locations.Boundary) + { numBoundaries++; + } } /// @@ -113,11 +137,17 @@ private Locations Locate(ICoordinate p, ILineString l) { ICoordinate[] pt = l.Coordinates; - if(!l.IsClosed) - if(p.Equals(pt[0]) || p.Equals(pt[pt.Length - 1])) - return Locations.Boundary; + if (!l.IsClosed) + { + if (p.Equals(pt[0]) || p.Equals(pt[pt.Length - 1])) + { + return Locations.Boundary; + } + } if (CGAlgorithms.IsOnLine(p, pt)) + { return Locations.Interior; + } return Locations.Exterior; } @@ -131,9 +161,13 @@ { // can this test be folded into IsPointInRing? if (CGAlgorithms.IsOnLine(p, ring.Coordinates)) + { return Locations.Boundary; + } if (CGAlgorithms.IsPointInRing(p, ring.Coordinates)) + { return Locations.Interior; + } return Locations.Exterior; } @@ -145,24 +179,34 @@ /// private Locations Locate(ICoordinate p, IPolygon poly) { - if (poly.IsEmpty) + if (poly.IsEmpty) + { return Locations.Exterior; + } ILinearRing shell = poly.Shell; Locations shellLoc = LocateInPolygonRing(p, shell); - if (shellLoc == Locations.Exterior) + if (shellLoc == Locations.Exterior) + { return Locations.Exterior; - if (shellLoc == Locations.Boundary) + } + if (shellLoc == Locations.Boundary) + { return Locations.Boundary; + } // now test if the point lies in or on the holes foreach (ILinearRing hole in poly.InteriorRings) { Locations holeLoc = LocateInPolygonRing(p, hole); - if (holeLoc == Locations.Interior) + if (holeLoc == Locations.Interior) + { return Locations.Exterior; - if (holeLoc == Locations.Boundary) + } + if (holeLoc == Locations.Boundary) + { return Locations.Boundary; + } } return Locations.Interior; } } -} +} \ No newline at end of file