# HG changeset patch # User Chris Cannam # Date 1493884380 -3600 # Node ID c6fa111b4553fe8b67c0544ffb185ecba889ade2 # Parent b7a9edee85e0a66cfa119c912dbf6bc1679d5753 Tests now passing diff -r b7a9edee85e0 -r c6fa111b4553 base/ScaleTickIntervals.h --- a/base/ScaleTickIntervals.h Thu May 04 08:32:41 2017 +0100 +++ b/base/ScaleTickIntervals.h Thu May 04 08:53:00 2017 +0100 @@ -20,7 +20,7 @@ #include #include -#define DEBUG_SCALE_TICK_INTERVALS 1 +//#define DEBUG_SCALE_TICK_INTERVALS 1 #ifdef DEBUG_SCALE_TICK_INTERVALS #include @@ -122,6 +122,17 @@ double min = ceil(r.min / roundTo) * roundTo; if (min > r.max) min = r.max; + if (!fixed && min != 0.0) { + double digNewMin = log10(fabs(min)); + if (digNewMin < digInc) { + prec = int(ceil(digMax - digNewMin)); +#ifdef DEBUG_SCALE_TICK_INTERVALS + std::cerr << "min is smaller than increment, adjusting prec to " + << prec << std::endl; +#endif + } + } + Ticks t { min, inc, roundTo, fixed, prec, {} }; explode(r, t); return t; diff -r b7a9edee85e0 -r c6fa111b4553 base/test/TestScaleTickIntervals.h --- a/base/test/TestScaleTickIntervals.h Thu May 04 08:32:41 2017 +0100 +++ b/base/test/TestScaleTickIntervals.h Thu May 04 08:53:00 2017 +0100 @@ -229,6 +229,19 @@ compareTicks(ticks.ticks, expected); } + void linear_0p001_1_5() + { + auto ticks = ScaleTickIntervals::linear({ 0.001, 1, 5 }); + vector expected { + { 0.1, "0.1" }, + { 0.3, "0.3" }, + { 0.5, "0.5" }, + { 0.7, "0.7" }, + { 0.9, "0.9" }, + }; + compareTicks(ticks.ticks, expected); + } + void linear_10000_10010_5() { auto ticks = ScaleTickIntervals::linear({ 10000, 10010, 5 }); @@ -313,13 +326,13 @@ { auto ticks = ScaleTickIntervals::linear({ M_PI, 6.022140857e23, 7 }); vector expected { - { 1e+21, "1.0e+21" }, - { 8.7e+22, "8.7e+22" }, - { 1.73e+23, "1.73e+23" }, - { 2.59e+23, "2.59e+23" }, - { 3.45e+23, "3.45e+23" }, - { 4.31e+23, "4.31e+23" }, - { 5.17e+23, "5.17e+23" }, + { 1e+21, "1.000e+21" }, + { 8.7e+22, "8.700e+22" }, + { 1.73e+23, "1.730e+23" }, + { 2.59e+23, "2.590e+23" }, + { 3.45e+23, "3.450e+23" }, + { 4.31e+23, "4.310e+23" }, + { 5.17e+23, "5.170e+23" }, }; compareTicks(ticks.ticks, expected); }