Engauge Digitizer  2
TestGridLineLimiter.cpp
1 #include "DocumentModelCoords.h"
2 #include "DocumentModelGridDisplay.h"
3 #include "GridLineLimiter.h"
4 #include "Logger.h"
5 #include "MainWindow.h"
6 #include "MainWindowModel.h"
7 #include <qmath.h>
8 #include <QtTest/QtTest>
9 #include "Test/TestGridLineLimiter.h"
10 #include "Transformation.h"
11 
12 QTEST_MAIN (TestGridLineLimiter)
13 
14 using namespace std;
15 
17  QObject(parent)
18 {
19 }
20 
21 void TestGridLineLimiter::cleanupTestCase ()
22 {
23 }
24 
25 void TestGridLineLimiter::initTestCase ()
26 {
27  const QString NO_ERROR_REPORT_LOG_FILE;
28  const QString NO_REGRESSION_OPEN_FILE;
29  const bool NO_GNUPLOT_LOG_FILES = false;
30  const bool NO_REGRESSION_IMPORT = false;
31  const bool NO_RESET = false;
32  const bool DEBUG_FLAG = false;
33  const QStringList NO_LOAD_STARTUP_FILES;
34 
35  initializeLogging ("engauge_test",
36  "engauge_test.log",
37  DEBUG_FLAG);
38 
39  MainWindow w (NO_ERROR_REPORT_LOG_FILE,
40  NO_REGRESSION_OPEN_FILE,
41  NO_GNUPLOT_LOG_FILES,
42  NO_REGRESSION_IMPORT,
43  NO_RESET,
44  NO_LOAD_STARTUP_FILES);
45  w.show ();
46 }
47 
48 void TestGridLineLimiter::testBadStepLinearX ()
49 {
50  bool success = testLinearX (0,
51  0, // Bad
52  100,
53  0.001, 0.001,
54  1000, 0.001,
55  0.001, 1000);
56 
57  QVERIFY (success);
58 }
59 
60 void TestGridLineLimiter::testBadStepLinearY ()
61 {
62  bool success = testLinearY (0,
63  0, // Bad
64  100,
65  0.001, 0.001,
66  1000, 0.001,
67  0.001, 1000);
68 
69  QVERIFY (success);
70 }
71 
72 void TestGridLineLimiter::testBadStepLogX ()
73 {
74  bool success = testLogX (0, // Bad
75  1, // Bad
76  100,
77  0.001, 0.001,
78  1000, 0.001,
79  0.001, 1000);
80 
81  QVERIFY (success);
82 }
83 
84 void TestGridLineLimiter::testBadStepLogY ()
85 {
86  bool success = testLogY (0, // Bad
87  1, // Bad
88  100,
89  0.001, 0.001,
90  1000, 0.001,
91  0.001, 1000);
92 
93  QVERIFY (success);
94 }
95 
96 bool TestGridLineLimiter::testLinearX (double start,
97  double step,
98  double stop,
99  double x1, double y1,
100  double x2, double y2,
101  double x3, double y3)
102 {
103  GridLineLimiter limiter;
104  QImage image;
105  Document document (image);
106  DocumentModelCoords modelCoords;
107  MainWindowModel modelMainWindow;
108  DocumentModelGridDisplay modelGrid;
109  Transformation transformation;
110  double startX, stepX, stopX; // Outputs from GridLineLimiter
111 
112  modelCoords.setCoordScaleXTheta (COORD_SCALE_LINEAR);
113  modelGrid.setStartX (start);
114  modelGrid.setStepX (step);
115  modelGrid.setStopX (stop);
116  modelMainWindow.setMaximumGridLines (5);
117  document.addPointAxisWithSpecifiedIdentifier (QPointF (0 , 0), QPointF (x1, y1), QString ("axis1"), 0.0, false);
118  document.addPointAxisWithSpecifiedIdentifier (QPointF (100, 0), QPointF (x2, y2), QString ("axis2"), 0.0, false);
119  document.addPointAxisWithSpecifiedIdentifier (QPointF (0 , 100), QPointF (x3, y3), QString ("axis3"), 0.0, false);
120 
121  limiter.limitForXTheta (document,
122  transformation,
123  modelCoords,
124  modelMainWindow,
125  modelGrid,
126  startX,
127  stepX,
128  stopX);
129 
130  bool success = true;
131 
132  if (stepX > 0) {
133 
134  int gridLineCount = 1 + (stopX - startX) / stepX;
135  success = (gridLineCount <= 20);
136 
137  } else {
138 
139  success = (startX == stopX);
140 
141  }
142 
143  return success;
144 }
145 
146 bool TestGridLineLimiter::testLinearY (double start,
147  double step,
148  double stop,
149  double x1, double y1,
150  double x2, double y2,
151  double x3, double y3)
152 {
153  GridLineLimiter limiter;
154  QImage image;
155  Document document (image);
156  DocumentModelCoords modelCoords;
157  MainWindowModel modelMainWindow;
158  DocumentModelGridDisplay modelGrid;
159  Transformation transformation;
160  double startY, stepY, stopY; // Outputs from GridLineLimiter
161 
162  modelCoords.setCoordScaleXTheta (COORD_SCALE_LINEAR);
163  modelGrid.setStartY (start);
164  modelGrid.setStepY (step);
165  modelGrid.setStopY (stop);
166  modelMainWindow.setMaximumGridLines (5);
167  document.addPointAxisWithSpecifiedIdentifier (QPointF (0 , 0), QPointF (x1, y1), QString ("axis1"), 0.0, false);
168  document.addPointAxisWithSpecifiedIdentifier (QPointF (100, 0), QPointF (x2, y2), QString ("axis2"), 0.0, false);
169  document.addPointAxisWithSpecifiedIdentifier (QPointF (0 , 100), QPointF (x3, y3), QString ("axis3"), 0.0, false);
170 
171  limiter.limitForYRadius (document,
172  transformation,
173  modelCoords,
174  modelMainWindow,
175  modelGrid,
176  startY,
177  stepY,
178  stopY);
179 
180  bool success = true;
181 
182  if (stepY > 0) {
183 
184  int gridLineCount = 1 + (stopY - startY) / stepY;
185  success = (gridLineCount <= 20);
186 
187  } else {
188 
189  success = (startY == stopY);
190 
191  }
192 
193  return success;
194 }
195 
196 bool TestGridLineLimiter::testLogX (double start,
197  double step,
198  double stop,
199  double x1, double y1,
200  double x2, double y2,
201  double x3, double y3)
202 {
203  GridLineLimiter limiter;
204  QImage image;
205  Document document (image);
206  DocumentModelCoords modelCoords;
207  MainWindowModel modelMainWindow;
208  DocumentModelGridDisplay modelGrid;
209  Transformation transformation;
210  double startX, stepX, stopX; // Outputs from GridLineLimiter
211 
212  modelCoords.setCoordScaleXTheta (COORD_SCALE_LOG);
213  modelGrid.setStartX (start);
214  modelGrid.setStepX (step);
215  modelGrid.setStopX (stop);
216  modelMainWindow.setMaximumGridLines (5);
217  document.addPointAxisWithSpecifiedIdentifier (QPointF (0 , 0), QPointF (x1, y1), QString ("axis1"), 0.0, false);
218  document.addPointAxisWithSpecifiedIdentifier (QPointF (100, 0), QPointF (x2, y2), QString ("axis2"), 0.0, false);
219  document.addPointAxisWithSpecifiedIdentifier (QPointF (0 , 100), QPointF (x3, y3), QString ("axis3"), 0.0, false);
220 
221  limiter.limitForXTheta (document,
222  transformation,
223  modelCoords,
224  modelMainWindow,
225  modelGrid,
226  startX,
227  stepX,
228  stopX);
229 
230  bool success = (startX > 0) && (stepX > 0);
231 
232  if (success) {
233 
234  int gridLineCount = 1 + (qLn (stopX) - qLn (startX)) / qLn (stepX);
235  success = (gridLineCount <= 20);
236 
237  }
238 
239  return success;
240 }
241 
242 bool TestGridLineLimiter::testLogY (double start,
243  double step,
244  double stop,
245  double x1, double y1,
246  double x2, double y2,
247  double x3, double y3)
248 {
249  GridLineLimiter limiter;
250  QImage image;
251  Document document (image);
252  DocumentModelCoords modelCoords;
253  MainWindowModel modelMainWindow;
254  DocumentModelGridDisplay modelGrid;
255  Transformation transformation;
256  double startY, stepY, stopY; // Outputs from GridLineLimiter
257 
258  modelCoords.setCoordScaleYRadius (COORD_SCALE_LOG);
259  modelGrid.setStartY (start);
260  modelGrid.setStepY (step);
261  modelGrid.setStopY (stop);
262  modelMainWindow.setMaximumGridLines (5);
263  document.addPointAxisWithSpecifiedIdentifier (QPointF (0 , 0), QPointF (x1, y1), QString ("axis1"), 0.0, false);
264  document.addPointAxisWithSpecifiedIdentifier (QPointF (100, 0), QPointF (x2, y2), QString ("axis2"), 0.0, false);
265  document.addPointAxisWithSpecifiedIdentifier (QPointF (0 , 100), QPointF (x3, y3), QString ("axis3"), 0.0, false);
266 
267  limiter.limitForYRadius (document,
268  transformation,
269  modelCoords,
270  modelMainWindow,
271  modelGrid,
272  startY,
273  stepY,
274  stopY);
275 
276  bool success = (startY > 0) && (stepY > 0);
277 
278  if (success) {
279 
280  int gridLineCount = 1 + (qLn (stopY) - qLn (startY)) / qLn (stepY);
281  success = (gridLineCount <= 20);
282 
283  }
284 
285  return success;
286 }
287 
288 void TestGridLineLimiter::testTransitionLinearToLogX ()
289 {
290  bool success = testLogX (0,
291  250,
292  1000,
293  0.001, 0.001,
294  1000, 0.001,
295  0.001, 1000);
296 
297  QVERIFY (success);
298 }
299 
300 void TestGridLineLimiter::testTransitionLinearToLogY ()
301 {
302  bool success = testLogY (0,
303  250,
304  1000,
305  0.001, 0.001,
306  1000, 0.001,
307  0.001, 1000);
308 
309  QVERIFY (success);
310 }
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...
void setStartX(double startX)
Set method for x grid line lower bound (inclusive).
Model for DlgSettingsGridDisplay and CmdSettingsGridDisplay.
void setStepX(double stepX)
Set method for x grid line increment.
void setCoordScaleYRadius(CoordScale coordScale)
Set method for linear/log scale on y/radius.
void setStepY(double yStep)
Set method for y grid line increment.
Affine transformation between screen and graph coordinates, based on digitized axis points...
void setStopX(double stopX)
Set method for x grid line upper bound (inclusive).
void addPointAxisWithSpecifiedIdentifier(const QPointF &posScreen, const QPointF &posGraph, const QString &identifier, double ordinal, bool isXOnly)
Add a single axis point with the specified point identifier.
Definition: Document.cpp:177
Model for DlgSettingsMainWindow.
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 setStopY(double yStop)
Set method for y grid line upper bound (inclusive).
Model for DlgSettingsCoords and CmdSettingsCoords.
Storage of one imported image and the data attached to that image.
Definition: Document.h:41
void setMaximumGridLines(int maximumGridLines)
Set method for maximum number of grid lines.
void setStartY(double yStart)
Set method for y grid line lower bound (inclusive).
Unit test of GridLineLimiter class.
TestGridLineLimiter(QObject *parent=0)
Single constructor.
Limit the number of grid lines so a bad combination of start/step/stop value will not lead to extreme...
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...
Definition: MainWindow.h:89
void setCoordScaleXTheta(CoordScale coordScale)
Set method for linear/log scale on x/theta.