Engauge Digitizer 2
Loading...
Searching...
No Matches
GridLineLimiter.cpp
Go to the documentation of this file.
1/******************************************************************************************************
2 * (C) 2016 markummitchell@github.com. This file is part of Engauge Digitizer, which is released *
3 * under GNU General Public License version 2 (GPLv2) or (at your option) any later version. See file *
4 * LICENSE or go to gnu.org/licenses for details. Distribution requires prior written permission. *
5 ******************************************************************************************************/
6
8#include "Document.h"
12#include "GridLineLimiter.h"
13#include "MainWindowModel.h"
14#include <qmath.h>
15#include "Transformation.h"
16
18
22
23void GridLineLimiter::documentBounds (const Document &document,
24 const Transformation &transformation,
25 QPointF &boundingRectMin,
26 QPointF &boundingRectMax) const
27{
28 // Get graph coordinate bounds
30 transformation);
31
32 Functor2wRet<const QString &, const Point &, CallbackSearchReturn> ftorWithCallback = functor_ret (ftor,
34 document.iterateThroughCurvePointsAxes (ftorWithCallback);
35 document.iterateThroughCurvesPointsGraphs (ftorWithCallback);
36
37 bool isEmpty;
38 boundingRectMin = ftor.boundingRectGraphMin (isEmpty);
39 boundingRectMax = ftor.boundingRectGraphMax (isEmpty);
40}
41
43 const Transformation &transformation,
44 const DocumentModelCoords &modelCoords,
45 const MainWindowModel &modelMainWindow,
46 double &startX,
47 double &stepX,
48 double &stopX,
49 unsigned int countX) const
50{
51 bool needReduction = (countX > (unsigned int) modelMainWindow.maximumGridLines());
52
53 if (modelCoords.coordScaleXTheta() == COORD_SCALE_LINEAR) {
54
55 // Linear
56 if (!needReduction) {
57 if (stepX <= 0) {
58 stepX = 0;
59 needReduction = true;
60 } else {
61 countX = qFloor (1.0 + (stopX - startX) / stepX);
62 needReduction = (countX > (unsigned int) modelMainWindow.maximumGridLines());
63 }
64 }
65
66 if (needReduction) {
67 stopX = startX + stepX * (modelMainWindow.maximumGridLines() - 1);
68 }
69
70 } else {
71
72 // Log
73 if (startX <= 0) {
74
75 // Start value is invalid so override both start and step
76 QPointF boundingRectGraphMin, boundingRectGraphMax;
77 documentBounds (document,
78 transformation,
79 boundingRectGraphMin,
80 boundingRectGraphMax);
81
82 // Override lower bound
83 startX = boundingRectGraphMin.x ();
84 }
85
86 if (!needReduction) {
87 if (stepX <= 1) {
88 stepX = 1;
89 needReduction = true;
90 } else {
91 countX = qFloor (1.0 + (qLn (stopX) - qLn (startX)) / qLn (stepX));
92 needReduction = (countX > (unsigned int) modelMainWindow.maximumGridLines());
93 }
94 }
95
96 if (needReduction) {
97 stopX = qExp (qLn (startX) + qLn (stepX) * (modelMainWindow.maximumGridLines() - 1));
98 }
99 }
100}
101
103 const Transformation &transformation,
104 const DocumentModelCoords &modelCoords,
105 const MainWindowModel &modelMainWindow,
106 double &startY,
107 double &stepY,
108 double &stopY,
109 unsigned int countY) const
110{
111 bool needReduction = (countY > (unsigned int) modelMainWindow.maximumGridLines());
112
113 if (modelCoords.coordScaleYRadius() == COORD_SCALE_LINEAR) {
114
115 // Linear
116 if (!needReduction) {
117 if (stepY <= 0) {
118 stepY = 0;
119 needReduction = true;
120 } else {
121 countY = qFloor (1.0 + (stopY - startY) / stepY);
122 needReduction = (countY > (unsigned int) modelMainWindow.maximumGridLines());
123 }
124 }
125
126 if (needReduction) {
127 stopY = startY + stepY * (modelMainWindow.maximumGridLines() - 1);
128 }
129
130 } else {
131
132 // Log
133 if (startY <= 0) {
134
135 // Start value is invalid so override both start and step
136 QPointF boundingRectGraphMin, boundingRectGraphMax;
137 documentBounds (document,
138 transformation,
139 boundingRectGraphMin,
140 boundingRectGraphMax);
141
142 // Override lower bound
143 startY = boundingRectGraphMin.y ();
144 }
145
146 if (!needReduction) {
147 if (stepY <= 1) {
148 stepY = 1;
149 needReduction = true;
150 } else {
151 countY = qFloor (1.0 + (qLn (stopY) - qLn (startY)) / qLn (stepY));
152 needReduction = (countY > (unsigned int) modelMainWindow.maximumGridLines());
153 }
154 }
155
156 if (needReduction) {
157 stopY = qExp (qLn (startY) + qLn (stepY) * (modelMainWindow.maximumGridLines() - 1));
158 }
159 }
160}
@ COORD_SCALE_LINEAR
Definition CoordScale.h:13
const int DEFAULT_MAXIMUM_GRID_LINES
Default for maximum number of grid lines.
Callback for computing the bounding rectangles of the screen and graph coordinates of the points in t...
CallbackSearchReturn callback(const QString &curveName, const Point &point)
Callback method.
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.
Storage of one imported image and the data attached to that image.
Definition Document.h:44
void iterateThroughCurvePointsAxes(const Functor2wRet< const QString &, const Point &, CallbackSearchReturn > &ftorWithCallback)
See Curve::iterateThroughCurvePoints, for the axes curve.
Definition Document.cpp:455
void iterateThroughCurvesPointsGraphs(const Functor2wRet< const QString &, const Point &, CallbackSearchReturn > &ftorWithCallback)
See Curve::iterateThroughCurvePoints, for all the graphs curves.
Definition Document.cpp:478
DocumentAxesPointsRequired documentAxesPointsRequired() const
Get method for DocumentAxesPointsRequired.
Definition Document.cpp:369
void limitForYRadius(const Document &document, const Transformation &transformation, const DocumentModelCoords &modelCoords, const MainWindowModel &modelMainWindow, double &startY, double &stepY, double &stopY, unsigned int numY) const
Limit step value for y/range coordinate. This is a noop if the maximum grid line limit in MainWindowM...
void limitForXTheta(const Document &document, const Transformation &transformation, const DocumentModelCoords &modelCoords, const MainWindowModel &modelMainWindow, double &startX, double &stepX, double &stopX, unsigned int numX) const
Limit step value for x/theta coordinate. This is a noop if the maximum grid line limit in MainWindowM...
GridLineLimiter()
Single constructor.
Model for DlgSettingsMainWindow.
int maximumGridLines() const
Get method for maximum number of grid lines.
Affine transformation between screen and graph coordinates, based on digitized axis points.