author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Thu, 22 Apr 2010 16:15:11 +0300 | |
branch | RCL_3 |
changeset 14 | 8c4229025c0b |
parent 4 | 3b1da2848fc7 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the test suite of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
||
43 |
#include <QtTest/QtTest> |
|
44 |
#include <qgraphicsitem.h> |
|
45 |
#include <qgraphicstransform.h> |
|
46 |
#include "../../shared/util.h" |
|
47 |
||
48 |
class tst_QGraphicsTransform : public QObject { |
|
49 |
Q_OBJECT |
|
50 |
||
51 |
public slots: |
|
52 |
void initTestCase(); |
|
53 |
void cleanupTestCase(); |
|
54 |
void init(); |
|
55 |
void cleanup(); |
|
56 |
||
57 |
private slots: |
|
58 |
void scale(); |
|
59 |
void rotation(); |
|
60 |
void rotation3d_data(); |
|
61 |
void rotation3d(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
62 |
void rotation3dArbitraryAxis_data(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
63 |
void rotation3dArbitraryAxis(); |
0 | 64 |
}; |
65 |
||
66 |
||
67 |
// This will be called before the first test function is executed. |
|
68 |
// It is only called once. |
|
69 |
void tst_QGraphicsTransform::initTestCase() |
|
70 |
{ |
|
71 |
} |
|
72 |
||
73 |
// This will be called after the last test function is executed. |
|
74 |
// It is only called once. |
|
75 |
void tst_QGraphicsTransform::cleanupTestCase() |
|
76 |
{ |
|
77 |
} |
|
78 |
||
79 |
// This will be called before each test function is executed. |
|
80 |
void tst_QGraphicsTransform::init() |
|
81 |
{ |
|
82 |
} |
|
83 |
||
84 |
// This will be called after every test function. |
|
85 |
void tst_QGraphicsTransform::cleanup() |
|
86 |
{ |
|
87 |
} |
|
88 |
||
89 |
static QTransform transform2D(const QGraphicsTransform& t) |
|
90 |
{ |
|
91 |
QMatrix4x4 m; |
|
92 |
t.applyTo(&m); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
93 |
return m.toTransform(); |
0 | 94 |
} |
95 |
||
96 |
void tst_QGraphicsTransform::scale() |
|
97 |
{ |
|
98 |
QGraphicsScale scale; |
|
99 |
||
100 |
// check initial conditions |
|
101 |
QCOMPARE(scale.xScale(), qreal(1)); |
|
102 |
QCOMPARE(scale.yScale(), qreal(1)); |
|
103 |
QCOMPARE(scale.zScale(), qreal(1)); |
|
104 |
QCOMPARE(scale.origin(), QVector3D(0, 0, 0)); |
|
105 |
||
106 |
scale.setOrigin(QVector3D(10, 10, 0)); |
|
107 |
||
108 |
QCOMPARE(scale.xScale(), qreal(1)); |
|
109 |
QCOMPARE(scale.yScale(), qreal(1)); |
|
110 |
QCOMPARE(scale.zScale(), qreal(1)); |
|
111 |
QCOMPARE(scale.origin(), QVector3D(10, 10, 0)); |
|
112 |
||
113 |
QMatrix4x4 t; |
|
114 |
scale.applyTo(&t); |
|
115 |
||
116 |
QCOMPARE(t, QMatrix4x4()); |
|
117 |
QCOMPARE(transform2D(scale), QTransform()); |
|
118 |
||
119 |
scale.setXScale(10); |
|
120 |
scale.setOrigin(QVector3D(0, 0, 0)); |
|
121 |
||
122 |
QCOMPARE(scale.xScale(), qreal(10)); |
|
123 |
QCOMPARE(scale.yScale(), qreal(1)); |
|
124 |
QCOMPARE(scale.zScale(), qreal(1)); |
|
125 |
QCOMPARE(scale.origin(), QVector3D(0, 0, 0)); |
|
126 |
||
127 |
QTransform res; |
|
128 |
res.scale(10, 1); |
|
129 |
||
130 |
QCOMPARE(transform2D(scale), res); |
|
131 |
QCOMPARE(transform2D(scale).map(QPointF(10, 10)), QPointF(100, 10)); |
|
132 |
||
133 |
scale.setOrigin(QVector3D(10, 10, 0)); |
|
134 |
QCOMPARE(transform2D(scale).map(QPointF(10, 10)), QPointF(10, 10)); |
|
135 |
QCOMPARE(transform2D(scale).map(QPointF(11, 10)), QPointF(20, 10)); |
|
136 |
||
137 |
scale.setYScale(2); |
|
138 |
scale.setZScale(4.5); |
|
139 |
scale.setOrigin(QVector3D(1, 2, 3)); |
|
140 |
||
141 |
QCOMPARE(scale.xScale(), qreal(10)); |
|
142 |
QCOMPARE(scale.yScale(), qreal(2)); |
|
143 |
QCOMPARE(scale.zScale(), qreal(4.5)); |
|
144 |
QCOMPARE(scale.origin(), QVector3D(1, 2, 3)); |
|
145 |
||
146 |
QMatrix4x4 t2; |
|
147 |
scale.applyTo(&t2); |
|
148 |
||
149 |
QCOMPARE(t2.map(QVector3D(4, 5, 6)), QVector3D(31, 8, 16.5)); |
|
150 |
||
151 |
// Because the origin has a non-zero z, mapping (4, 5) in 2D |
|
152 |
// will introduce a projective component into the result. |
|
153 |
QTransform t3 = t2.toTransform(); |
|
154 |
QCOMPARE(t3.map(QPointF(4, 5)), QPointF(31 / t3.m33(), 8 / t3.m33())); |
|
155 |
} |
|
156 |
||
157 |
// QMatrix4x4 uses float internally, whereas QTransform uses qreal. |
|
158 |
// This can lead to issues with qFuzzyCompare() where it uses double |
|
159 |
// precision to compare values that have no more than float precision |
|
160 |
// after conversion from QMatrix4x4 to QTransform. The following |
|
161 |
// definitions correct for the difference. |
|
162 |
static inline bool fuzzyCompare(qreal p1, qreal p2) |
|
163 |
{ |
|
164 |
// increase delta on small machines using float instead of double |
|
165 |
if (sizeof(qreal) == sizeof(float)) |
|
166 |
return (qAbs(p1 - p2) <= 0.00002f * qMin(qAbs(p1), qAbs(p2))); |
|
167 |
else |
|
168 |
return (qAbs(p1 - p2) <= 0.00001f * qMin(qAbs(p1), qAbs(p2))); |
|
169 |
} |
|
170 |
static bool fuzzyCompare(const QTransform& t1, const QTransform& t2) |
|
171 |
{ |
|
172 |
return fuzzyCompare(t1.m11(), t2.m11()) && |
|
173 |
fuzzyCompare(t1.m12(), t2.m12()) && |
|
174 |
fuzzyCompare(t1.m13(), t2.m13()) && |
|
175 |
fuzzyCompare(t1.m21(), t2.m21()) && |
|
176 |
fuzzyCompare(t1.m22(), t2.m22()) && |
|
177 |
fuzzyCompare(t1.m23(), t2.m23()) && |
|
178 |
fuzzyCompare(t1.m31(), t2.m31()) && |
|
179 |
fuzzyCompare(t1.m32(), t2.m32()) && |
|
180 |
fuzzyCompare(t1.m33(), t2.m33()); |
|
181 |
} |
|
182 |
||
183 |
void tst_QGraphicsTransform::rotation() |
|
184 |
{ |
|
185 |
QGraphicsRotation rotation; |
|
186 |
QCOMPARE(rotation.axis(), QVector3D(0, 0, 1)); |
|
187 |
QCOMPARE(rotation.origin(), QVector3D(0, 0, 0)); |
|
188 |
QCOMPARE(rotation.angle(), (qreal)0); |
|
189 |
||
190 |
rotation.setOrigin(QVector3D(10, 10, 0)); |
|
191 |
||
192 |
QCOMPARE(rotation.axis(), QVector3D(0, 0, 1)); |
|
193 |
QCOMPARE(rotation.origin(), QVector3D(10, 10, 0)); |
|
194 |
QCOMPARE(rotation.angle(), (qreal)0); |
|
195 |
||
196 |
QMatrix4x4 t; |
|
197 |
rotation.applyTo(&t); |
|
198 |
||
199 |
QCOMPARE(t, QMatrix4x4()); |
|
200 |
QCOMPARE(transform2D(rotation), QTransform()); |
|
201 |
||
202 |
rotation.setAngle(40); |
|
203 |
rotation.setOrigin(QVector3D(0, 0, 0)); |
|
204 |
||
205 |
QCOMPARE(rotation.axis(), QVector3D(0, 0, 1)); |
|
206 |
QCOMPARE(rotation.origin(), QVector3D(0, 0, 0)); |
|
207 |
QCOMPARE(rotation.angle(), (qreal)40); |
|
208 |
||
209 |
QTransform res; |
|
210 |
res.rotate(40); |
|
211 |
||
212 |
QVERIFY(fuzzyCompare(transform2D(rotation), res)); |
|
213 |
||
214 |
rotation.setOrigin(QVector3D(10, 10, 0)); |
|
215 |
rotation.setAngle(90); |
|
216 |
QCOMPARE(transform2D(rotation).map(QPointF(10, 10)), QPointF(10, 10)); |
|
217 |
QCOMPARE(transform2D(rotation).map(QPointF(20, 10)), QPointF(10, 20)); |
|
218 |
} |
|
219 |
||
220 |
Q_DECLARE_METATYPE(Qt::Axis); |
|
221 |
void tst_QGraphicsTransform::rotation3d_data() |
|
222 |
{ |
|
223 |
QTest::addColumn<Qt::Axis>("axis"); |
|
224 |
QTest::addColumn<qreal>("angle"); |
|
225 |
||
226 |
for (int angle = 0; angle <= 360; angle++) { |
|
227 |
QTest::newRow("test rotation on X") << Qt::XAxis << qreal(angle); |
|
228 |
QTest::newRow("test rotation on Y") << Qt::YAxis << qreal(angle); |
|
229 |
QTest::newRow("test rotation on Z") << Qt::ZAxis << qreal(angle); |
|
230 |
} |
|
231 |
} |
|
232 |
||
233 |
void tst_QGraphicsTransform::rotation3d() |
|
234 |
{ |
|
235 |
QFETCH(Qt::Axis, axis); |
|
236 |
QFETCH(qreal, angle); |
|
237 |
||
238 |
QGraphicsRotation rotation; |
|
239 |
rotation.setAxis(axis); |
|
240 |
||
241 |
QMatrix4x4 t; |
|
242 |
rotation.applyTo(&t); |
|
243 |
||
244 |
QVERIFY(t.isIdentity()); |
|
245 |
QVERIFY(transform2D(rotation).isIdentity()); |
|
246 |
||
247 |
rotation.setAngle(angle); |
|
248 |
||
249 |
// QGraphicsRotation uses a correct mathematical rotation in 3D. |
|
250 |
// QTransform's Qt::YAxis rotation is inverted from the mathematical |
|
251 |
// version of rotation. We correct for that here. |
|
252 |
QTransform expected; |
|
253 |
if (axis == Qt::YAxis && angle != 180.) |
|
254 |
expected.rotate(-angle, axis); |
|
255 |
else |
|
256 |
expected.rotate(angle, axis); |
|
257 |
||
258 |
QVERIFY(fuzzyCompare(transform2D(rotation), expected)); |
|
259 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
260 |
// Check that "rotation" produces the 4x4 form of the 3x3 matrix. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
261 |
// i.e. third row and column are 0 0 1 0. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
262 |
t.setToIdentity(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
263 |
rotation.applyTo(&t); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
264 |
QMatrix4x4 r(expected); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
265 |
if (sizeof(qreal) == sizeof(float) && angle == 268) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
266 |
// This test fails, on only this angle, when qreal == float |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
267 |
// because the deg2rad value in QTransform is not accurate |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
268 |
// enough to match what QMatrix4x4 is doing. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
269 |
} else { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
270 |
QVERIFY(qFuzzyCompare(t, r)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
271 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
272 |
|
0 | 273 |
//now let's check that a null vector will not change the transform |
274 |
rotation.setAxis(QVector3D(0, 0, 0)); |
|
275 |
rotation.setOrigin(QVector3D(10, 10, 0)); |
|
276 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
277 |
t.setToIdentity(); |
0 | 278 |
rotation.applyTo(&t); |
279 |
||
280 |
QVERIFY(t.isIdentity()); |
|
281 |
QVERIFY(transform2D(rotation).isIdentity()); |
|
282 |
||
283 |
rotation.setAngle(angle); |
|
284 |
||
285 |
QVERIFY(t.isIdentity()); |
|
286 |
QVERIFY(transform2D(rotation).isIdentity()); |
|
287 |
||
288 |
rotation.setOrigin(QVector3D(0, 0, 0)); |
|
289 |
||
290 |
QVERIFY(t.isIdentity()); |
|
291 |
QVERIFY(transform2D(rotation).isIdentity()); |
|
292 |
} |
|
293 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
294 |
void tst_QGraphicsTransform::rotation3dArbitraryAxis_data() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
295 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
296 |
QTest::addColumn<QVector3D>("axis"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
297 |
QTest::addColumn<qreal>("angle"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
298 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
299 |
QVector3D axis1 = QVector3D(1.0f, 1.0f, 1.0f); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
300 |
QVector3D axis2 = QVector3D(2.0f, -3.0f, 0.5f); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
301 |
QVector3D axis3 = QVector3D(-2.0f, 0.0f, -0.5f); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
302 |
QVector3D axis4 = QVector3D(0.0001f, 0.0001f, 0.0001f); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
303 |
QVector3D axis5 = QVector3D(0.01f, 0.01f, 0.01f); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
304 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
305 |
for (int angle = 0; angle <= 360; angle++) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
306 |
QTest::newRow("test rotation on (1, 1, 1)") << axis1 << qreal(angle); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
307 |
QTest::newRow("test rotation on (2, -3, .5)") << axis2 << qreal(angle); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
308 |
QTest::newRow("test rotation on (-2, 0, -.5)") << axis3 << qreal(angle); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
309 |
QTest::newRow("test rotation on (.0001, .0001, .0001)") << axis4 << qreal(angle); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
310 |
QTest::newRow("test rotation on (.01, .01, .01)") << axis5 << qreal(angle); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
311 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
312 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
313 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
314 |
void tst_QGraphicsTransform::rotation3dArbitraryAxis() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
315 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
316 |
QFETCH(QVector3D, axis); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
317 |
QFETCH(qreal, angle); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
318 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
319 |
QGraphicsRotation rotation; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
320 |
rotation.setAxis(axis); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
321 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
322 |
QMatrix4x4 t; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
323 |
rotation.applyTo(&t); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
324 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
325 |
QVERIFY(t.isIdentity()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
326 |
QVERIFY(transform2D(rotation).isIdentity()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
327 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
328 |
rotation.setAngle(angle); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
329 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
330 |
// Compute the expected answer using QMatrix4x4 and a projection. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
331 |
// These two steps are performed in one hit by QGraphicsRotation. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
332 |
QMatrix4x4 exp; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
333 |
exp.rotate(angle, axis); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
334 |
QTransform expected = exp.toTransform(1024.0f); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
335 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
336 |
QVERIFY(fuzzyCompare(transform2D(rotation), expected)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
337 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
338 |
// Check that "rotation" produces the 4x4 form of the 3x3 matrix. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
339 |
// i.e. third row and column are 0 0 1 0. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
340 |
t.setToIdentity(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
341 |
rotation.applyTo(&t); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
342 |
QMatrix4x4 r(expected); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
343 |
QVERIFY(qFuzzyCompare(t, r)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
344 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
345 |
|
0 | 346 |
|
347 |
QTEST_MAIN(tst_QGraphicsTransform) |
|
348 |
#include "tst_qgraphicstransform.moc" |
|
349 |