Engauge Digitizer  2
ExportAlignLinear.cpp
1 #include "EngaugeAssert.h"
2 #include "ExportAlignLinear.h"
3 #include <qmath.h>
4 
5 const double EPSILON = 0.000001;
6 
8  double xMax)
9 {
10  ENGAUGE_ASSERT (xMin <= xMax);
11 
12  // Start with digit N=1, then keep adding to that digit until:
13  // 1) number is between xMin and xMax in which case that value is the result
14  // 2) number exceeds xMax in which case digit N+1 is added and this repeats
15  double powerOf10 = qPow (10.0, (int) (log10 (qAbs (xMin)) + EPSILON));
16  int firstDigit = (int) (xMin / powerOf10);
17  double digitsCurrent = firstDigit * powerOf10; // May or may not be less than xMax
18  while (digitsCurrent > xMin) {
19  digitsCurrent -= powerOf10; // Go backwards until less than xMin. Required only if xMin < 0
20  }
21  double digitsHighestUnderXMin = digitsCurrent;
22  do {
23  digitsCurrent = digitsHighestUnderXMin; // Go back to highest value so far less than xMin
24  while (digitsCurrent < xMin) {
25  digitsCurrent += powerOf10;
26 
27  if (digitsCurrent < xMin) {
28  digitsHighestUnderXMin = digitsCurrent;
29  }
30  }
31  powerOf10 /= 10.0;
32  } while (digitsCurrent > xMax);
33 
34  m_firstSimplestNumber = digitsCurrent;
35 }
36 
38 {
39  return m_firstSimplestNumber;
40 }
41 
42 double ExportAlignLinear::log10 (double in) const
43 {
44  return qLn (in) / qLn (10.0);
45 }
ExportAlignLinear(double xMin, double xMax)
Single constructor.
double firstSimplestNumber() const
Result.