Coverage for pygeodesy/clipy.py : 94%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# -*- coding: utf-8 -*-
against a rectangular box or clip region.
@newfield example: Example, Examples '''
LatLon_ as LL_
abs(p1.lon - p2.lon) > EPS
'''(INTERNAL) Cohen-Sutherland line clipping. ''' # single-bit codes
raise ValueError('%s invalid: %r to %r' % ( 'clip box', lowerleft, upperright))
# def clip4(self, p, c): # clip point p for code c # if c & _CS._YMIN: # return self.lon4(p, self._ymin) # elif c & _CS._YMAX: # return self.lon4(p, self._ymax) # elif c & _CS._XMIN: # return self.lat4(p, self._xmin) # elif c & _CS._XMAX: # return self.lat4(p, self._xmax) # # should never get here # raise AssertionError('clipCS3.clip2')
else:
return _CS._YMAX, self.lon4, self._ymax, p else: # inside
return _CS._XMIN, self.lat4, self._xmin, p else: # inside
if p: # should never get here raise AssertionError('clipCS3.nop4') return _CS._IN, self.nop4, b, p
'''Clip a path against a rectangular clip box using the U{Cohen-Sutherland <https://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 L{ClipCS3Tuple}C{(start, end, index)} for each edge of the clipped path.
@raise ValueError: The B{C{lowerleft}} corner is not below and/or not to the left of the B{C{upperright}} corner. '''
continue
if inull: # null edge if not c1: yield ClipCS3Tuple(p1, p1, i) elif not c2: yield ClipCS3Tuple(p2, p2, i) continue
else: # inside else: # should never get here raise AssertionError('clipCS3.for _')
'''(INTERNAL) LatLon_ for _SH intersections. '''
'''(INTERNAL) Sutherland-Hodgman polyon clipping. ''' raise ValueError raise ValueError('%s[%s] invalid: %r' % ('corners', n, corners))
np -= 1 raise ValueError('too few %s: %s' % ('points', np))
# clip the points, closed # self.append(p1, False, e) else: # ... p2 outside
# no is True iff all points are on or at one # side (left or right) of each clip edge, # ni is True iff all points are on or on the # right side (i.e. inside) of all clip edges
else: # original point
# clip corner c1 and clip edge c1 to c2, indicating whether # points[i] is located to the right, to the left or on the # (extended) clip edge from c1 to c2 self._dy * float(p.lon - self._x1) # clockwise corners, +1 means points[i] is to the right # of, -1 means on the left of, 0 means on edge c1 to c2
# of polygon edge p1 to p2 and the current clip edge, # where p1 and p2 are known to NOT be located on the # same side of or on the current clip edge # <https://StackOverflow.com/questions/563198/ # how-do-you-detect-where-two-line-segments-intersect> raise AssertionError('clipSH.intersect')
'''Clip a polygon against a clip region or box using the U{Sutherland-Hodgman <https://WikiPedia.org/wiki/Sutherland_Hodgman_algorithm>} algorithm.
@param points: The polygon points (C{LatLon}[]). @param corners: Three or more points defining a convex clip region (C{LatLon}[]) or two points to specify a rectangular clip box. @keyword inull: Optionally, include null edges (C{bool}). @keyword closed: Close the clipped points (C{bool}).
@return: Yield the clipped points (C{LatLon}[]).
@raise ValueError: Insufficient number of B{C{points}} or the B{C{corners}} specify a polar, zero-area, non-convex or otherwise invalid clip region. '''
'''Clip a polygon against a clip region or box using the U{Sutherland-Hodgman <https://WikiPedia.org/wiki/Sutherland_Hodgman_algorithm>} algorithm.
@param points: The polygon points (C{LatLon}[]). @param corners: Three or more points defining a convex clip region (C{LatLon}[]) or two points to specify a rectangular clip box. @keyword inull: Optionally, include null edges (C{bool}). @keyword closed: Close the clipped points (C{bool}).
@return: Yield a L{ClipSH3Tuple}C{(start, end, original)} for each edge of the clipped polygon.
@raise ValueError: Insufficient number of B{C{points}} or the B{C{corners}} specify a polar, zero-area, non-convex or otherwise invalid clip region. '''
# **) MIT License # # Copyright (C) 2018-2020 -- mrJean1 at Gmail -- All Rights Reserved. # # Permission is hereby granted, free of charge, to any person obtaining a # copy of this software and associated documentation files (the "Software"), # to deal in the Software without restriction, including without limitation # the rights to use, copy, modify, merge, publish, distribute, sublicense, # and/or sell copies of the Software, and to permit persons to whom the # Software is furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included # in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR # OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR # OTHER DEALINGS IN THE SOFTWARE. |