comparison layer/LogNumericalScale.cpp @ 904:e0f08e108064 cxx11

Move to using double rather than float for floating-point calculations (float only for storage); more build fixes
author Chris Cannam
date Mon, 09 Mar 2015 12:02:10 +0000
parents 3ca3b8fbbcee
children b66fb15de477
comparison
equal deleted inserted replaced
903:1757933ce5a7 904:e0f08e108064
36 void 36 void
37 LogNumericalScale::paintVertical(View *v, 37 LogNumericalScale::paintVertical(View *v,
38 const VerticalScaleLayer *layer, 38 const VerticalScaleLayer *layer,
39 QPainter &paint, 39 QPainter &paint,
40 int x0, 40 int x0,
41 float minlog, 41 double minlog,
42 float maxlog) 42 double maxlog)
43 { 43 {
44 int w = getWidth(v, paint) + x0; 44 int w = getWidth(v, paint) + x0;
45 45
46 int n = 10; 46 int n = 10;
47 47
48 float val = minlog; 48 double val = minlog;
49 float inc = (maxlog - val) / n; // even increments of log scale 49 double inc = (maxlog - val) / n; // even increments of log scale
50 50
51 // smallest increment as displayed 51 // smallest increment as displayed
52 float minDispInc = LogRange::unmap(minlog + inc) - LogRange::unmap(minlog); 52 double minDispInc = LogRange::unmap(minlog + inc) - LogRange::unmap(minlog);
53 53
54 #ifdef DEBUG_TIME_VALUE_LAYER 54 #ifdef DEBUG_TIME_VALUE_LAYER
55 cerr << "min = " << minlog << ", max = " << maxlog << ", inc = " << inc << ", minDispInc = " << minDispInc << endl; 55 cerr << "min = " << minlog << ", max = " << maxlog << ", inc = " << inc << ", minDispInc = " << minDispInc << endl;
56 #endif 56 #endif
57 57
58 const int buflen = 40; 58 const int buflen = 40;
59 char buffer[buflen]; 59 char buffer[buflen];
60 60
61 float round = 1.f; 61 double round = 1.f;
62 int dp = 0; 62 int dp = 0;
63 63
64 if (minDispInc > 0) { 64 if (minDispInc > 0) {
65 int prec = trunc(log10f(minDispInc)); 65 int prec = trunc(log10f(minDispInc));
66 if (prec < 0) dp = -prec; 66 if (prec < 0) dp = -prec;
81 if (i == n-1 && 81 if (i == n-1 &&
82 v->height() < paint.fontMetrics().height() * (n*2)) { 82 v->height() < paint.fontMetrics().height() * (n*2)) {
83 if (layer->getScaleUnits() != "") drawText = false; 83 if (layer->getScaleUnits() != "") drawText = false;
84 } 84 }
85 85
86 float dispval = LogRange::unmap(val); 86 double dispval = LogRange::unmap(val);
87 dispval = floor(dispval / round) * round; 87 dispval = floor(dispval / round) * round;
88 88
89 #ifdef DEBUG_TIME_VALUE_LAYER 89 #ifdef DEBUG_TIME_VALUE_LAYER
90 cerr << "val = " << val << ", dispval = " << dispval << endl; 90 cerr << "val = " << val << ", dispval = " << dispval << endl;
91 #endif 91 #endif