Engauge Digitizer  2
 All Classes Files Functions Variables Enumerations Enumerator Friends Pages
FormatCoordsUnitsStrategyAbstractBase.cpp
1 #include "FormatCoordsUnitsStrategyAbstractBase.h"
2 #include "Logger.h"
3 #include <qmath.h>
4 #include "Transformation.h"
5 
7 {
8 }
9 
11  double valueUnformattedOther,
12  bool isXTheta,
13  const Transformation &transformation) const
14 {
15  LOG4CPP_DEBUG_S ((*mainCat)) << "FormatCoordsUnitsStrategyAbstractBase::precisionDigitsForRawNumber";
16 
17  const double PIXEL_SHIFT = 1;
18  const int DEFAULT_PRECISION = 5; // Precision used before transformation is available. Equal or greater than x/y pixel counts
19 
20  if (transformation.transformIsDefined()) {
21 
22  // Measure the resolution if the point is moved some number of pixels in screen coordinates
23  QPointF posGraph;
24  if (isXTheta) {
25 
26  posGraph = QPointF (valueUnformatted,
27  valueUnformattedOther);
28 
29  } else {
30 
31  posGraph = QPointF (valueUnformattedOther,
32  valueUnformatted);
33 
34  }
35 
36  QPointF posScreen, posScreenShifted, posGraphShifted;
37 
38  transformation.transformRawGraphToScreen (posGraph,
39  posScreen);
40 
41  posScreenShifted = posScreen + QPointF (PIXEL_SHIFT, PIXEL_SHIFT);
42 
43  transformation.transformScreenToRawGraph (posScreenShifted,
44  posGraphShifted);
45 
46  double xResolutionPerPixel = (posGraphShifted.x() - posGraph.x()) / PIXEL_SHIFT;
47  double yResolutionPerPixel = (posGraphShifted.y() - posGraph.y()) / PIXEL_SHIFT;
48  double resolutionPerPixel = (isXTheta ? xResolutionPerPixel : yResolutionPerPixel);
49 
50  // Compute number of digits ahead of the decimal point (any single decimal place would work but the decimal point is easiest)
51  int powerValue = qFloor (qLn (qAbs (valueUnformatted)) / qLn (10.0));
52  int powerResolution = qFloor (qLn (qAbs (resolutionPerPixel)) / qLn (10.0));
53 
54  int numberDigitsForResolution = powerValue - powerResolution + 1;
55 
56  return numberDigitsForResolution + 1; // Add one just to be safe
57 
58  } else {
59 
60  return DEFAULT_PRECISION;
61  }
62 }
void transformScreenToRawGraph(const QPointF &coordScreen, QPointF &coordGraph) const
Transform from cartesian pixel screen coordinates to cartesian/polar graph coordinates.
Affine transformation between screen and graph coordinates, based on digitized axis points...
int precisionDigitsForRawNumber(double valueUnformatted, double valueUnformattedOther, bool isXTheta, const Transformation &transformation) const
Compute precision for outputting an unformatted value, consistent with the resolution at the point wh...
bool transformIsDefined() const
Transform is defined when at least three axis points have been digitized.
void transformRawGraphToScreen(const QPointF &pointRaw, QPointF &pointScreen) const
Transform from raw graph coordinates to linear cartesian graph coordinates, then to screen coordinate...