Engauge Digitizer
2
Toggle main menu visibility
Loading...
Searching...
No Matches
Format
FormatCoordsUnitsStrategyAbstractBase.cpp
Go to the documentation of this file.
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 "
DocumentModelGeneral.h
"
8
#include "
FormatCoordsUnitsStrategyAbstractBase.h
"
9
#include "
Logger.h
"
10
#include <qmath.h>
11
#include "
Transformation.h
"
12
13
FormatCoordsUnitsStrategyAbstractBase::FormatCoordsUnitsStrategyAbstractBase
()
14
{
15
}
16
17
int
FormatCoordsUnitsStrategyAbstractBase::precisionDigitsForRawNumber
(
double
valueUnformatted,
18
double
valueUnformattedOther,
19
bool
isXTheta,
20
const
DocumentModelGeneral
&modelGeneral,
21
const
Transformation
&transformation)
const
22
{
23
//qCDebug(ENGAUGE_LOG) << "FormatCoordsUnitsStrategyAbstractBase::precisionDigitsForRawNumber";
24
25
const
double
PIXEL_SHIFT = 1;
26
const
int
DEFAULT_PRECISION = 5;
// Precision used before transformation is available. Equal or greater than x/y pixel counts
27
28
if
(transformation.
transformIsDefined
()) {
29
30
// Measure the resolution if the point is moved some number of pixels in screen coordinates
31
QPointF posGraph;
32
if
(isXTheta) {
33
34
posGraph = QPointF (valueUnformatted,
35
valueUnformattedOther);
36
37
}
else
{
38
39
posGraph = QPointF (valueUnformattedOther,
40
valueUnformatted);
41
42
}
43
44
QPointF posScreen, posScreenShifted, posGraphShifted;
45
46
transformation.
transformRawGraphToScreen
(posGraph,
47
posScreen);
48
49
posScreenShifted = posScreen + QPointF (PIXEL_SHIFT, PIXEL_SHIFT);
50
51
transformation.
transformScreenToRawGraph
(posScreenShifted,
52
posGraphShifted);
53
54
double
xResolutionPerPixel = (posGraphShifted.x() - posGraph.x()) / PIXEL_SHIFT;
55
double
yResolutionPerPixel = (posGraphShifted.y() - posGraph.y()) / PIXEL_SHIFT;
56
double
resolutionPerPixel = (isXTheta ? xResolutionPerPixel : yResolutionPerPixel);
57
58
// Compute number of digits ahead of the decimal point (any single decimal place would work but the decimal point is easiest)
59
int
powerValue = qFloor (qLn (qAbs (valueUnformatted)) / qLn (10.0));
60
int
powerResolution = qFloor (qLn (qAbs (resolutionPerPixel)) / qLn (10.0));
61
62
int
numberDigitsForResolution = powerValue - powerResolution + 1 + modelGeneral.
extraPrecision
();
63
64
return
numberDigitsForResolution + 1;
// Add one just to be safe
65
66
}
else
{
67
68
return
DEFAULT_PRECISION;
69
}
70
}
DocumentModelGeneral.h
FormatCoordsUnitsStrategyAbstractBase.h
Logger.h
Transformation.h
DocumentModelGeneral
Model for DlgSettingsGeneral and CmdSettingsGeneral.
Definition
DocumentModelGeneral.h:17
DocumentModelGeneral::extraPrecision
int extraPrecision() const
Get method for extra digits of precsion.
Definition
DocumentModelGeneral.cpp:61
FormatCoordsUnitsStrategyAbstractBase::precisionDigitsForRawNumber
int precisionDigitsForRawNumber(double valueUnformatted, double valueUnformattedOther, bool isXTheta, const DocumentModelGeneral &modelGeneral, const Transformation &transformation) const
Compute precision for outputting an unformatted value, consistent with the resolution at the point wh...
Definition
FormatCoordsUnitsStrategyAbstractBase.cpp:17
FormatCoordsUnitsStrategyAbstractBase::FormatCoordsUnitsStrategyAbstractBase
FormatCoordsUnitsStrategyAbstractBase()
Single constructor.
Definition
FormatCoordsUnitsStrategyAbstractBase.cpp:13
Transformation
Affine transformation between screen and graph coordinates, based on digitized axis points.
Definition
Transformation.h:32
Transformation::transformRawGraphToScreen
void transformRawGraphToScreen(const QPointF &pointRaw, QPointF &pointScreen) const
Transform from raw graph coordinates to linear cartesian graph coordinates, then to screen coordinate...
Definition
Transformation.cpp:446
Transformation::transformScreenToRawGraph
void transformScreenToRawGraph(const QPointF &coordScreen, QPointF &coordGraph) const
Transform from cartesian pixel screen coordinates to cartesian/polar graph coordinates.
Definition
Transformation.cpp:465
Transformation::transformIsDefined
bool transformIsDefined() const
Transform is defined when at least three axis points have been digitized.
Definition
Transformation.cpp:347
Generated on
for Engauge Digitizer by
1.17.0