Engauge Digitizer  2
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 
19  // Measure the resolution if the point is moved some number of pixels in screen coordinates
20  QPointF posGraph;
21  if (isXTheta) {
22 
23  posGraph = QPointF (valueUnformatted,
24  valueUnformattedOther);
25 
26  } else {
27 
28  posGraph = QPointF (valueUnformattedOther,
29  valueUnformatted);
30 
31  }
32 
33  QPointF posScreen, posScreenShifted, posGraphShifted;
34 
35  transformation.transformRawGraphToScreen (posGraph,
36  posScreen);
37 
38  posScreenShifted = posScreen + QPointF (PIXEL_SHIFT, PIXEL_SHIFT);
39 
40  transformation.transformScreenToRawGraph (posScreenShifted,
41  posGraphShifted);
42 
43  double xResolutionPerPixel = (posGraphShifted.x() - posGraph.x()) / PIXEL_SHIFT;
44  double yResolutionPerPixel = (posGraphShifted.y() - posGraph.y()) / PIXEL_SHIFT;
45  double resolutionPerPixel = (isXTheta ? xResolutionPerPixel : yResolutionPerPixel);
46 
47  // Compute number of digits ahead of the decimal point (any single decimal place would work but the decimal point is easiest)
48  int powerValue = qFloor (qLn (qAbs (valueUnformatted)) / qLn (10.0));
49  int powerResolution = qFloor (qLn (qAbs (resolutionPerPixel)) / qLn (10.0));
50 
51  int numberDigitsForResolution = powerValue - powerResolution + 1;
52 
53  return numberDigitsForResolution + 1; // Add one just to be safe
54 }
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...
void transformRawGraphToScreen(const QPointF &pointRaw, QPointF &pointScreen) const
Transform from raw graph coordinates to linear cartesian graph coordinates, then to screen coordinate...