Engauge Digitizer 2
Loading...
Searching...
No Matches
GridLineNormalize.cpp
Go to the documentation of this file.
1/******************************************************************************************************
2 * (C) 2021 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 "GridLineNormalize.h"
8#include "MainWindowModel.h"
9#include <qmath.h>
10
12 m_maximumGridLines (modelMainWindow.maximumGridLines())
13{
14}
15
19
20void GridLineNormalize::normalize (bool isLinear,
21 GridCoordDisable disable,
22 double &start,
23 double &step,
24 double &stop,
25 unsigned int &num) const
26{
27 // Make sure we are not using any disabled parameters
28
29 double numMinus1 = qMax (1.0, num - 1.0);
30
31 if (isLinear) {
32
33 // Linear case
34 if (disable == GRID_COORD_DISABLE_START) {
35 start = stop - numMinus1 * step;
36 } else if (disable == GRID_COORD_DISABLE_STEP) {
37 step = (stop - start) / numMinus1;
38 } else if (disable == GRID_COORD_DISABLE_STOP) {
39 stop = start + numMinus1 * step;
40 } else if (disable == GRID_COORD_DISABLE_COUNT) {
41 if (qAbs (step) * m_maximumGridLines < qAbs (stop - start)) {
42 num = m_maximumGridLines;
43 } else {
44 num = qFloor (0.5 + 1.0 + (stop - start) / step);
45 }
46 }
47 } else {
48
49 // Log case
50 if (disable == GRID_COORD_DISABLE_START) {
51 start = stop / qPow (step, numMinus1);
52 } else if (disable == GRID_COORD_DISABLE_STEP) {
53 step = qExp (qLn (stop / start) / numMinus1);
54 } else if (disable == GRID_COORD_DISABLE_STOP) {
55 stop = start * qPow (step, numMinus1);
56 } else if (disable == GRID_COORD_DISABLE_COUNT) {
57 if (start <= 0.0 || step <= 0.0 || stop <= 0.) {
58 num = 2;
59 } else if (qAbs (qLn (step)) * m_maximumGridLines < qAbs (qLn (stop / start))) {
60 num = m_maximumGridLines;
61 } else {
62 num = qFloor (0.5 + 1.0 + qLn (stop / start) / qLn (step));
63 }
64 }
65 }
66}
GridCoordDisable
@ GRID_COORD_DISABLE_STOP
@ GRID_COORD_DISABLE_START
@ GRID_COORD_DISABLE_STEP
@ GRID_COORD_DISABLE_COUNT
GridLineNormalize(const MainWindowModel &modelMainWindow)
Default constructor.
void normalize(bool isLinear, GridCoordDisable disable, double &start, double &step, double &stop, unsigned int &num) const
Normalize the quartet of grid line parameters by adjusting the disabled one to achieve consistency.
Model for DlgSettingsMainWindow.