[Kst] kdeextragear-2/kst/kst

George Staikos staikos at kde.org
Tue Jan 20 11:12:03 CET 2004


CVS commit by staikos: 

As the previous implementation wasn't considered "close enough", we now check
the point rounded up and down (slight bias upward), and use the shortest
distance instead of the closest Y point.  This is closer to the concept of
the "closest data point".  It still falls apart with very steep graphs.
CCMAIL: 72204 at bugs.kde.org


  M +25 -4     kstview.cpp   1.75


--- kdeextragear-2/kst/kst/kstview.cpp  #1.74:1.75
@@ -421,11 +421,32 @@ void KstView::updateMouse() {
         pt -= int((*i)->minX());
 
-        if (pt < 0) {
+        double ydiff, xdiff, nd;
+
+        if (pt >= 0 && pt < (*i)->sampleCount()) {
+          (*i)->getPoint(pt, xpt, ypt);
+          ydiff = ypos - ypt;
+          xdiff = xpos - xpt;
+          nd = ydiff*ydiff + xdiff*xdiff;
+          if (nd < delta) {
+            delta = nd;
+            newxpos = xpt;
+            newypos = ypt;
+            curve = *i;
+          }
+        }
+
+        // The previous point rounded down, let's round up.
+        // This doesn't help us with very vertical regions though.
+        pt++;
+        if (pt >= (*i)->sampleCount() || pt < 0) {
           continue;
         }
  
         (*i)->getPoint(pt, xpt, ypt);
-        if (fabs(ypos - ypt) < delta) {
-          delta = fabs(ypos - ypt);
+        ydiff = ypos - ypt;
+        xdiff = xpos - xpt;
+        nd = ydiff*ydiff + xdiff*xdiff;
+        if (nd < delta) {
+          delta = nd;
           newxpos = xpt;
           newypos = ypt;





More information about the Kst mailing list