comparison base/ScaleTickIntervals.h @ 1468:5f23274e21f9

Commit some extra debug, trying to narrow down Travis failure case
author Chris Cannam
date Thu, 17 May 2018 11:33:33 +0100
parents 5630df84d99f
children 1cc106bf601d
comparison
equal deleted inserted replaced
1467:5630df84d99f 1468:5f23274e21f9
22 22
23 #include "LogRange.h" 23 #include "LogRange.h"
24 #include "Debug.h" 24 #include "Debug.h"
25 25
26 // Can't have this on by default, as we're called on every refresh 26 // Can't have this on by default, as we're called on every refresh
27 //#define DEBUG_SCALE_TICK_INTERVALS 1 27 #define DEBUG_SCALE_TICK_INTERVALS 1
28 28
29 class ScaleTickIntervals 29 class ScaleTickIntervals
30 { 30 {
31 public: 31 public:
32 struct Range { 32 struct Range {
131 } else { 131 } else {
132 prec = precRange; 132 prec = precRange;
133 } 133 }
134 134
135 #ifdef DEBUG_SCALE_TICK_INTERVALS 135 #ifdef DEBUG_SCALE_TICK_INTERVALS
136 SVDEBUG << "ScaleTickIntervals: calculating linearInstruction" << endl 136 SVCERR << "ScaleTickIntervals: calculating linearInstruction" << endl
137 << "ScaleTickIntervals: min = " << r.min << ", max = " << r.max 137 << "ScaleTickIntervals: min = " << r.min << ", max = " << r.max
138 << ", n = " << r.n << ", inc = " << inc << endl; 138 << ", n = " << r.n << ", inc = " << inc << endl;
139 SVDEBUG << "ScaleTickIntervals: digMax = " << digMax 139 SVCERR << "ScaleTickIntervals: digMax = " << digMax
140 << ", digInc = " << digInc << endl; 140 << ", digInc = " << digInc << endl;
141 SVDEBUG << "ScaleTickIntervals: display = " << display 141 SVCERR << "ScaleTickIntervals: display = " << display
142 << ", inc = " << inc << ", precInc = " << precInc 142 << ", inc = " << inc << ", precInc = " << precInc
143 << ", precRange = " << precRange 143 << ", precRange = " << precRange
144 << ", prec = " << prec << ", roundTo = " << roundTo 144 << ", prec = " << prec << ", roundTo = " << roundTo
145 << endl; 145 << endl;
146 #endif 146 #endif
159 if (inc < roundTo) inc = roundTo; 159 if (inc < roundTo) inc = roundTo;
160 min = ceil(min / roundTo - eps) * roundTo; 160 min = ceil(min / roundTo - eps) * roundTo;
161 if (min > r.max) min = r.max; 161 if (min > r.max) min = r.max;
162 if (min == -0.0) min = 0.0; 162 if (min == -0.0) min = 0.0;
163 #ifdef DEBUG_SCALE_TICK_INTERVALS 163 #ifdef DEBUG_SCALE_TICK_INTERVALS
164 SVDEBUG << "ScaleTickIntervals: rounded inc to " << inc 164 SVCERR << "ScaleTickIntervals: rounded inc to " << inc
165 << " and min to " << min << endl; 165 << " and min to " << min << endl;
166 #endif 166 #endif
167 } 167 }
168 168
169 if (display == Scientific && min != 0.0) { 169 if (display == Scientific && min != 0.0) {
170 double digNewMin = log10(fabs(min)); 170 double digNewMin = log10(fabs(min));
171 if (digNewMin < digInc) { 171 if (digNewMin < digInc) {
172 prec = int(ceil(digMax - digNewMin)); 172 prec = int(ceil(digMax - digNewMin));
173 #ifdef DEBUG_SCALE_TICK_INTERVALS 173 #ifdef DEBUG_SCALE_TICK_INTERVALS
174 SVDEBUG << "ScaleTickIntervals: min is smaller than increment, adjusting prec to " << prec << endl; 174 SVCERR << "ScaleTickIntervals: min is smaller than increment, adjusting prec to " << prec << endl;
175 #endif 175 #endif
176 } 176 }
177 } 177 }
178 178
179 return { min, r.max, inc, roundTo, display, prec, false }; 179 return { min, r.max, inc, roundTo, display, prec, false };
182 static Instruction logInstruction(Range r) 182 static Instruction logInstruction(Range r)
183 { 183 {
184 Display display = Auto; 184 Display display = Auto;
185 185
186 #ifdef DEBUG_SCALE_TICK_INTERVALS 186 #ifdef DEBUG_SCALE_TICK_INTERVALS
187 SVDEBUG << "ScaleTickIntervals::logInstruction: Range is " 187 SVCERR << "ScaleTickIntervals::logInstruction: Range is "
188 << r.min << " to " << r.max << endl; 188 << r.min << " to " << r.max << endl;
189 #endif 189 #endif
190 190
191 if (r.n < 1) { 191 if (r.n < 1) {
192 return {}; 192 return {};
199 } 199 }
200 200
201 double inc = (r.max - r.min) / r.n; 201 double inc = (r.max - r.min) / r.n;
202 202
203 #ifdef DEBUG_SCALE_TICK_INTERVALS 203 #ifdef DEBUG_SCALE_TICK_INTERVALS
204 SVDEBUG << "ScaleTickIntervals::logInstruction: " 204 SVCERR << "ScaleTickIntervals::logInstruction: "
205 << "Naive increment is " << inc << endl; 205 << "Naive increment is " << inc << endl;
206 #endif 206 #endif
207 207
208 int precision = 1; 208 int precision = 1;
209 209
217 217
218 inc = round(inc / roundIncTo) * roundIncTo; 218 inc = round(inc / roundIncTo) * roundIncTo;
219 if (inc < roundIncTo) inc = roundIncTo; 219 if (inc < roundIncTo) inc = roundIncTo;
220 220
221 #ifdef DEBUG_SCALE_TICK_INTERVALS 221 #ifdef DEBUG_SCALE_TICK_INTERVALS
222 SVDEBUG << "ScaleTickIntervals::logInstruction: " 222 SVCERR << "ScaleTickIntervals::logInstruction: "
223 << "Rounded increment to " << inc << endl; 223 << "Rounded increment to " << inc << endl;
224 #endif 224 #endif
225 225
226 // if inc is close to giving us powers of two, nudge it 226 // if inc is close to giving us powers of two, nudge it
227 if (fabs(inc - 0.301) < 0.01) { 227 if (fabs(inc - 0.301) < 0.01) {
228 inc = log10(2.0); 228 inc = log10(2.0);
229 229
230 #ifdef DEBUG_SCALE_TICK_INTERVALS 230 #ifdef DEBUG_SCALE_TICK_INTERVALS
231 SVDEBUG << "ScaleTickIntervals::logInstruction: " 231 SVCERR << "ScaleTickIntervals::logInstruction: "
232 << "Nudged increment to " << inc << " to get powers of two" 232 << "Nudged increment to " << inc << " to get powers of two"
233 << endl; 233 << endl;
234 #endif 234 #endif
235 } 235 }
236 236
270 270
271 int digits = (value != 0.0 ? 271 int digits = (value != 0.0 ?
272 1 + int(floor(eps + log10(abs(value)))) : 272 1 + int(floor(eps + log10(abs(value)))) :
273 0); 273 0);
274 274
275 #ifdef DEBUG_SCALE_TICK_INTERVALS
276 SVCERR << "makeTick: display = Auto, precision = "
277 << precision << ", value = " << value
278 << ", resulting digits = " << digits << endl;
279 #endif
280
275 // This is not the same logic as %g uses for determining 281 // This is not the same logic as %g uses for determining
276 // whether to delegate to use scientific or fixed notation 282 // whether to delegate to use scientific or fixed notation
277 283
278 if (digits < -3 || digits > 4) { 284 if (digits < -3 || digits > 4) {
279 285
299 #pragma GCC diagnostic ignored "-Wformat-nonliteral" 305 #pragma GCC diagnostic ignored "-Wformat-nonliteral"
300 306
301 snprintf(buffer, buflen, spec, precision, value); 307 snprintf(buffer, buflen, spec, precision, value);
302 308
303 #ifdef DEBUG_SCALE_TICK_INTERVALS 309 #ifdef DEBUG_SCALE_TICK_INTERVALS
304 SVDEBUG << "makeTick: spec = \"" << spec 310 SVCERR << "makeTick: spec = \"" << spec
305 << "\", prec = " << precision << ", value = " << value 311 << "\", prec = " << precision << ", value = " << value
306 << ", label = \"" << buffer << "\"" << endl; 312 << ", label = \"" << buffer << "\"" << endl;
307 #endif 313 #endif
308 314
309 return Tick({ value, std::string(buffer) }); 315 return Tick({ value, std::string(buffer) });
310 } 316 }
311 317
312 static Ticks explode(Instruction instruction) { 318 static Ticks explode(Instruction instruction) {
313 319
314 #ifdef DEBUG_SCALE_TICK_INTERVALS 320 #ifdef DEBUG_SCALE_TICK_INTERVALS
315 SVDEBUG << "ScaleTickIntervals::explode:" << endl 321 SVCERR << "ScaleTickIntervals::explode:" << endl
316 << "initial = " << instruction.initial 322 << "initial = " << instruction.initial
317 << ", limit = " << instruction.limit 323 << ", limit = " << instruction.limit
318 << ", spacing = " << instruction.spacing 324 << ", spacing = " << instruction.spacing
319 << ", roundTo = " << instruction.roundTo 325 << ", roundTo = " << instruction.roundTo
320 << ", display = " << instruction.display 326 << ", display = " << instruction.display