def map_coords(x, y, x1, y1, x2, y2, tol=tolerance.TOL): """ map_coords(x, y, x1, y1, x2, y2[, tol]) """ _x = get_float(x) _y = get_float(y) _x1 = get_float(x1) _y1 = get_float(y1) _x2 = get_float(x2) _y2 = get_float(y2) _t = tolerance.toltest(tol) if ((_x < min(_x1, _x2) - _t) or (_y < min(_y1, _y2) - _t) or (_x > max(_x1, _x2) + _t) or (_y > max(_y1, _y2) + _t)): return None _sqlen = pow((_x2 - _x1), 2) + pow((_y2 - _y1), 2) if _sqlen < 1e-10: # coincident points return None _r = ((_x - _x1) * (_x2 - _x1) + (_y - _y1) * (_y2 - _y1)) / _sqlen if _r < 0.0: _r = 0.0 if _r > 1.0: _r = 1.0 _px = _x1 + _r * (_x2 - _x1) _py = _y1 + _r * (_y2 - _y1) if abs(_px - _x) < _t and abs(_py - _y) < _t: return _px, _py return None
def find(self, *args): _alen = len(args) if _alen < 4: raise ValueError, "Invalid argument count: %d" % _alen _x1 = util.get_float(args[0]) _y1 = util.get_float(args[1]) _x2 = util.get_float(args[2]) _y2 = util.get_float(args[3]) _t = tolerance.TOL if _alen > 4: _t = tolerance.toltest(args[4]) _xmin = min(_x1, _x2) - _t _ymin = min(_y1, _y2) - _t _xmax = max(_x1, _x2) + _t _ymax = max(_y1, _y2) + _t _clines = [] for _cline in self.getInRegion(_xmin, _ymin, _xmax, _ymax): _p1, _p2 = _cline.getKeypoints() if ((abs(_p1.x - _x1) < _t) and (abs(_p1.y - _y1) < _t) and (abs(_p2.x - _x2) < _t) and (abs(_p2.y - _y2) < _t)): _clines.append(_cline) elif ((abs(_p1.x - _x2) < _t) and (abs(_p1.y - _y2) < _t) and (abs(_p2.x - _x1) < _t) and (abs(_p2.y - _y1) < _t)): _clines.append(_cline) else: pass return _clines
def find(self, *args): _alen = len(args) if _alen < 5: raise ValueError, "Invalid argument count: %d" % _alen _x = util.get_float(args[0]) _y = util.get_float(args[1]) _r = util.get_float(args[2]) _sa = util.get_float(args[3]) _ea = util.get_float(args[4]) _t = tolerance.TOL if _alen > 5: _t = tolerance.toltest(args[5]) _axmin = _x - _r - _t _axmax = _x + _r + _t _aymin = _y - _r - _t _aymax = _y + _r + _t _arcs = [] for _arc in self.getInRegion(_axmin, _aymin, _axmax, _aymax): _cx, _cy = _arc.getCenter().getCoords() if ((abs(_cx - _x) < _t) and (abs(_cy - _y) < _t) and (abs(_arc.getRadius() - _r) < _t) and (abs(_arc.getStartAngle() - _sa) < 1e-10) and (abs(_arc.getEndAngle() - _ea) < 1e-10)): _arcs.append(_arc) return _arcs
def mapCoords(self, x, y, tol=tolerance.TOL): """Return the nearest Point on the VCLine to a coordinate pair. mapCoords(x, y[, tol]) The function has two required argument: x: A Float value giving the 'x' coordinate y: A Float value giving the 'y' coordinate There is a single optional argument: tol: A float value equal or greater than 0.0 This function is used to map a possibly near-by coordinate pair to an actual Point on the VCLine. If the distance between the actual Point and the coordinates used as an argument is less than the tolerance, the actual Point is returned. Otherwise, this function returns None. """ _x = util.get_float(x) _y = util.get_float(y) _t = tolerance.toltest(tol) _vx = self.__keypoint.x if abs(_vx - x) < _t: return _vx, _y return None
def mapCoords(self, x, y, tol=tolerance.TOL): """Return the nearest Point on the Polyline by the x/y coordinates. mapCoords(x, y[, tol]) The function has two required arguments: x: A Float value giving the 'x' coordinate y: A Float value giving the 'y' coordinate There is a single optional argument: tol: A float value equal or greater than 0.0 This function is used to map a possibly near-by coordinate pair to a Point object on the Polyline. If the distance between the actual Point and the coordinates used as an argument is less than the tolerance, the actual Point is returned. Otherwise, this method returns None. """ _x = util.get_float(x) _y = util.get_float(y) _t = tolerance.toltest(tol) _count = len(self.__pts) - 1 for _i in range(_count): _x1, _y1 = self.__pts[_i].getCoords() _x2, _y2 = self.__pts[_i + 1].getCoords() _pt = util.map_coords(_x, _y, _x1, _y1, _x2, _y2, _t) if _pt is not None: return _pt return None
def find(self, *args): _alen = len(args) if _alen < 6: raise ValueError, "Invalid argument count: %d" % _alen _x1 = util.get_float(args[0]) _y1 = util.get_float(args[1]) _x2 = util.get_float(args[2]) _y2 = util.get_float(args[3]) _x3 = util.get_float(args[4]) _y3 = util.get_float(args[5]) _t = tolerance.TOL if _alen > 6: _t = tolerance.toltest(args[6]) _xmin = min(_x1, _x2, _x3) - _t _xmax = max(_x1, _x2, _x3) + _t _ymin = min(_y1, _y2, _y3) - _t _ymax = max(_y1, _y2, _y3) + _t _leaders = [] for _leader in self.getInRegion(_xmin, _ymin, _xmax, _ymax): _p1, _p2, _p3 = _leader.getPoints() if ((abs(_p1.x - _x1) < _t) and (abs(_p1.y - _y1) < _t) and (abs(_p2.x - _x2) < _t) and (abs(_p2.y - _y2) < _t) and (abs(_p3.x - _x3) < _t) and (abs(_p3.y - _y3) < _t)): _leaders.append(_leader) return _leaders
def getClosest(self, x, y, tol=tolerance.TOL): _x = util.get_float(x) _y = util.get_float(y) _t = tolerance.toltest(tol) _cline = _tsep = None _cdict = {} _nodes = [self.getTreeRoot()] while len(_nodes): _node = _nodes.pop() if _node.hasSubnodes(): _nodes.extend(_node.getSubnodes()) else: for _c in _node.getObjects(): _cid = id(_c) if _cid not in _cdict: _cx, _cy = _c.getProjection(_x, _y) if abs(_cx - _x) < _t and abs(_cy - _y) < _t: _sep = math.hypot((_cx - _x), (_cy - _y)) if _tsep is None: _tsep = _sep _cline = _c else: if _sep < _tsep: _tsep = _sep _cline = _c return _cline
def mapCoords(self, x, y, tol=tolerance.TOL): """Return the nearest Point on the CCircle to a coordinate pair. mapCoords(x, y[, tol]) The function has two required arguments: x: A Float value giving the x-coordinate y: A Float value giving the y-coordinate There is a single optional argument: tol: A float value equal or greater than 0.0 This function is used to map a possibly near-by coordinate pair to an actual Point on the CCircle. If the distance between the actual Point and the coordinates used as an argument is less than the tolerance, the actual Point is returned. Otherwise, this function returns None. """ _x = util.get_float(x) _y = util.get_float(y) _t = tolerance.toltest(tol) _cx, _cy = self.__center.getCoords() _r = self.__radius _dist = math.hypot((_x - _cx), (_y - _cy)) if abs(_dist - _r) < _t: _angle = math.atan2((_y - _cy),(_x - _cx)) _xoff = _r * math.cos(_angle) _yoff = _r * math.sin(_angle) return (_cx + _xoff), (_cy + _yoff) return None
def mapCoords(self, x, y, tol=tolerance.TOL): """Return the nearest Point on the CLine to a coordinate pair. mapCoords(x, y[, tol]) The function has two required arguments: x: A Float value giving the 'x' coordinate y: A Float value giving the 'y' coordinate There is a single optional argument: tol: A float value equal or greater than 0.0 This function is used to map a possibly near-by coordinate pair to a actual Point on the CLine. If the distance between the actual Point and the coordinates used as an argument is less than the tolerance, the actual Point is returned. Otherwise, this function returns None. """ _x = util.get_float(x) _y = util.get_float(y) _t = tolerance.toltest(tol) _x1, _y1 = self.__p1.getCoords() _x2, _y2 = self.__p2.getCoords() _sqlen = pow((_x2 - _x1), 2) + pow((_y2 - _y1), 2) if _sqlen < 1e-10: # both points the same raise RuntimeError, "CLine points coincident." _r = ((_x - _x1) * (_x2 - _x1) + (_y - _y1) * (_y2 - _y1)) / _sqlen _px = _x1 + _r * (_x2 - _x1) _py = _y1 + _r * (_y2 - _y1) if abs(_px - _x) < _t and abs(_py - _y) < _t: return _px, _py return None
def getClosest(self, x, y, tol=tolerance.TOL): _x = util.get_float(x) _y = util.get_float(y) _t = tolerance.toltest(tol) _acline = _tsep = None _adict = {} _nodes = [self.getTreeRoot()] while len(_nodes): _node = _nodes.pop() if _node.hasSubnodes(): _nodes.extend(_node.getSubnodes()) else: for _a in _node.getObjects(): _aid = id(_a) if _aid not in _adict: _ax, _ay = _a.getProjection(_x, _y) if abs(_ax - _x) < _t and abs(_ay - _y) < _t: _sep = math.hypot((_ax - _x), (_ay - _y)) if _tsep is None: _tsep = _sep _acline = _a else: if _sep < _tsep: _tsep = _sep _acline = _a return _acline
def map_coords(x, y, x1, y1, x2, y2, tol=tolerance.TOL): """ map_coords(x, y, x1, y1, x2, y2[, tol]) """ _x = get_float(x) _y = get_float(y) _x1 = get_float(x1) _y1 = get_float(y1) _x2 = get_float(x2) _y2 = get_float(y2) _t = tolerance.toltest(tol) if (_x < min(_x1, _x2) - _t) or (_y < min(_y1, _y2) - _t) or (_x > max(_x1, _x2) + _t) or (_y > max(_y1, _y2) + _t): return None _sqlen = pow((_x2 - _x1), 2) + pow((_y2 - _y1), 2) if _sqlen < 1e-10: # coincident points return None _r = ((_x - _x1) * (_x2 - _x1) + (_y - _y1) * (_y2 - _y1)) / _sqlen if _r < 0.0: _r = 0.0 if _r > 1.0: _r = 1.0 _px = _x1 + _r * (_x2 - _x1) _py = _y1 + _r * (_y2 - _y1) if abs(_px - _x) < _t and abs(_py - _y) < _t: return _px, _py return None
def mapCoords(self, x, y, tol=tolerance.TOL): """Return the nearest Point on the Leader to a coordinate pair. mapCoords(x, y[, tol]) The function has two required arguments: x: A Float value giving the 'x' coordinate y: A Float value giving the 'y' coordinate There is a single optional argument: tol: A float value equal or greater than 0.0 This function is used to map a possibly near-by coordinate pair to an actual Point on the Leader. If the distance between the actual Point and the coordinates used as an argument is less than the tolerance, the actual Point is returned. Otherwise, this function returns None. """ _x = util.get_float(x) _y = util.get_float(y) _t = tolerance.toltest(tol) _x1, _y1 = self.__p1.getCoords() _x2, _y2 = self.__p2.getCoords() _x3, _y3 = self.__p3.getCoords() _pt = util.map_coords(_x, _y, _x1, _y1, _x2, _y2, _t) if _pt is None: _pt = util.map_coords(_x, _y, _x2, _y2, _x3, _y3, _t) if _pt is not None: return _pt return None
def mapCoords(self, x, y, tol=tolerance.TOL): """Return the nearest Point on the Arc to a coordinate pair. mapCoords(x, y[, tol]) The function has two required arguments: x: A Float value giving the x-coordinate y: A Float value giving the y-coordinate There is a single optional argument: tol: A float value equal or greater than 0.0 This function is used to map a possibly near-by coordinate pair to an actual Point on the Arc. If the distance between the actual Point and the coordinates used as an argument is less than the tolerance, the actual Point is returned. Otherwise, this function returns None. """ _x = util.get_float(x) _y = util.get_float(y) _t = tolerance.toltest(tol) _cx, _cy = self.__center.getCoords() _r = self.__radius _dist = math.hypot((_x - _cx), (_y - _cy)) if abs(_dist - _r) < _t: _ra = math.atan2((_y - _cy), (_x - _cx)) _da = _ra * _rtd if _da < 0.0: _da = _da + 360.0 if self.throughAngle(_da): _xoff = _r * math.cos(_ra) _yoff = _r * math.sin(_ra) return (_cx + _xoff), (_cy + _yoff) return None
def mapCoords(self, x, y, tol=tolerance.TOL): """Return the nearest Point on the HCLine to a coordinate pair. mapCoords(x, y[, tol]) The function has two required argument: x: A Float value giving the 'x' coordinate y: A Float value giving the 'y' coordinate There is a single optional argument: tol: A float value equal or greater than 0.0 This function is used to map a possibly near-by coordinate pair to an actual Point on the HCLine. If the distance between the actual Point and the coordinates used as an argument is less than the tolerance, the actual Point is returned. Otherwise, this function returns None. """ _x = util.get_float(x) _y = util.get_float(y) _t = tolerance.toltest(tol) _hy = self.__keypoint.y if abs(_hy - _y) < _t: return _x, _hy return None
def getClosest(self, x, y, tol=tolerance.TOL): _x = util.get_float(x) _y = util.get_float(y) _t = tolerance.toltest(tol) _leader = _tsep = None _bailout = False _ldict = {} _nodes = [self.getTreeRoot()] while len(_nodes): _node = _nodes.pop() _xmin, _ymin, _xmax, _ymax = _node.getBoundary() if ((_x < (_xmin - _t)) or (_x > (_xmax + _t)) or (_y < (_ymin - _t)) or (_y > (_ymax + _t))): continue if _node.hasSubnodes(): _nodes.extend(_node.getSubnodes()) else: for _l in _node.getObjects(): _lid = id(_l) _p1, _p2, _p3 = _l.getPoints() if _lid not in _ldict: _px, _py = _p1.getCoords() if ((abs(_px - _x) < 1e-10) and (abs(_py - _y) < 1e-10)): _leader = _l _bailout = True break _px, _py = _p2.getCoords() if ((abs(_px - _x) < 1e-10) and (abs(_py - _y) < 1e-10)): _leader = _l _bailout = True break _px, _py = _p3.getCoords() if ((abs(_px - _x) < 1e-10) and (abs(_py - _y) < 1e-10)): _leader = _l _bailout = True break _ldict[_lid] = True _pt = _l.mapCoords(_x, _y, _t) if _pt is not None: _px, _py = _pt _sep = math.hypot((_px - _x), (_py - _y)) if _tsep is None: _tsep = _sep _leader = _l else: if _sep < _tsep: _tsep = _sep _leader = _l if _bailout: break return _leader
def find(self, *args): _alen = len(args) if _alen < 2: raise ValueError, "Invalid argument count: %d" % _alen _x = util.get_float(args[0]) _y = util.get_float(args[1]) _t = tolerance.TOL if _alen > 2 : _t = tolerance.toltest(args[2]) return self.getInRegion((_x - _t), (_y - _t), (_x + _t), (_y + _t))
def find(self, *args): _alen = len(args) if _alen < 2: raise ValueError, "Invalid argument count: %d" % _alen _x = util.get_float(args[0]) _y = util.get_float(args[1]) _t = tolerance.TOL if _alen > 2: _t = tolerance.toltest(args[2]) return self.getInRegion((_x - _t), (_y - _t), (_x + _t), (_y + _t))
def find(self, *args): _alen = len(args) if _alen < 1: raise ValueError, "Invalid argument count: %d" % _alen _x = util.get_float(args[0]) _t = tolerance.TOL if _alen > 1: _t = tolerance.toltest(args[1]) _xmin = _x - _t _xmax = _x + _t return self.getInRegion(_xmin, 0, _xmax, 1) # y values arbitrary
def find(self, *args): _alen = len(args) if _alen < 1: raise ValueError, "Invalid argument count: %d" % _alen if not isinstance(args[0], list): raise TypeError, "Invalid coordinate list: " + ` type(args[0]) ` _coords = [] _xmin = _xmax = _ymin = _ymax = None for _arg in args[0]: if not isinstance(_arg, tuple): raise TypeError, "Invalid coordinate tuple: " + ` type(_arg) ` if len(_arg) != 2: raise ValueError, "Invalid coodinate tuple: " + str(_arg) _x = util.get_float(_arg[0]) _y = util.get_float(_arg[1]) _coords.append((_x, _y)) if _xmin is None or _x < _xmin: _xmin = _x if _xmax is None or _x > _xmax: _xmax = _x if _ymin is None or _y < _ymin: _ymin = _y if _ymax is None or _y > _ymax: _ymax = _y _t = tolerance.TOL if _alen > 1: _t = tolerance.toltest(args[1]) _xmin = _xmin - _t _ymin = _ymin - _t _xmax = _xmax + _t _ymax = _ymax + _t _plines = [] for _pline in self.getInRegion(_xmin, _ymin, _xmax, _ymax): _pts = _pline.getPoints() if len(_pts) != len(_coords): continue _hit = False for _i in range(len(_pts)): _px, _py = _pts[_i].getCoords() if ((abs(_px - _coords[_i][0]) > _t) or (abs(_py - _coords[_i][1]) > _t)): continue _hit = True if not _hit: _pts.reverse() for _i in range(len(_pts)): _px, _py = _pts[_i].getCoords() if ((abs(_px - _coords[_i][0]) > _t) or (abs(_py - _coords[_i][1]) > _t)): continue _hit = True if _hit: _plines.append(_pline) return _plines
def find(self, *args): _alen = len(args) if _alen < 1: raise ValueError, "Invalid argument count: %d" % _alen if not isinstance(args[0], list): raise TypeError, "Invalid coordinate list: " + `type(args[0])` _coords = [] _xmin = _xmax = _ymin = _ymax = None for _arg in args[0]: if not isinstance(_arg, tuple): raise TypeError, "Invalid coordinate tuple: " + `type(_arg)` if len(_arg) != 2: raise ValueError, "Invalid coodinate tuple: " + str(_arg) _x = util.get_float(_arg[0]) _y = util.get_float(_arg[1]) _coords.append((_x, _y)) if _xmin is None or _x < _xmin: _xmin = _x if _xmax is None or _x > _xmax: _xmax= _x if _ymin is None or _y < _ymin: _ymin = _y if _ymax is None or _y > _ymax: _ymax = _y _t = tolerance.TOL if _alen > 1: _t = tolerance.toltest(args[1]) _xmin = _xmin - _t _ymin = _ymin - _t _xmax = _xmax + _t _ymax = _ymax + _t _plines = [] for _pline in self.getInRegion(_xmin, _ymin, _xmax, _ymax): _pts = _pline.getPoints() if len(_pts) != len(_coords): continue _hit = False for _i in range(len(_pts)): _px, _py = _pts[_i].getCoords() if ((abs(_px - _coords[_i][0]) > _t) or (abs(_py - _coords[_i][1]) > _t)): continue _hit = True if not _hit: _pts.reverse() for _i in range(len(_pts)): _px, _py = _pts[_i].getCoords() if ((abs(_px - _coords[_i][0]) > _t) or (abs(_py - _coords[_i][1]) > _t)): continue _hit = True if _hit: _plines.append(_pline) return _plines
def find(self, *args): _alen = len(args) if _alen < 1: raise ValueError, "Invalid argument count: %d" % _alen _y = util.get_float(args[0]) _t = tolerance.TOL if _alen > 1: _t = tolerance.toltest(args[1]) _hclines = [] _ymin = _y - _t _ymax = _y + _t return self.getInRegion(0, _ymin, 1, _ymax) # x values arbitrary
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 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 mapCoords(self, x, y, tol=tolerance.TOL): """Return the nearest Point on the ACLine to a coordinate pair. mapCoords(x, y[, tol]) The function has two required arguments: x: A Float value giving the x-coordinate y: A Float value giving the y-coordinate There is a single optional argument: tol: A float value equal or greater than 0.0 This function is used to map a possibly near-by coordinate pair to an actual Point on the ACLine. If the distance between the actual Point and the coordinates used as an argument is less than the tolerance, the actual Point is returned. Otherwise, this function returns None. """ _x = util.get_float(x) _y = util.get_float(y) _t = tolerance.toltest(tol) _xs, _ys = self.getLocation().getCoords() _angle = self.__angle # # the second point is 1 unit away - this simplifies things ... # if self.isHorizontal(): _x2 = _xs + 1.0 _y2 = _ys elif self.isVertical(): _x2 = _xs _y2 = _ys + 1.0 else: _x2 = _xs + math.cos(_angle * _dtr) _y2 = _ys + math.sin(_angle * _dtr) _r = ((_x - _xs)*(_x2 - _xs) + (_y - _ys)*(_y2 - _ys)) _px = _xs + (_r * (_x2 - _xs)) _py = _ys + (_r * (_y2 - _ys)) if abs(_px - _x) < _t and abs(_py - _y) < _t: return _px, _py return None
def mapCoords(self, x, y, tol=tolerance.TOL): """Return the nearest _Point on the Ellipse to a coordinate pair. mapCoords(x, y[, tol]) The function has two required arguments: x: A Float value giving the 'x' coordinate y: A Float value giving the 'y' coordinate There is a single optional argument: tol: A float value equal or greater than 0.0 This function is used to map a possibly near-by coordinate pair to an actual _Point on the Ellipse. If the distance between the actual _Point and the coordinates used as an argument is less than the tolerance, the actual _Point is returned. Otherwise, this function returns None. """ _x = util.get_float(x) _y = util.get_float(y) _t = tolerance.toltest(tol) _cx, _cy = self.__center.getCoords() _dist = math.hypot((_x - _cx), (_y - _cy)) _major = self.__major _minor = self.__minor _ep = None if abs(_major - _minor) < 1e-10: # circular _sep = _dist - _major if _sep < _t or abs(_sep - _t) < 1e-10: _angle = math.atan2((_y - _cy), (_x - _cx)) _px = _major * math.cos(_angle) _py = _major * math.sin(_angle) _ep = point._Point((_cx + _px), (_cy + _py)) else: if _dist < _major and _dist > _minor: _ecos = math.cos(self.__angle) _esin = math.sin(self.__angle) # FIXME ... return _ep
def find(self, *args): _alen = len(args) if _alen < 3: raise ValueError, "Invalid argument count: %d" % _alen _x = util.get_float(args[0]) _y = util.get_float(args[1]) _angle = util.make_angle(args[2]) _t = tolerance.TOL if _alen > 3: _t = tolerance.toltest(args[3]) _xmin = _x - _t _xmax = _x + _t _ymin = _y - _t _ymax = _y + _t _aclines = [] for _acl in self.getInRegion(_xmin, _ymin, _xmax, _ymax): _ax, _ay = _acl.getLocation().getCoords() if ((abs(_ax - _x) < _t) and (abs(_ay - _y) < _t) and (abs(_acl.getAngle() - _angle) < 1e-10)): _aclines.append(_acl) return _aclines
def find(self, *args): _alen = len(args) if _alen < 4: raise ValueError, "Invalid argument count: %d" % _alen _x1 = args[0] if not isinstance(_x1, float): _x1 = float(args[0]) _y1 = args[1] if not isinstance(_y1, float): _y1 = float(args[1]) _x2 = args[2] if not isinstance(_x2, float): _x2 = float(args[2]) _y2 = args[3] if not isinstance(_y2, float): _y2 = float(args[3]) _t = tolerance.TOL if _alen > 4: _t = tolerance.toltest(args[4]) _xmin = min(_x1, _x2) - _t _ymin = min(_y1, _y2) - _t _xmax = max(_x1, _x2) + _t _ymax = max(_y1, _y2) + _t _segs = [] for _seg in self.getInRegion(_xmin, _ymin, _xmax, _ymax): _p1, _p2 = _seg.getEndpoints() if ((abs(_x1 - _p1.x) < _t) and (abs(_y1 - _p1.y) < _t) and (abs(_x2 - _p2.x) < _t) and (abs(_y2 - _p2.y) < _t)): _segs.append(_seg) elif ((abs(_x2 - _p1.x) < _t) and (abs(_y2 - _p1.y) < _t) and (abs(_x1 - _p2.x) < _t) and (abs(_y1 - _p2.y) < _t)): _segs.append(_seg) else: pass return _segs
def find(self, *args): _alen = len(args) if _alen < 3: raise ValueError, "Invalid argument count: %d" % _alen _x = util.get_float(args[0]) _y = util.get_float(args[1]) _r = util.get_float(args[2]) _t = tolerance.TOL if _alen > 3: _t = tolerance.toltest(args[4]) _xmin = _x - _r - _t _xmax = _x + _r + _t _ymin = _y - _r - _t _ymax = _y + _r + _t _ccircles = [] for _ccirc in self.getInRegion(_xmin, _ymin, _xmax, _ymax): _cx, _cy = _ccirc.getCenter().getCoords() if ((abs(_cx - _x) < _t) and (abs(_cy - _y) < _t) and (abs(_ccirc.getRadius() - _r) < _t)): _ccircles.append(_ccirc) return _ccircles
def getClosest(self, x, y, tol=tolerance.TOL): _x = util.get_float(x) _y = util.get_float(y) _t = tolerance.toltest(tol) _dim = _tsep = None _bailout = False _ddict = {} _nodes = [self.getTreeRoot()] while len(_nodes): _node = _nodes.pop() _xmin, _ymin, _xmax, _ymax = _node.getBoundary() if ((_x < (_xmin - _t)) or (_x > (_xmax + _t)) or (_y < (_ymin - _t)) or (_y > (_ymax + _t))): continue if _node.hasSubnodes(): _nodes.extend(_node.getSubnodes()) else: for _d in _node.getObjects(): _did = id(_d) if _did not in _ddict: _pt = _d.mapCoords(_x, _y, _t) if _pt is not None: _px = _py = _pt _sep = math.hypot((_px - _x), (_py - _y)) if _tsep is None: _tsep = _sep _dim = _d else: if _sep < _tsep: _tsep = _sep _dim = _d if _dim is not None and _sep < 1e-10: _bailout = True break if _bailout: break return _dim