00001
00002
00003
00004
00005
00006
00007 #include "FormatCoordsUnitsStrategyAbstractBase.h"
00008 #include "Logger.h"
00009 #include <qmath.h>
00010 #include "Transformation.h"
00011
00012 FormatCoordsUnitsStrategyAbstractBase::FormatCoordsUnitsStrategyAbstractBase ()
00013 {
00014 }
00015
00016 int FormatCoordsUnitsStrategyAbstractBase::precisionDigitsForRawNumber (double valueUnformatted,
00017 double valueUnformattedOther,
00018 bool isXTheta,
00019 const Transformation &transformation) const
00020 {
00021 LOG4CPP_DEBUG_S ((*mainCat)) << "FormatCoordsUnitsStrategyAbstractBase::precisionDigitsForRawNumber";
00022
00023 const double PIXEL_SHIFT = 1;
00024 const int DEFAULT_PRECISION = 5;
00025
00026 if (transformation.transformIsDefined()) {
00027
00028
00029 QPointF posGraph;
00030 if (isXTheta) {
00031
00032 posGraph = QPointF (valueUnformatted,
00033 valueUnformattedOther);
00034
00035 } else {
00036
00037 posGraph = QPointF (valueUnformattedOther,
00038 valueUnformatted);
00039
00040 }
00041
00042 QPointF posScreen, posScreenShifted, posGraphShifted;
00043
00044 transformation.transformRawGraphToScreen (posGraph,
00045 posScreen);
00046
00047 posScreenShifted = posScreen + QPointF (PIXEL_SHIFT, PIXEL_SHIFT);
00048
00049 transformation.transformScreenToRawGraph (posScreenShifted,
00050 posGraphShifted);
00051
00052 double xResolutionPerPixel = (posGraphShifted.x() - posGraph.x()) / PIXEL_SHIFT;
00053 double yResolutionPerPixel = (posGraphShifted.y() - posGraph.y()) / PIXEL_SHIFT;
00054 double resolutionPerPixel = (isXTheta ? xResolutionPerPixel : yResolutionPerPixel);
00055
00056
00057 int powerValue = qFloor (qLn (qAbs (valueUnformatted)) / qLn (10.0));
00058 int powerResolution = qFloor (qLn (qAbs (resolutionPerPixel)) / qLn (10.0));
00059
00060 int numberDigitsForResolution = powerValue - powerResolution + 1;
00061
00062 return numberDigitsForResolution + 1;
00063
00064 } else {
00065
00066 return DEFAULT_PRECISION;
00067 }
00068 }