def nearestOn2(self, points, closed=False, radius=R_M, height=None): '''Locate the point on a polygon (with great circle arcs joining consecutive points) closest to this point. If this point is within the extent of any great circle arc, the closest point is on that arc. Otherwise, the closest is the nearest of the arc's end points. @param points: The polygon points (L{LatLon}[]). @keyword closed: Optionally, close the polygon (C{bool}). @keyword radius: Optional, mean earth radius (C{meter}). @keyword height: Optional height, overriding the mean height for a point within the arc (C{meter}). @return: 2-Tuple (closest, distance) of the closest point (L{LatLon}) on the polygon and the distance to that point from the given point in C{meter}, same units of B{C{radius}}. @raise TypeError: Some B{C{points}} are not C{LatLon}. @raise ValueError: No B{C{points}}. ''' n, points = self.points2(points, closed=closed) i, m = _imdex2(closed, n) c = p2 = points[i] d = self.distanceTo(c, radius=radius) for i in range(m, n): p1, p2 = p2, points[i] p = self.nearestOn(p1, p2, height=height) t = self.distanceTo(p, radius=radius) if t < d: c, d = p, t return c, d
def _rads(n, points, closed): # angular edge lengths in radians i, m = _imdex2(closed, n) v1 = points[i].toNvector() for i in range(m, n): v2 = points[i].toNvector() yield v1.angleTo(v2) v1 = v2
def _rads(n, points, closed): # angular edge lengths in radians i, m = _imdex2(closed, n) a1, b1 = points[i].to2ab() for i in range(m, n): a2, b2 = points[i].to2ab() db, b2 = unrollPI(b1, b2, wrap=wrap) yield haversine_(a2, a1, db) a1, b1 = a2, b2
def clipCS3(points, lowerleft, upperright, closed=False, inull=False): # MCCABE 25 '''Clip a path against a rectangular clip box using the U{Cohen-Sutherland <http://WikiPedia.org/wiki/Cohen-Sutherland_algorithm>} algorithm. @param points: The points (C{LatLon}[]). @param lowerleft: Bottom-left corner of the clip box (C{LatLon}). @param upperright: Top-right corner of the clip box (C{LatLon}). @keyword closed: Optionally, close the path (C{bool}). @keyword inull: Optionally, include null edges if inside (C{bool}). @return: Yield a 3-tuple (start, end, index) for each edge of the clipped path with the start and end points C{LatLon} of the portion of the edge inside or on the clip box and the index C{int} of the edge in the original path. @raise ValueError: The I{lowerleft} corner is not below and/or not to the left of the I{upperright} corner. ''' cs = _CS(lowerleft, upperright) n, points = points2(points, closed=closed) i, m = _imdex2(closed, n) cmbp = cs.code4(points[i]) for i in range(m, n): c1, m1, b1, p1 = cmbp c2, m2, b2, p2 = cmbp = cs.code4(points[i]) if c1 & c2: # edge outside continue if not cs.edge(p1, p2): if inull: # null edge if not c1: yield p1, p1, i elif not c2: yield p2, p2, i continue for _ in range(5): if c1: # clip p1 c1, m1, b1, p1 = m1(b1, p1) elif c2: # clip p2 c2, m2, b2, p2 = m2(b2, p2) else: # inside if inull or _neq(p1, p2): yield p1, p2, i break if c1 & c2: # edge outside break else: # should never get here raise AssertionError('clipCS3.for_')