Mercurial > hg > svcore
comparison base/ScaleTickIntervals.h @ 1419:e7e626a87a1e scale-ticks
SVDEBUG, though it turns out not to be very useful
author | Chris Cannam |
---|---|
date | Thu, 04 May 2017 19:20:24 +0100 |
parents | e7cb4fb2aee4 |
children | 8b7d6c1e1ab7 91001e2bb96a |
comparison
equal
deleted
inserted
replaced
1418:e7cb4fb2aee4 | 1419:e7e626a87a1e |
---|---|
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 | |
24 | |
25 #ifdef DEBUG_SCALE_TICK_INTERVALS | |
26 #include <iostream> | |
27 #endif | |
28 | |
29 #include "LogRange.h" | 23 #include "LogRange.h" |
24 #include "Debug.h" | |
25 | |
26 // Can't have this on by default, as we're called on every refresh | |
27 //#define DEBUG_SCALE_TICK_INTERVALS 1 | |
30 | 28 |
31 class ScaleTickIntervals | 29 class ScaleTickIntervals |
32 { | 30 { |
33 public: | 31 public: |
34 struct Range { | 32 struct Range { |
132 } else { | 130 } else { |
133 prec = precRange; | 131 prec = precRange; |
134 } | 132 } |
135 | 133 |
136 #ifdef DEBUG_SCALE_TICK_INTERVALS | 134 #ifdef DEBUG_SCALE_TICK_INTERVALS |
137 std::cerr << "\nmin = " << r.min << ", max = " << r.max << ", n = " << r.n | 135 SVDEBUG << "ScaleTickIntervals: calculating linearInstruction" << endl |
138 << ", inc = " << inc << std::endl; | 136 << "ScaleTickIntervals: min = " << r.min << ", max = " << r.max |
139 std::cerr << "digMax = " << digMax << ", digInc = " << digInc | 137 << ", n = " << r.n << ", inc = " << inc << endl; |
140 << std::endl; | 138 SVDEBUG << "ScaleTickIntervals: digMax = " << digMax |
141 std::cerr << "display = " << display << ", inc = " << inc | 139 << ", digInc = " << digInc << endl; |
142 << ", precInc = " << precInc << ", precRange = " << precRange | 140 SVDEBUG << "ScaleTickIntervals: display = " << display |
143 << ", prec = " << prec << std::endl; | 141 << ", inc = " << inc << ", precInc = " << precInc |
144 std::cerr << "roundTo = " << roundTo << std::endl; | 142 << ", precRange = " << precRange |
143 << ", prec = " << prec << ", roundTo = " << roundTo | |
144 << endl; | |
145 #endif | 145 #endif |
146 | 146 |
147 double min = r.min; | 147 double min = r.min; |
148 | 148 |
149 if (roundTo != 0.0) { | 149 if (roundTo != 0.0) { |
156 if (display == Scientific && min != 0.0) { | 156 if (display == Scientific && min != 0.0) { |
157 double digNewMin = log10(fabs(min)); | 157 double digNewMin = log10(fabs(min)); |
158 if (digNewMin < digInc) { | 158 if (digNewMin < digInc) { |
159 prec = int(ceil(digMax - digNewMin)); | 159 prec = int(ceil(digMax - digNewMin)); |
160 #ifdef DEBUG_SCALE_TICK_INTERVALS | 160 #ifdef DEBUG_SCALE_TICK_INTERVALS |
161 std::cerr << "min is smaller than increment, adjusting prec to " | 161 SVDEBUG << "ScaleTickIntervals: min is smaller than increment, adjusting prec to " << prec << endl; |
162 << prec << std::endl; | |
163 #endif | 162 #endif |
164 } | 163 } |
165 } | 164 } |
166 | 165 |
167 return { min, r.max, inc, roundTo, display, prec, false }; | 166 return { min, r.max, inc, roundTo, display, prec, false }; |
211 if (r.max >= -2.0 && r.max <= 3.0 && | 210 if (r.max >= -2.0 && r.max <= 3.0 && |
212 r.min >= -3.0 && r.min <= 3.0) { | 211 r.min >= -3.0 && r.min <= 3.0) { |
213 display = Fixed; | 212 display = Fixed; |
214 if (prec == 0) prec = 1; | 213 if (prec == 0) prec = 1; |
215 } | 214 } |
216 | 215 |
217 #ifdef DEBUG_SCALE_TICK_INTERVALS | 216 #ifdef DEBUG_SCALE_TICK_INTERVALS |
218 std::cerr << "\nmin = " << r.min << ", max = " << r.max << ", n = " << r.n | 217 SVDEBUG << "ScaleTickIntervals: calculating logInstruction" << endl |
219 << ", inc = " << inc << ", minDispInc = " << minDispInc | 218 << "ScaleTickIntervals: min = " << r.min << ", max = " << r.max |
220 << ", digInc = " << digInc << std::endl; | 219 << ", n = " << r.n << ", inc = " << inc |
221 std::cerr << "display = " << display << ", inc = " << inc | 220 << ", minDispInc = " << minDispInc << ", digInc = " << digInc |
222 << ", precInc = " << precInc | 221 << endl; |
223 << ", prec = " << prec << std::endl; | 222 SVDEBUG << "ScaleTickIntervals: display = " << display |
224 std::cerr << "roundTo = " << roundTo << std::endl; | 223 << ", inc = " << inc << ", precInc = " << precInc |
224 << ", prec = " << prec << endl; | |
225 SVDEBUG << "ScaleTickIntervals: roundTo = " << roundTo << endl; | |
225 #endif | 226 #endif |
226 | 227 |
227 double min = r.min; | 228 double min = r.min; |
228 if (inc != 0.0) { | 229 if (inc != 0.0) { |
229 min = ceil(r.min / inc) * inc; | 230 min = ceil(r.min / inc) * inc; |
257 } | 258 } |
258 | 259 |
259 static Ticks explode(Instruction instruction) { | 260 static Ticks explode(Instruction instruction) { |
260 | 261 |
261 #ifdef DEBUG_SCALE_TICK_INTERVALS | 262 #ifdef DEBUG_SCALE_TICK_INTERVALS |
262 std::cerr << "initial = " << instruction.initial | 263 SVDEBUG << "ScaleTickIntervals::explode:" << endl |
263 << ", limit = " << instruction.limit | 264 << "initial = " << instruction.initial |
264 << ", spacing = " << instruction.spacing | 265 << ", limit = " << instruction.limit |
265 << ", roundTo = " << instruction.roundTo | 266 << ", spacing = " << instruction.spacing |
266 << ", display = " << instruction.display | 267 << ", roundTo = " << instruction.roundTo |
267 << ", precision = " << instruction.precision | 268 << ", display = " << instruction.display |
268 << ", logUnmap = " << instruction.logUnmap | 269 << ", precision = " << instruction.precision |
269 << std::endl; | 270 << ", logUnmap = " << instruction.logUnmap |
271 << endl; | |
270 #endif | 272 #endif |
271 | 273 |
272 if (instruction.spacing == 0.0) { | 274 if (instruction.spacing == 0.0) { |
273 return {}; | 275 return {}; |
274 } | 276 } |