Index: src/Common/NetTopologySuite/Algorithm/SimplePointInAreaLocator.cs =================================================================== diff -u -r8f6ae890fed8e8eae3a32f9c0498a10f82e0ddf9 -r5fc71a385897af92ccb092f2f969b5709afab85a --- src/Common/NetTopologySuite/Algorithm/SimplePointInAreaLocator.cs (.../SimplePointInAreaLocator.cs) (revision 8f6ae890fed8e8eae3a32f9c0498a10f82e0ddf9) +++ src/Common/NetTopologySuite/Algorithm/SimplePointInAreaLocator.cs (.../SimplePointInAreaLocator.cs) (revision 5fc71a385897af92ccb092f2f969b5709afab85a) @@ -15,7 +15,7 @@ /// /// /// - private SimplePointInAreaLocator() { } + private SimplePointInAreaLocator() {} /// /// Locate is the main location function. It handles both single-element @@ -27,59 +27,75 @@ public static Locations Locate(ICoordinate p, IGeometry geom) { if (geom.IsEmpty) + { return Locations.Exterior; + } if (ContainsPoint(p, geom)) + { return Locations.Interior; + } return Locations.Exterior; } /// /// /// /// - /// + /// /// - private static bool ContainsPoint(ICoordinate p, IGeometry geom) + public static bool ContainsPointInPolygon(ICoordinate p, IPolygon poly) { - if (geom is IPolygon) - return ContainsPointInPolygon(p, (IPolygon) geom); - else if(geom is IGeometryCollection) + if (poly.IsEmpty) { - IEnumerator geomi = new GeometryCollectionEnumerator((IGeometryCollection) geom); - while (geomi.MoveNext()) + return false; + } + ILinearRing shell = (ILinearRing) poly.ExteriorRing; + if (!CGAlgorithms.IsPointInRing(p, shell.Coordinates)) + { + return false; + } + // now test if the point lies in or on the holes + for (int i = 0; i < poly.NumInteriorRings; i++) + { + ILinearRing hole = (ILinearRing) poly.GetInteriorRingN(i); + if (CGAlgorithms.IsPointInRing(p, hole.Coordinates)) { - IGeometry g2 = (IGeometry) geomi.Current; - // if(g2 != geom) --- Diego Guidi say's: Java code tests reference equality: in C# with operator overloads we tests the object.equals()... more slower! - if (!ReferenceEquals(g2, geom)) - if (ContainsPoint(p, g2)) - return true; + return false; } } - return false; + return true; } /// /// /// /// - /// + /// /// - public static bool ContainsPointInPolygon(ICoordinate p, IPolygon poly) + private static bool ContainsPoint(ICoordinate p, IGeometry geom) { - if (poly.IsEmpty) - return false; - ILinearRing shell = (ILinearRing) poly.ExteriorRing; - if (!CGAlgorithms.IsPointInRing(p, shell.Coordinates)) - return false; - // now test if the point lies in or on the holes - for (int i = 0; i < poly.NumInteriorRings; i++) + if (geom is IPolygon) { - ILinearRing hole = (ILinearRing) poly.GetInteriorRingN(i); - if (CGAlgorithms.IsPointInRing(p, hole.Coordinates)) - return false; + return ContainsPointInPolygon(p, (IPolygon) geom); } - return true; + else if (geom is IGeometryCollection) + { + IEnumerator geomi = new GeometryCollectionEnumerator((IGeometryCollection) geom); + while (geomi.MoveNext()) + { + IGeometry g2 = (IGeometry) geomi.Current; + // if(g2 != geom) --- Diego Guidi say's: Java code tests reference equality: in C# with operator overloads we tests the object.equals()... more slower! + if (!ReferenceEquals(g2, geom)) + { + if (ContainsPoint(p, g2)) + { + return true; + } + } + } + } + return false; } } -} +} \ No newline at end of file