1 #include "DocumentModelCoords.h"
2 #include "EngaugeAssert.h"
3 #include "GridInitializer.h"
7 #include "Transformation.h"
13 void GridInitializer::axisScale (
double xMin,
21 const double range_epsilon = 0.00000000001;
22 double xAverage, xAverageRoundedUp, xRange;
29 const int nDigitsPrecision = 8;
40 ENGAUGE_ASSERT(xMin > 0);
41 ENGAUGE_ASSERT(xMax > 0);
47 xAverage = (xMin + xMax) / 2.0;
50 xRange = fabs (xAverage / 10.0);
53 xDelta = pow ((
double) 10.0, (
double) nDigitRange);
54 xAverageRoundedUp = xDelta * floor ((xAverage + xDelta / 2.0) / xDelta);
56 if (xRange > range_epsilon) {
58 while (fabs (xRange / xDelta) <= 2.000001) {
64 xStart = xAverageRoundedUp;
65 while (xStart > xMin) {
70 xStop = xAverageRoundedUp;
71 while (xStop < xMax) {
75 xCount = 1 + (int) floor ((xStop - xStart) / xDelta + 0.5);
80 xStart = pow((
double) 10.0, xStart);
81 xStop = pow((
double) 10.0, xStop);
82 xDelta = pow((
double) 10.0, xDelta);
87 int power =
valuePower (xDelta) - nDigitsPrecision;
88 xStart = roundOffToPower(xStart, power);
89 xStop = roundOffToPower(xStop, power);
90 xDelta = roundOffToPower(xDelta, power);
106 count = (int) (1.0 + (stop - start) / step);
109 if ((start <= 0) || (step <= 0.0)) {
112 count = (int) (1.0 + log10 (stop / start) / log10 (step));
127 start = stop - step * (count - 1);
129 start = stop / pow (step, (
double) (count - 1));
144 step = (stop - start) / (count - 1);
153 step = pow (stop / start, (
double) 1.0 / (count - 1));
171 stop = start + step * (count - 1);
173 stop = start * pow (step, (
double) (count - 1));
182 LOG4CPP_INFO_S ((*mainCat)) <<
"GridInitializer::initializeWithNarrowCoverage";
187 double start, stop, step;
190 axisScale (boundingRectGraph.x(),
191 boundingRectGraph.x() + boundingRectGraph.width(),
198 modelGridDisplay.
setDisableX (GRID_COORD_DISABLE_COUNT);
205 axisScale (boundingRectGraph.y(),
206 boundingRectGraph.y() + boundingRectGraph.height(),
213 modelGridDisplay.
setDisableY (GRID_COORD_DISABLE_COUNT);
221 return modelGridDisplay;
227 const QSize &imageSize)
const
229 LOG4CPP_INFO_S ((*mainCat)) <<
"GridInitializer::initializeWithWidePolarCoverage";
234 if (modelCoords.
coordsType() == COORDS_TYPE_POLAR) {
236 overridePolarCoordinateSettings (modelCoords,
242 return modelGridDisplay;
245 void GridInitializer::overridePolarCoordinateSettings (
const DocumentModelCoords &modelCoords,
248 const QSize &imageSize)
const
250 ENGAUGE_ASSERT (modelCoords.
coordsType() == COORDS_TYPE_POLAR);
255 double stopX = 360.0;
257 int countX = (int) (0.5 + (stopX - startX) / stepX);
265 QPointF posTL, posBL, posTR, posBR;
271 double radiusTL = qSqrt (posTL.x () * posTL.x () + posTL.y () * posTL.y ());
272 double radiusBL = qSqrt (posBL.x () * posBL.x () + posBL.y () * posBL.y ());
273 double radiusTR = qSqrt (posTR.x () * posTR.x () + posTR.y () * posTR.y ());
274 double radiusBR = qSqrt (posBR.x () * posBR.x () + posBR.y () * posBR.y ());
276 double radius = qMax (qMax (qMax (radiusTL, radiusBL), radiusTR), radiusBR);
281 double stopY = radius;
282 double stepY = modelGridDisplay.
stepY ();
287 if (denominator != 0) {
289 (int) (0.5 + (stopY - startY) / denominator) :
290 (
int) (0.5 + (qLn (stopY) - qLn (startY)) / denominator));
298 double GridInitializer::roundOffToPower(
double arg,
301 double powerOf10 = pow ((
double) 10, power);
302 return powerOf10 * floor (arg / powerOf10 + 0.5);
307 const int minPower = -30;
309 double avalue = fabs(value);
310 if (avalue < pow(10.0, minPower)) {
313 return (
int) floor (log10 (avalue));
int computeCount(bool linearAxis, double start, double stop, double step) const
Compute axis scale count from the other axis parameters.
void setStartX(double startX)
Set method for x grid line lower bound (inclusive).
Model for DlgSettingsGridDisplay and CmdSettingsGridDisplay.
DocumentModelGridDisplay initializeWithNarrowCoverage(const QRectF &boundingRectGraph, const DocumentModelCoords &modelCoords) const
Initialize given the boundaries of the graph coordinates. The output is useful for the Checker class...
void setCountY(unsigned int countY)
Set method for y grid line count.
void setStepX(double stepX)
Set method for x grid line increment.
CoordScale coordScaleYRadius() const
Get method for linear/log scale on y/radius.
double originRadius() const
Get method for origin radius in polar mode.
double computeStart(bool linearAxis, double stop, double step, int count) const
Compute axis scale start from the other axis parameters.
void setStepY(double yStep)
Set method for y grid line increment.
void setStable(bool stable)
Set method for stable flag.
GridInitializer()
Single constructor.
CoordScale coordScaleXTheta() const
Get method for linear/log scale on x/theta.
void setStopX(double stopX)
Set method for x grid line upper bound (inclusive).
int valuePower(double value) const
Compute power of 10 for input value, rounding down to nearest integer solution of value>=10**solution...
CoordsType coordsType() const
Get method for coordinates type.
void setDisableX(GridCoordDisable disableX)
Set method for x grid line disabled variable.
void setStopY(double yStop)
Set method for y grid line upper bound (inclusive).
Model for DlgSettingsCoords and CmdSettingsCoords.
double computeStop(bool linearAxis, double start, double step, int count) const
Compute axis scale stop from the other axis parameters.
void setDisableY(GridCoordDisable disableY)
Set method for y grid line disabled variable.
DocumentModelGridDisplay initializeWithWidePolarCoverage(const QRectF &boundingRectGraph, const DocumentModelCoords &modelCoords, const Transformation &transformation, const QSize &imageSize) const
Initialize given the boundaries of the graph coordinates, and then extra processing for polar coordin...
void setCountX(unsigned int countX)
Set method for x grid line count.
void setStartY(double yStart)
Set method for y grid line lower bound (inclusive).
double stepY() const
Get method for y grid line increment.
double computeStep(bool linearAxis, double start, double stop, int count) const
Compute axis scale step from the other axis parameters.