示例#1
0
 def closestPoint(self, pos):
     """
     Find the closest curve point for a specific position
     
     :param QPoint pos: Position, where to look for the closest curve point
     :return: tuple `(index, dist)`
     
     `dist` is the distance between the position and the closest curve 
     point. `index` is the index of the closest curve point, or -1 if 
     none can be found ( f.e when the curve has no points ).
     
     .. note::
     
         `closestPoint()` implements a dumb algorithm, that iterates
         over all points
     """
     numSamples = self.dataSize()
     if self.plot() is None or numSamples <= 0:
         return -1
     series = self.data()
     xMap = self.plot().canvasMap(self.xAxis())
     yMap = self.plot().canvasMap(self.yAxis())
     index = -1
     dmin = 1.0e10
     for i in range(numSamples):
         sample = series.sample(i)
         cx = xMap.transform(sample.x()) - pos.x()
         cy = yMap.transform(sample.y()) - pos.y()
         f = qwtSqr(cx) + qwtSqr(cy)
         if f < dmin:
             index = i
             dmin = f
     dist = np.sqrt(dmin)
     return index, dist
示例#2
0
 def closestPoint(self, pos):
     """
     Find the closest curve point for a specific position
     
     :param QPoint pos: Position, where to look for the closest curve point
     :return: tuple `(index, dist)`
     
     `dist` is the distance between the position and the closest curve 
     point. `index` is the index of the closest curve point, or -1 if 
     none can be found ( f.e when the curve has no points ).
     
     .. note::
     
         `closestPoint()` implements a dumb algorithm, that iterates
         over all points
     """
     numSamples = self.dataSize()
     if self.plot() is None or numSamples <= 0:
         return -1
     series = self.data()
     xMap = self.plot().canvasMap(self.xAxis())
     yMap = self.plot().canvasMap(self.yAxis())
     index = -1
     dmin = 1.0e10
     for i in range(numSamples):
         sample = series.sample(i)
         cx = xMap.transform(sample.x())-pos.x()
         cy = yMap.transform(sample.y())-pos.y()
         f = qwtSqr(cx)+qwtSqr(cy)
         if f < dmin:
             index = i
             dmin = f
     dist = np.sqrt(dmin)
     return index, dist
示例#3
0
 def closestPoint(self, pos):
     numSamples = self.dataSize()
     if self.plot() is None or numSamples <= 0:
         return -1
     series = self.data()
     xMap = self.plot().canvasMap(self.xAxis())
     yMap = self.plot().canvasMap(self.yAxis())
     index = -1
     dmin = 1.0e10
     for i in range(numSamples):
         sample = series.sample(i)
         cx = xMap.transform(sample.x())-pos.x()
         cy = yMap.transform(sample.y())-pos.y()
         f = qwtSqr(cx)+qwtSqr(cy)
         if f < dmin:
             index = i
             dmin = f
     dist = np.sqrt(dmin)
     return index, dist
示例#4
0
 def closestPoint(self, pos):
     numSamples = self.dataSize()
     if self.plot() is None or numSamples <= 0:
         return -1
     series = self.data()
     xMap = self.plot().canvasMap(self.xAxis())
     yMap = self.plot().canvasMap(self.yAxis())
     index = -1
     dmin = 1.0e10
     for i in range(numSamples):
         sample = series.sample(i)
         cx = xMap.transform(sample.x()) - pos.x()
         cy = yMap.transform(sample.y()) - pos.y()
         f = qwtSqr(cx) + qwtSqr(cy)
         if f < dmin:
             index = i
             dmin = f
     dist = np.sqrt(dmin)
     return index, dist