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,
27{
28 // Get graph coordinate bounds
30 transformation);
31
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,
47 double &startX,
48 double &stepX,
49 double &stopX) const
50{
51 startX = modelGrid.startX();
52 stopX = modelGrid.stopX();
53 stepX = modelGrid.stepX();
54 int countX = signed (modelGrid.countX());
55
56 bool needReduction = (countX > modelMainWindow.maximumGridLines());
57
58 if (modelCoords.coordScaleXTheta() == COORD_SCALE_LINEAR) {
59
60 // Linear
61 if (!needReduction) {
62 if (stepX <= 0) {
63 stepX = 0;
64 needReduction = true;
65 } else {
66 countX = qFloor (1.0 + (stopX - startX) / stepX);
67 needReduction = (countX > modelMainWindow.maximumGridLines());
68 }
69 }
70
71 if (needReduction) {
72 stopX = startX + stepX * (modelMainWindow.maximumGridLines() - 1);
73 }
74
75 } else {
76
77 // Log
78 if (startX <= 0) {
79
80 // Start value is invalid so override both start and step
81 QPointF boundingRectGraphMin, boundingRectGraphMax;
82 documentBounds (document,
83 transformation,
84 boundingRectGraphMin,
85 boundingRectGraphMax);
86
87 // Override lower bound
88 startX = boundingRectGraphMin.x ();
89 }
90
91 if (!needReduction) {
92 if (stepX <= 1) {
93 stepX = 1;
94 needReduction = true;
95 } else {
96 countX = qFloor (1.0 + (qLn (stopX) - qLn (startX)) / qLn (stepX));
97 needReduction = (countX > modelMainWindow.maximumGridLines());
98 }
99 }
100
101 if (needReduction) {
102 stopX = qExp (qLn (startX) + qLn (stepX) * (modelMainWindow.maximumGridLines() - 1));
103 }
104 }
105}
106
108 const Transformation &transformation,
109 const DocumentModelCoords &modelCoords,
110 const MainWindowModel &modelMainWindow,
112 double &startY,
113 double &stepY,
114 double &stopY) const
115{
116 startY = modelGrid.startY();
117 stopY = modelGrid.stopY();
118 stepY = modelGrid.stepY();
119 int countY = signed (modelGrid.countY());
120
121 bool needReduction = (countY > modelMainWindow.maximumGridLines());
122
123 if (modelCoords.coordScaleYRadius() == COORD_SCALE_LINEAR) {
124
125 // Linear
126 if (!needReduction) {
127 if (stepY <= 0) {
128 stepY = 0;
129 needReduction = true;
130 } else {
131 countY = qFloor (1.0 + (stopY - startY) / stepY);
132 needReduction = (countY > modelMainWindow.maximumGridLines());
133 }
134 }
135
136 if (needReduction) {
137 stopY = startY + stepY * (modelMainWindow.maximumGridLines() - 1);
138 }
139
140 } else {
141
142 // Log
143 if (startY <= 0) {
144
145 // Start value is invalid so override both start and step
146 QPointF boundingRectGraphMin, boundingRectGraphMax;
147 documentBounds (document,
148 transformation,
149 boundingRectGraphMin,
150 boundingRectGraphMax);
151
152 // Override lower bound
153 startY = boundingRectGraphMin.y ();
154 }
155
156 if (!needReduction) {
157 if (stepY <= 1) {
158 stepY = 1;
159 needReduction = true;
160 } else {
161 countY = qFloor (1.0 + (qLn (stopY) - qLn (startY)) / qLn (stepY));
162 needReduction = (countY > modelMainWindow.maximumGridLines());
163 }
164 }
165
166 if (needReduction) {
167 stopY = qExp (qLn (startY) + qLn (stepY) * (modelMainWindow.maximumGridLines() - 1));
168 }
169 }
170}
@ COORD_SCALE_LINEAR
Definition CoordScale.h:13
const int INNER_RADIUS_MIN
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.
Model for DlgSettingsGridDisplay and CmdSettingsGridDisplay.
Storage of one imported image and the data attached to that image.
Definition Document.h:42
void iterateThroughCurvePointsAxes(const Functor2wRet< const QString &, const Point &, CallbackSearchReturn > &ftorWithCallback)
See Curve::iterateThroughCurvePoints, for the axes curve.
Definition Document.cpp:449
void iterateThroughCurvesPointsGraphs(const Functor2wRet< const QString &, const Point &, CallbackSearchReturn > &ftorWithCallback)
See Curve::iterateThroughCurvePoints, for all the graphs curves.
Definition Document.cpp:472
DocumentAxesPointsRequired documentAxesPointsRequired() const
Get method for DocumentAxesPointsRequired.
Definition Document.cpp:363
void limitForYRadius(const Document &document, const Transformation &transformation, const DocumentModelCoords &modelCoords, const MainWindowModel &modelMainWindow, const DocumentModelGridDisplay &modelGrid, double &startY, double &stepY, double &stopY) 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, const DocumentModelGridDisplay &modelGrid, double &startX, double &stepX, double &stopX) 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
Maximum number of grid lines.
Affine transformation between screen and graph coordinates, based on digitized axis points.