diff base/ScaleTickIntervals.h @ 1423:04ce84f21af3

Merge
author Chris Cannam
date Thu, 31 Aug 2017 18:46:03 +0100
parents 91001e2bb96a 8b7d6c1e1ab7
children 48e9f538e6e9
line wrap: on
line diff
--- a/base/ScaleTickIntervals.h	Thu Aug 31 18:45:17 2017 +0100
+++ b/base/ScaleTickIntervals.h	Thu Aug 31 18:46:03 2017 +0100
@@ -147,10 +147,22 @@
         double min = r.min;
         
         if (roundTo != 0.0) {
-            inc = round(inc / roundTo) * roundTo;
+            // Round inc to the nearest multiple of roundTo, and min
+            // to the next multiple of roundTo up. The small offset of
+            // eps is included to avoid inc of 2.49999999999 rounding
+            // to 2 or a min of -0.9999999999 rounding to 0, both of
+            // which would prevent some of our test cases from getting
+            // the most natural results.
+            double eps = 1e-8;
+            inc = round(inc / roundTo + eps) * roundTo;
             if (inc < roundTo) inc = roundTo;
-            min = ceil(min / roundTo) * roundTo;
+            min = ceil(min / roundTo - eps) * roundTo;
             if (min > r.max) min = r.max;
+            if (min == -0.0) min = 0.0;
+#ifdef DEBUG_SCALE_TICK_INTERVALS
+            SVDEBUG << "ScaleTickIntervals: rounded inc to " << inc
+                    << " and min to " << min << endl;
+#endif
         }
 
         if (display == Scientific && min != 0.0) {