internal static bool IsClockwiseRing(com.epl.geometry.MultiPathImpl polygon, int iring) { int high_point_index = polygon.GetHighestPointIndex(iring); int path_start = polygon.GetPathStart(iring); int path_end = polygon.GetPathEnd(iring); com.epl.geometry.Point2D q = polygon.GetXY(high_point_index); com.epl.geometry.Point2D p; com.epl.geometry.Point2D r; if (high_point_index == path_start) { p = polygon.GetXY(path_end - 1); r = polygon.GetXY(path_start + 1); } else { if (high_point_index == path_end - 1) { p = polygon.GetXY(high_point_index - 1); r = polygon.GetXY(path_start); } else { p = polygon.GetXY(high_point_index - 1); r = polygon.GetXY(high_point_index + 1); } } int orientation = com.epl.geometry.Point2D.OrientationRobust(p, q, r); if (orientation == 0) { return(polygon.CalculateRingArea2D(iring) > 0.0); } return(orientation == -1); }
public static int IsPointInAnyOuterRing(com.epl.geometry.Polygon inputPolygon, com.epl.geometry.Point2D inputPoint, double tolerance) { com.epl.geometry.Envelope2D env = new com.epl.geometry.Envelope2D(); inputPolygon.QueryLooseEnvelope(env); env.Inflate(tolerance, tolerance); if (!env.Contains(inputPoint)) { return(0); } // Note: // Wolfgang had noted that this could be optimized if the exterior rings // have positive area: // Only test the positive rings and bail out immediately when in a // positive ring. // The worst case complexity is still O(n), but on average for polygons // with holes, that would be faster. // However, that method would not work if polygon is reversed, while the // one here works fine same as PointInPolygon. bool bAltenate = false; // use winding in this test com.epl.geometry.PointInPolygonHelper helper = new com.epl.geometry.PointInPolygonHelper(bAltenate, inputPoint, tolerance); com.epl.geometry.MultiPathImpl mpImpl = (com.epl.geometry.MultiPathImpl)inputPolygon._getImpl(); com.epl.geometry.SegmentIteratorImpl iter = mpImpl.QuerySegmentIterator(); while (iter.NextPath()) { double ringArea = mpImpl.CalculateRingArea2D(iter.GetPathIndex()); bool bIsHole = ringArea < 0; if (!bIsHole) { helper.m_windnum = 0; while (iter.HasNextSegment()) { com.epl.geometry.Segment segment = iter.NextSegment(); if (helper.ProcessSegment(segment)) { return(-1); } } // point on boundary if (helper.m_windnum != 0) { return(1); } } } return(helper.Result()); }