def mapPoint(self, p, tol=tolerance.TOL): """See if an object in the PointBMapTree exists at a Point. mapPoint(p [, tol]) This method has one required parameter: p: Either a Point object or a tuple of two-floats There is a single optional argument: tol: A float equal or greater than 0 used to decide if the point is close enough to the objects held in the Tree. The function returns a list of at tuples, each of the form (obj, pt) obj: Object that the Point is mapped to pt: The projected Point on the object The list will contain at most two tuples. """ _p = p if not isinstance(_p, (point.Point, tuple)): raise TypeError, "Invalid type for searching in PointMapTree: " + `_p` if isinstance(_p, tuple): _x, _y = util.tuple_to_two_floats(_p) _p = point.Point(_x, _y) _t = tolerance.toltest(tol) _objlist = [] _scanlist = [] _lo = 0 _hi = len(self) while _lo < _hi: _mid = (_hi+_lo)//2 if _mid in _scanlist: break _scanlist.append(_mid) _obj = self[_mid] _res = cmp(_obj, _p) if _res == -1: _lo = _mid + 1 elif _res == 1: _hi = _mid else: _pt = _obj.mapPoint(_p, _t) if _pt is not None: _objlist.append((_obj, _pt)) break return _objlist
def mapPoint(self, p, tol=tolerance.TOL): """See if an object in the PointBMapTree exists at a Point. mapPoint(p [, tol]) This method has one required parameter: p: Either a Point object or a tuple of two-floats There is a single optional argument: tol: A float equal or greater than 0 used to decide if the point is close enough to the objects held in the Tree. The function returns a list of at tuples, each of the form (obj, pt) obj: Object that the Point is mapped to pt: The projected Point on the object The list will contain at most two tuples. """ _p = p if not isinstance(_p, (point.Point, tuple)): raise TypeError, "Invalid type for searching in PointMapTree: " + ` _p ` if isinstance(_p, tuple): _x, _y = util.tuple_to_two_floats(_p) _p = point.Point(_x, _y) _t = tolerance.toltest(tol) _objlist = [] _scanlist = [] _lo = 0 _hi = len(self) while _lo < _hi: _mid = (_hi + _lo) // 2 if _mid in _scanlist: break _scanlist.append(_mid) _obj = self[_mid] _res = cmp(_obj, _p) if _res == -1: _lo = _mid + 1 elif _res == 1: _hi = _mid else: _pt = _obj.mapPoint(_p, _t) if _pt is not None: _objlist.append((_obj, _pt)) break return _objlist
def __eq__(self, obj): """Compare a Point to either another Point or a tuple for equality. """ if not isinstance(obj, (Point, tuple)): return False if isinstance(obj, Point): if obj is self: return True _x, _y = obj.getCoords() else: _x, _y = util.tuple_to_two_floats(obj) if abs(self.__x - _x) < 1e-10 and abs(self.__y - _y) < 1e-10: return True return False
def __eq__(self, obj): """Compare a Point to either another Point or a tuple for equality. """ if not isinstance(obj, (Point,tuple)): return False if isinstance(obj, Point): if obj is self: return True _x, _y = obj.getCoords() else: _x, _y = util.tuple_to_two_floats(obj) if abs(self.__x - _x) < 1e-10 and abs(self.__y - _y) < 1e-10: return True return False
def mapPoint(self, p, tol=tolerance.TOL, count=2): """See if an object in the PointMapTree exists at a Point. mapPoint(p [, tol, count]) This method has one required parameter: p: Either a Point object or a tuple of two-floats There are two optional arguments: tol: A float equal or greater than 0 used to decide if the point is close enough to the objects held in the Tree. count: An integer indicating the maximum number of objects to return. By default this value is 2. The function returns a list of at tuples, each of the form (obj, pt) obj: Object that the Point is mapped to pt: The projected Point on the object """ _p = p if not isinstance(_p, (point.Point, tuple)): raise TypeError, "Invalid type for searching in PointMapTree: " + ` _p ` if isinstance(_p, tuple): _x, _y = util.tuple_to_two_floats(_p) _p = point.Point(_x, _y) _t = tolerance.toltest(tol) _count = count if not isinstance(_count, int): _count = int(count) if _count < 0: raise ValueError, "Invalid count: %d" % _count _objlist = [] for _obj in self: _pt = _obj.mapPoint(_p, _t) if _pt is not None: _objlist.append((_obj, _pt)) if len(_objlist) == _count or cmp(_obj, _p) == 1: break return _objlist
def mapPoint(self, p, tol=tolerance.TOL, count=2): """See if an object in the PointMapTree exists at a Point. mapPoint(p [, tol, count]) This method has one required parameter: p: Either a Point object or a tuple of two-floats There are two optional arguments: tol: A float equal or greater than 0 used to decide if the point is close enough to the objects held in the Tree. count: An integer indicating the maximum number of objects to return. By default this value is 2. The function returns a list of at tuples, each of the form (obj, pt) obj: Object that the Point is mapped to pt: The projected Point on the object """ _p = p if not isinstance(_p, (point.Point, tuple)): raise TypeError, "Invalid type for searching in PointMapTree: " + `_p` if isinstance(_p, tuple): _x, _y = util.tuple_to_two_floats(_p) _p = point.Point(_x, _y) _t = tolerance.toltest(tol) _count = count if not isinstance(_count, int): _count = int(count) if _count < 0: raise ValueError, "Invalid count: %d" % _count _objlist = [] for _obj in self: _pt = _obj.mapPoint(_p, _t) if _pt is not None: _objlist.append((_obj, _pt)) if len(_objlist) == _count or cmp(_obj, _p) == 1: break return _objlist
def __init__(self, x, y=None, **kw): """Initialize a Point. There are two ways to initialize a Point: Point(xc,yc) - Two arguments, with both arguments being floats Point((xc,yc)) - A single tuple containing two float objects """ super(Point, self).__init__(**kw) if isinstance(x, tuple): if y is not None: raise SyntaxError, "Invalid call to Point()" _x, _y = util.tuple_to_two_floats(x) elif y is not None: _x = util.get_float(x) _y = util.get_float(y) else: raise SyntaxError, "Invalid call to Point()." self.__x = _x self.__y = _y