Mercurial > hg > svcore
comparison 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 |
comparison
equal
deleted
inserted
replaced
1411:1f0d071e7ce6 | 1412:b7a9edee85e0 |
---|---|
18 | 18 |
19 #include <string> | 19 #include <string> |
20 #include <vector> | 20 #include <vector> |
21 #include <cmath> | 21 #include <cmath> |
22 | 22 |
23 //#define DEBUG_SCALE_TICK_INTERVALS 1 | 23 #define DEBUG_SCALE_TICK_INTERVALS 1 |
24 | 24 |
25 #ifdef DEBUG_SCALE_TICK_INTERVALS | 25 #ifdef DEBUG_SCALE_TICK_INTERVALS |
26 #include <iostream> | 26 #include <iostream> |
27 #endif | 27 #endif |
28 | 28 |
30 { | 30 { |
31 public: | 31 public: |
32 struct Range { | 32 struct Range { |
33 double min; // start of value range | 33 double min; // start of value range |
34 double max; // end of value range | 34 double max; // end of value range |
35 int n; // number of divisions (will be at most n+1 ticks) | 35 int n; // number of divisions (approximate only) |
36 }; | 36 }; |
37 | 37 |
38 struct Tick { | 38 struct Tick { |
39 double value; // value this tick represents | 39 double value; // value this tick represents |
40 std::string label; // value as written | 40 std::string label; // value as written |
144 }; | 144 }; |
145 double eps = 1e-7; | 145 double eps = 1e-7; |
146 if (t.spacing < eps * 10.0) { | 146 if (t.spacing < eps * 10.0) { |
147 eps = t.spacing / 10.0; | 147 eps = t.spacing / 10.0; |
148 } | 148 } |
149 for (double value = t.initial; value < r.max + eps; value += t.spacing) { | 149 int n = 0; |
150 while (true) { | |
151 double value = t.initial + n * t.spacing; | |
150 value = t.roundTo * round(value / t.roundTo); | 152 value = t.roundTo * round(value / t.roundTo); |
153 if (value >= r.max + eps) { | |
154 break; | |
155 } | |
151 t.ticks.push_back(makeTick(value)); | 156 t.ticks.push_back(makeTick(value)); |
157 ++n; | |
152 } | 158 } |
153 } | 159 } |
154 }; | 160 }; |
155 | 161 |
156 #endif | 162 #endif |