Engauge Digitizer 2
Loading...
Searching...
No Matches
TestCentipedeEndpoints.cpp
Go to the documentation of this file.
5#include "Logger.h"
6#include "MainWindowModel.h"
7#include "mmsubs.h"
8#include <qmath.h>
9#include <QTransform>
10#include <QtTest/QtTest>
12
13QTEST_MAIN (TestCentipedeEndpoints)
14
16 QObject(parent)
17{
18}
19
20void TestCentipedeEndpoints::cleanupTestCase ()
21{
22}
23
24void TestCentipedeEndpoints::initTestCase ()
25{
26 // Member variables not initialized here are fine with defaults
27
28 const bool DEBUG_FLAG = false;
29
30 initializeLogging ("engauge_test",
31 "engauge_test.log",
33
34 initTestCaseCommon ();
35 initTestCaseCartesian ();
36 initTestCasePolarLog ();
37}
38
39void TestCentipedeEndpoints::initTestCaseCartesian ()
40 {
41 // Cartesian/linear
42 // screen graph
43 // (100,100) (0,0)
44 // (150,100) (1,0))
45 // (200,100) (0,1)
46
47 QPointF posScreen0 = QPointF (m_windowSize.width() / 2,
48 m_windowSize.height() / 2); // Center
49 QPointF posScreen1 = QPointF (m_windowSize.width(),
50 m_windowSize.height() / 2); // Right
51 QPointF posScreen2 = QPointF (m_windowSize.width() / 2,
52 0); // Top
53
54 const double RADIUS = 1;
55 m_modelCoordsCartesian.setCoordsType (COORDS_TYPE_CARTESIAN);
56 DocumentModelGeneral modelGeneral; // For formatting only which this testing does not use
57 MainWindowModel mainWindowModel; // For formatting only which this testing does not use
58 QTransform matrixScene (posScreen0.x(), posScreen1.x(), posScreen2.x(),
59 posScreen0.y(), posScreen1.y(), posScreen2.y(),
60 1, 1, 1);
61 QTransform matrixGraph (0, RADIUS, 0,
62 0, 0, RADIUS,
63 1, 1, 1);
64 m_transformationCartesian.updateTransformFromMatrices (matrixScene,
65 matrixGraph);
66 m_transformationCartesian.setModelCoords (m_modelCoordsPolarLog,
67 modelGeneral,
68 mainWindowModel);
69}
70
71void TestCentipedeEndpoints::initTestCaseCommon ()
72{
73 // Common values. All test cases share common 200x200 image with origin at (100,100)
74 m_windowSize = QSize (200, 200);
75 QPointF center (m_windowSize.width () / 2,
76 m_windowSize.height () / 2);
77 m_posClickScreen = QPointF (center.x() + m_windowSize.width() / 4,
78 center.y() - m_windowSize.height() / 4);
79}
80
81void TestCentipedeEndpoints::initTestCasePolarLog ()
82 {
83 // Polar/log-radius
84 // screen graph
85 // (100,100) (0,1)
86 // (150,100) (0,10)
87 // (200,100) (0,100)
88
89 QPointF posScreen0 = QPointF (m_windowSize.width() / 2,
90 m_windowSize.height() / 2); // Center
91 QPointF posScreen1 = QPointF (m_windowSize.width(),
92 m_windowSize.height() / 2); // Right
93 QPointF posScreen2 = QPointF (m_windowSize.width() / 2,
94 0); // Top
95
96 const double LOG_RADIUS_MIN = 1;
97 const double LOG_RADIUS_MAX = 100;
98 m_modelCoordsPolarLog.setCoordsType (COORDS_TYPE_POLAR);
99 m_modelCoordsPolarLog.setCoordScaleYRadius (COORD_SCALE_LOG);
100 m_modelCoordsPolarLog.setOriginRadius (LOG_RADIUS_MIN);
101 DocumentModelGeneral modelGeneral; // For formatting only which this testing does not use
102 MainWindowModel mainWindowModel; // For formatting only which this testing does not use
103 QTransform matrixScene (posScreen0.x(), posScreen1.x(), posScreen2.x(),
104 posScreen0.y(), posScreen1.y(), posScreen2.y(),
105 1, 1, 1);
106 QTransform matrixGraph ( 0, 90, 0,
107 LOG_RADIUS_MIN, LOG_RADIUS_MAX, LOG_RADIUS_MAX,
108 1, 1, 1);
109 m_transformationPolarLog.updateTransformFromMatrices (matrixScene,
110 matrixGraph);
111 m_transformationPolarLog.setModelCoords (m_modelCoordsPolarLog,
112 modelGeneral,
113 mainWindowModel);
114}
115
116void TestCentipedeEndpoints::testCartesianXPosition ()
117{
118 const double EPSILON = 0.001;
119
120 DocumentModelGuideline modelGuideline;
121
122 CentipedeEndpointsCartesian endpoints (modelGuideline,
123 m_transformationCartesian,
124 m_posClickScreen);
125
126 QPointF posLow = endpoints.posScreenConstantYForLowX (modelGuideline.creationCircleRadius());
127 QPointF posHigh = endpoints.posScreenConstantYForHighX (modelGuideline.creationCircleRadius());
128
129 QVERIFY (magnitude (posLow - QPointF (130, 50)) < EPSILON);
130 QVERIFY (magnitude (posHigh - QPointF (170, 50)) < EPSILON);
131}
132
133void TestCentipedeEndpoints::testCartesianYPosition ()
134{
135 const double EPSILON = 0.001;
136
137 DocumentModelGuideline modelGuideline;
138
139 CentipedeEndpointsCartesian endpoints (modelGuideline,
140 m_transformationCartesian,
141 m_posClickScreen);
142
143 QPointF posLow = endpoints.posScreenConstantXForLowY (modelGuideline.creationCircleRadius());
144 QPointF posHigh = endpoints.posScreenConstantXForHighY (modelGuideline.creationCircleRadius());
145
146 QVERIFY (magnitude (posLow - QPointF (150, 70)) < EPSILON);
147 QVERIFY (magnitude (posHigh - QPointF (150, 30)) < EPSILON);
148}
149
150void TestCentipedeEndpoints::testPolarRPosition ()
151{
152 const double EPSILON = 0.001;
153
154 DocumentModelGuideline modelGuideline;
155
156 QPointF posOriginScreen (100, 100);
157 CentipedeEndpointsPolar endpoints (m_modelCoordsPolarLog,
158 modelGuideline,
159 m_transformationPolarLog,
160 m_posClickScreen,
161 posOriginScreen);
162
163 QPointF posLow, posHigh;
164 endpoints.posScreenConstantTForRHighLow (modelGuideline.creationCircleRadius(),
165 posLow,
166 posHigh);
167
168 QVERIFY (magnitude (posLow - QPointF (135.616, 64.6746)) < EPSILON);
169 QVERIFY (magnitude (posHigh - QPointF (163.840, 35.880)) < EPSILON);
170}
171
172void TestCentipedeEndpoints::testPolarTPosition ()
173{
174 const double EPSILON = 0.001;
175
176 DocumentModelGuideline modelGuideline;
177
178 QPointF posOriginScreen (100, 100);
179 CentipedeEndpointsPolar endpoints (m_modelCoordsPolarLog,
180 modelGuideline,
181 m_transformationPolarLog,
182 m_posClickScreen,
183 posOriginScreen);
184
185 QPointF posLow = endpoints.posScreenConstantRForLowT (modelGuideline.creationCircleRadius());
186 QPointF posHigh = endpoints.posScreenConstantRForHighT (modelGuideline.creationCircleRadius());
187
188 QVERIFY (magnitude (posLow - QPointF (161.2417, 66.5416)) < EPSILON);
189 QVERIFY (magnitude (posHigh - QPointF (138.2443, 33.8197)) < EPSILON);
190}
@ COORD_SCALE_LOG
Definition CoordScale.h:14
@ COORDS_TYPE_POLAR
Definition CoordsType.h:14
@ COORDS_TYPE_CARTESIAN
Definition CoordsType.h:13
const double EPSILON
void initializeLogging(const QString &name, const QString &filename, bool isDebug)
Definition Logger.cpp:21
const bool DEBUG_FLAG
double creationCircleRadius() const
Get method for creation circle radius in pixels.
Unit tests of centipede endpoints.
TestCentipedeEndpoints(QObject *parent=0)
Single constructor.
double magnitude(const QPointF &vec)
Norm of vector.
Definition mmsubs.cpp:193