Engauge Digitizer 2
Loading...
Searching...
No Matches
ExportAlignLinear.cpp
1/******************************************************************************************************
2 * (C) 2014 markummitchell@github.com. This file is part of Engauge Digitizer, which is released *
3 * under GNU General Public License version 2 (GPLv2) or (at your option) any later version. See file *
4 * LICENSE or go to gnu.org/licenses for details. Distribution requires prior written permission. *
5 ******************************************************************************************************/
6
7#include "EngaugeAssert.h"
8#include "ExportAlignLinear.h"
9#include <qmath.h>
10
11const double EPSILON = 0.000001;
12
14 double xMax)
15{
16 ENGAUGE_ASSERT (xMin <= xMax);
17
18 // Start with digit N=1, then keep adding to that digit until:
19 // 1) number is between xMin and xMax in which case that value is the result
20 // 2) number exceeds xMax in which case digit N+1 is added and this repeats
21 double powerOf10 = qPow (10.0, (int) (log10 (qAbs (xMin)) + EPSILON));
22 int firstDigit = (int) (xMin / powerOf10);
23 double digitsCurrent = firstDigit * powerOf10; // May or may not be less than xMax
24 while (digitsCurrent > xMin) {
25 digitsCurrent -= powerOf10; // Go backwards until less than xMin. Required only if xMin < 0
26 }
27 double digitsHighestUnderXMin = digitsCurrent;
28 do {
29 digitsCurrent = digitsHighestUnderXMin; // Go back to highest value so far less than xMin
30 while (digitsCurrent < xMin) {
31 digitsCurrent += powerOf10;
32
33 if (digitsCurrent < xMin) {
34 digitsHighestUnderXMin = digitsCurrent;
35 }
36 }
37 powerOf10 /= 10.0;
38 } while (digitsCurrent > xMax);
39
40 m_firstSimplestNumber = digitsCurrent;
41}
42
44{
45 return m_firstSimplestNumber;
46}
47
48double ExportAlignLinear::log10 (double in) const
49{
50 return qLn (in) / qLn (10.0);
51}
double firstSimplestNumber() const
Result.
ExportAlignLinear(double xMin, double xMax)
Single constructor.