[Kst] [Bug 117822] double click on a curve only works if you are near an actual data point

Duncan Hanson duncan.hanson at gmail.com
Wed May 10 02:06:40 CEST 2006


------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.
         
http://bugs.kde.org/show_bug.cgi?id=117822         
duncan.hanson gmail com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED



------- Additional Comments From duncan.hanson gmail com  2006-05-10 02:06 -------
SVN commit 539223 by dhanson:

BUG:117822 fixed Barth's report, as well as some other problems which I missed the first time round.

 M  +4 -3      libkstapp/kst2dplot.cpp  
 M  +14 -6     libkstmath/kstvcurve.cpp  


--- trunk/extragear/graphics/kst/src/libkstapp/kst2dplot.cpp #539222:539223
 @ -3689,7 +3689,7  @
       (*i)->point(i_near_x, near_x, near_y);
       distance = fabs(ypos - near_y);
       
-      if (distance < best_distance || !rc ) {
+      if (distance < best_distance || !rc) {
         newypos = near_y;
         newxpos = near_x;
         best_distance = distance;
 @ -6079,10 +6079,11  @
     dx_per_pix = pow(10.0, dx_per_pix);
   }
   dx_per_pix -= xpos;
+  double dx = 5*dx_per_pix;
 
   for (KstBaseCurveList::Iterator i = Curves.begin(); i != Curves.end(); ++i) {
     (*i)->readLock();
-    double distance = (*i)->distanceToPoint(xpos, dx_per_pix, ypos);
+    double distance = (*i)->distanceToPoint(xpos, dx, ypos);
     (*i)->readUnlock();
     if (isYLog()) {
       distance = log(distance);
 @ -6093,7 +6094,7  @
     }
   }
 
-  if (curve && best_distance/fabs((ymax - ymin) / pr.height()) <= 5) {
+  if (curve && fabs(best_distance * pr.height() / (ymax - ymin)) <= 5) {
     curve->readLock();
     KstDataObjectPtr provider = curve->providerDataObject();
     if (provider) {
--- trunk/extragear/graphics/kst/src/libkstmath/kstvcurve.cpp #539222:539223
 @ -1613,12 +1613,14  @
 
 
 double KstVCurve::distanceToPoint(double xpos, double dx, double ypos) const {
-// find the y distance between the curve and a point.
+// find the y distance between the curve and a point. return 1.0E300 if this distance is undefined. i don't want to use -1 because it will make the code which uses this function messy.
   KstVectorPtr xv = *_inputVectors.find(COLOR_XVECTOR);
   if (!xv) {
-    return 0; // anything better we can do?
+    return 1.0E300; // anything better we can do?
   }
 
+  double distance = 1.0E300; // default value.
+
   if (hasLines() && xv->isRising()) {
   // if hasLines then we should find the distance between the curve and the point, not the data and the point. if isRising because it is (probably) to slow to use this technique if the data is unordered.
     // borrowed from indexNearX. use binary search to find the indices immediately above and below our xpos.
 @ -1641,16 +1643,22  @
     point(i_bot, x_bot, y_bot);
     point(i_top, x_top, y_top);
 
-    double near_y = (y_top - y_bot) * (xpos - x_bot) + y_bot; // calculate y value for line segment between x_bot and x_top.
-
-    return fabs(ypos - near_y);
+    if (x_bot < xpos && x_top > xpos) {
+      double near_y = (y_top - y_bot) * (xpos - x_bot) + y_bot; // calculate y value for line segment between   x_bot and x_top.
+      distance = fabs(ypos - near_y);
+    }
   } else {
   // !hasLines- find the distance between the data and the point.
     int i_near_x = getIndexNearXY(xpos, dx, ypos);
     double near_x, near_y;
     point(i_near_x, near_x, near_y);
-    return fabs(ypos - near_y);
+
+    if (fabs(near_x - xpos) < dx) {
+      distance = fabs(ypos - near_y);
+    }
   }
+
+  return distance;
 }


More information about the Kst mailing list