diff base/ScaleTickIntervals.h @ 1412:b7a9edee85e0 scale-ticks

Change loop to something that feels more correct, though it makes no difference to the tests here. More tests, one failing.
author Chris Cannam
date Thu, 04 May 2017 08:32:41 +0100
parents 1f0d071e7ce6
children c6fa111b4553
line wrap: on
line diff
--- a/base/ScaleTickIntervals.h	Wed May 03 18:26:26 2017 +0100
+++ b/base/ScaleTickIntervals.h	Thu May 04 08:32:41 2017 +0100
@@ -20,7 +20,7 @@
 #include <vector>
 #include <cmath>
 
-//#define DEBUG_SCALE_TICK_INTERVALS 1
+#define DEBUG_SCALE_TICK_INTERVALS 1
 
 #ifdef DEBUG_SCALE_TICK_INTERVALS
 #include <iostream>
@@ -32,7 +32,7 @@
     struct Range {
 	double min;        // start of value range
 	double max;        // end of value range
-	int n;             // number of divisions (will be at most n+1 ticks)
+	int n;             // number of divisions (approximate only)
     };
 
     struct Tick {
@@ -146,9 +146,15 @@
         if (t.spacing < eps * 10.0) {
             eps = t.spacing / 10.0;
         }
-	for (double value = t.initial; value < r.max + eps; value += t.spacing) {
+        int n = 0;
+        while (true) {
+            double value = t.initial + n * t.spacing;
 	    value = t.roundTo * round(value / t.roundTo);
+            if (value >= r.max + eps) {
+                break;
+            }
 	    t.ticks.push_back(makeTick(value));
+            ++n;
 	}
     }
 };