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; // 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 
129  bool success = (stepX > 0);
130 
131  if (success) {
132 
133  bool stopX = modelGrid.stopX ();
134  int gridLineCount = 1 + (stopX - startX) / stepX;
135  success = (gridLineCount <= 20);
136 
137  }
138 
139  return success;
140 }
141 
142 bool TestGridLineLimiter::testLinearY (double start,
143  double step,
144  double stop,
145  double x1, double y1,
146  double x2, double y2,
147  double x3, double y3)
148 {
149  GridLineLimiter limiter;
150  QImage image;
151  Document document (image);
152  DocumentModelCoords modelCoords;
153  MainWindowModel modelMainWindow;
154  DocumentModelGridDisplay modelGrid;
155  Transformation transformation;
156  double startY, stepY; // Outputs from GridLineLimiter
157 
158  modelCoords.setCoordScaleXTheta (COORD_SCALE_LINEAR);
159  modelGrid.setStartY (start);
160  modelGrid.setStepY (step);
161  modelGrid.setStopY (stop);
162  modelMainWindow.setMaximumGridLines (5);
163  document.addPointAxisWithSpecifiedIdentifier (QPointF (0 , 0), QPointF (x1, y1), QString ("axis1"), 0.0, false);
164  document.addPointAxisWithSpecifiedIdentifier (QPointF (100, 0), QPointF (x2, y2), QString ("axis2"), 0.0, false);
165  document.addPointAxisWithSpecifiedIdentifier (QPointF (0 , 100), QPointF (x3, y3), QString ("axis3"), 0.0, false);
166 
167  limiter.limitForYRadius (document,
168  transformation,
169  modelCoords,
170  modelMainWindow,
171  modelGrid,
172  startY,
173  stepY);
174 
175  bool success = (stepY > 0);
176 
177  if (success) {
178 
179  bool stopY = modelGrid.stopY ();
180  int gridLineCount = 1 + (stopY - startY) / stepY;
181  success = (gridLineCount <= 20);
182 
183  }
184 
185  return success;
186 }
187 
188 bool TestGridLineLimiter::testLogX (double start,
189  double step,
190  double stop,
191  double x1, double y1,
192  double x2, double y2,
193  double x3, double y3)
194 {
195  GridLineLimiter limiter;
196  QImage image;
197  Document document (image);
198  DocumentModelCoords modelCoords;
199  MainWindowModel modelMainWindow;
200  DocumentModelGridDisplay modelGrid;
201  Transformation transformation;
202  double startX, stepX; // Outputs from GridLineLimiter
203 
204  modelCoords.setCoordScaleXTheta (COORD_SCALE_LOG);
205  modelGrid.setStartX (start);
206  modelGrid.setStepX (step);
207  modelGrid.setStopX (stop);
208  modelMainWindow.setMaximumGridLines (5);
209  document.addPointAxisWithSpecifiedIdentifier (QPointF (0 , 0), QPointF (x1, y1), QString ("axis1"), 0.0, false);
210  document.addPointAxisWithSpecifiedIdentifier (QPointF (100, 0), QPointF (x2, y2), QString ("axis2"), 0.0, false);
211  document.addPointAxisWithSpecifiedIdentifier (QPointF (0 , 100), QPointF (x3, y3), QString ("axis3"), 0.0, false);
212 
213  limiter.limitForXTheta (document,
214  transformation,
215  modelCoords,
216  modelMainWindow,
217  modelGrid,
218  startX,
219  stepX);
220 
221  bool success = (startX > 0) && (stepX > 0);
222 
223  if (success) {
224 
225  bool stopX = modelGrid.stopX ();
226  int gridLineCount = 1 + (qLn (stopX) - qLn (startX)) / qLn (stepX);
227  success = (gridLineCount <= 20);
228 
229  }
230 
231  return success;
232 }
233 
234 bool TestGridLineLimiter::testLogY (double start,
235  double step,
236  double stop,
237  double x1, double y1,
238  double x2, double y2,
239  double x3, double y3)
240 {
241  GridLineLimiter limiter;
242  QImage image;
243  Document document (image);
244  DocumentModelCoords modelCoords;
245  MainWindowModel modelMainWindow;
246  DocumentModelGridDisplay modelGrid;
247  Transformation transformation;
248  double startY, stepY; // Outputs from GridLineLimiter
249 
250  modelCoords.setCoordScaleYRadius (COORD_SCALE_LOG);
251  modelGrid.setStartY (start);
252  modelGrid.setStepY (step);
253  modelGrid.setStopY (stop);
254  modelMainWindow.setMaximumGridLines (5);
255  document.addPointAxisWithSpecifiedIdentifier (QPointF (0 , 0), QPointF (x1, y1), QString ("axis1"), 0.0, false);
256  document.addPointAxisWithSpecifiedIdentifier (QPointF (100, 0), QPointF (x2, y2), QString ("axis2"), 0.0, false);
257  document.addPointAxisWithSpecifiedIdentifier (QPointF (0 , 100), QPointF (x3, y3), QString ("axis3"), 0.0, false);
258 
259  limiter.limitForYRadius (document,
260  transformation,
261  modelCoords,
262  modelMainWindow,
263  modelGrid,
264  startY,
265  stepY);
266 
267  bool success = (startY > 0) && (stepY > 0);
268 
269  if (success) {
270 
271  bool stopY = modelGrid.stopY ();
272  int gridLineCount = 1 + (qLn (stopY) - qLn (startY)) / qLn (stepY);
273  success = (gridLineCount <= 20);
274 
275  }
276 
277  return success;
278 }
279 
280 void TestGridLineLimiter::testTransitionLinearToLogX ()
281 {
282  bool success = testLogX (0,
283  250,
284  1000,
285  0.001, 0.001,
286  1000, 0.001,
287  0.001, 1000);
288 
289  QVERIFY (success);
290 }
291 
292 void TestGridLineLimiter::testTransitionLinearToLogY ()
293 {
294  bool success = testLogY (0,
295  250,
296  1000,
297  0.001, 0.001,
298  1000, 0.001,
299  0.001, 1000);
300 
301  QVERIFY (success);
302 }
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:180
Model for DlgSettingsMainWindow.
double stopY() const
Get method for y grid line upper bound (inclusive).
double stopX() const
Get method for x grid line upper bound (inclusive).
void setStopY(double yStop)
Set method for y grid line upper bound (inclusive).
Model for DlgSettingsCoords and CmdSettingsCoords.
void limitForYRadius(const Document &document, const Transformation &transformation, const DocumentModelCoords &modelCoords, const MainWindowModel &modelMainWindow, const DocumentModelGridDisplay &modelGrid, double &startY, double &stepY) const
Limit step value for y/range coordinate. This is a noop if the maximum grid line limit in MainWindowM...
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.
void limitForXTheta(const Document &document, const Transformation &transformation, const DocumentModelCoords &modelCoords, const MainWindowModel &modelMainWindow, const DocumentModelGridDisplay &modelGrid, double &startX, double &stepX) const
Limit step value for x/theta coordinate. This is a noop if the maximum grid line limit in MainWindowM...
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:86
void setCoordScaleXTheta(CoordScale coordScale)
Set method for linear/log scale on x/theta.