13void GridInitializer::axisScale (
double xMin,
21 const double range_epsilon = 0.00000000001;
22 double xAverage, xAverageRoundedUp, xRange;
29 const int nDigitsPrecision = 8;
47 xAverage = (xMin + xMax) / 2.0;
49 if (qAbs (xRange) <= 0) {
50 xRange = fabs (xAverage / 10.0);
53 xDelta = pow (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 + qFloor ((xStop - xStart) / xDelta + 0.5);
80 xStart = pow(10.0, xStart);
81 xStop = pow(10.0, xStop);
82 xDelta = pow(10.0, xDelta);
87 int power =
valuePower (xDelta) - nDigitsPrecision;
88 xStart = roundOffToPower(xStart, power);
89 xStop = roundOffToPower(xStop, power);
90 xDelta = roundOffToPower(xDelta, power);
103 if (qAbs (step) <= 0) {
106 count = qFloor (1.0 + (stop - start) / step);
109 if ((start <= 0) || (step <= 0.0)) {
112 count = qFloor (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, 1.0 /
double (count - 1));
171 stop = start + step * (count - 1);
173 stop = start * pow (step,
double (count - 1));
180 const QPointF &boundingRectGraphMax,
188 double start, stop, step;
191 axisScale (boundingRectGraphMin.x(),
192 boundingRectGraphMax.x(),
200 modelGridDisplay.
setCountX (
unsigned (count));
206 axisScale (boundingRectGraphMin.y(),
207 boundingRectGraphMax.y(),
215 modelGridDisplay.
setCountY (
unsigned (count));
222 return modelGridDisplay;
226 const QPointF &boundingRectGraphMax,
229 const QSize &imageSize)
const
234 boundingRectGraphMax,
239 overridePolarCoordinateSettings (modelCoords,
245 return modelGridDisplay;
248void GridInitializer::overridePolarCoordinateSettings (
const DocumentModelCoords &modelCoords,
251 const QSize &imageSize)
const
258 double stopX = 360.0;
260 int countX = qFloor (0.5 + (stopX - startX) / stepX);
264 modelGridDisplay.
setCountX (
unsigned (countX));
268 QPointF posTL, posBL, posTR, posBR;
274 double radiusTL = qSqrt (posTL.x () * posTL.x () + posTL.y () * posTL.y ());
275 double radiusBL = qSqrt (posBL.x () * posBL.x () + posBL.y () * posBL.y ());
276 double radiusTR = qSqrt (posTR.x () * posTR.x () + posTR.y () * posTR.y ());
277 double radiusBR = qSqrt (posBR.x () * posBR.x () + posBR.y () * posBR.y ());
279 double radius = qMax (qMax (qMax (radiusTL, radiusBL), radiusTR), radiusBR);
284 double stopY = radius;
285 double stepY = modelGridDisplay.
stepY ();
290 if (qAbs (denominator) > 0) {
292 qFloor (0.5 + (stopY - startY) / denominator) :
293 qFloor (0.5 + (qLn (stopY) - qLn (startY)) / denominator));
298 modelGridDisplay.
setCountY (
unsigned (countY));
301double GridInitializer::roundOffToPower(
double arg,
304 double powerOf10 = pow (10.0, power);
305 return powerOf10 * floor (arg / powerOf10 + 0.5);
310 const int minPower = -30;
312 double avalue = fabs(value);
313 if (avalue < pow(10.0, minPower)) {
316 return qFloor (log10 (avalue));
#define ENGAUGE_ASSERT(cond)
Drop in replacement for Q_ASSERT.
@ GRID_COORD_DISABLE_COUNT
log4cpp::Category * mainCat
Model for DlgSettingsCoords and CmdSettingsCoords.
CoordScale coordScaleYRadius() const
Get method for linear/log scale on y/radius.
CoordScale coordScaleXTheta() const
Get method for linear/log scale on x/theta.
CoordsType coordsType() const
Get method for coordinates type.
double originRadius() const
Get method for origin radius in polar mode.
Model for DlgSettingsGridDisplay and CmdSettingsGridDisplay.
void setStepX(double stepX)
Set method for x grid line increment.
void setStepY(double yStep)
Set method for y grid line increment.
void setStopX(double stopX)
Set method for x grid line upper bound (inclusive).
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).
void setDisableY(GridCoordDisable disableY)
Set method for y grid line disabled variable.
double stepY() const
Get method for y grid line increment.
void setCountX(unsigned int countX)
Set method for x grid line count.
void setStartX(double startX)
Set method for x grid line lower bound (inclusive).
void setStable(bool stable)
Set method for stable flag.
void setStartY(double yStart)
Set method for y grid line lower bound (inclusive).
void setCountY(unsigned int countY)
Set method for y grid line count.
int valuePower(double value) const
Compute power of 10 for input value, rounding down to nearest integer solution of value>=10**solution...
double computeStep(bool linearAxis, double start, double stop, int count) const
Compute axis scale step from the other axis parameters.
double computeStart(bool linearAxis, double stop, double step, int count) const
Compute axis scale start from the other axis parameters.
int computeCount(bool linearAxis, double start, double stop, double step) const
Compute axis scale count from the other axis parameters.
GridInitializer()
Single constructor.
DocumentModelGridDisplay initializeWithNarrowCoverage(const QPointF &boundingRectGraphMin, const QPointF &boundingRectGraphMax, const DocumentModelCoords &modelCoords) const
Initialize given the boundaries of the graph coordinates.
DocumentModelGridDisplay initializeWithWidePolarCoverage(const QPointF &boundingRectGraphMin, const QPointF &boundingRectGraphMax, 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...
double computeStop(bool linearAxis, double start, double step, int count) const
Compute axis scale stop from the other axis parameters.
#define LOG4CPP_INFO_S(logger)