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:
0
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 <qmatrix.h> |
|
45 |
#include <math.h> |
|
46 |
#include <qpolygon.h> |
|
47 |
||
48 |
Q_DECLARE_METATYPE(QRect) |
|
49 |
||
50 |
//TESTED_CLASS= |
|
51 |
//TESTED_FILES=gui/painting/qmatrix.h gui/painting/qmatrix.cpp |
|
52 |
||
53 |
class tst_QWMatrix : public QObject |
|
54 |
{ |
|
55 |
Q_OBJECT |
|
56 |
||
57 |
public: |
|
58 |
tst_QWMatrix(); |
|
59 |
virtual ~tst_QWMatrix(); |
|
60 |
||
61 |
||
62 |
public slots: |
|
63 |
void init(); |
|
64 |
void cleanup(); |
|
65 |
private slots: |
|
66 |
void mapRect_data(); |
|
67 |
void operator_star_qrect_data(); |
|
68 |
void mapToPolygon_data(); |
|
69 |
void mapRect(); |
|
70 |
void operator_star_qrect(); |
|
71 |
void operator_star_qwmatrix(); |
|
72 |
void assignments(); |
|
73 |
void mapToPolygon(); |
|
74 |
void translate(); |
|
75 |
void scale(); |
|
76 |
void mapPolygon(); |
|
77 |
||
78 |
private: |
|
79 |
void mapping_data(); |
|
80 |
}; |
|
81 |
||
82 |
Q_DECLARE_METATYPE(QMatrix) |
|
83 |
Q_DECLARE_METATYPE(QPolygon) |
|
84 |
||
85 |
tst_QWMatrix::tst_QWMatrix() |
|
86 |
{ |
|
87 |
} |
|
88 |
||
89 |
tst_QWMatrix::~tst_QWMatrix() |
|
90 |
{ |
|
91 |
} |
|
92 |
||
93 |
void tst_QWMatrix::init() |
|
94 |
{ |
|
95 |
// No initialisation is required |
|
96 |
} |
|
97 |
||
98 |
void tst_QWMatrix::cleanup() |
|
99 |
{ |
|
100 |
// No cleanup is required. |
|
101 |
} |
|
102 |
||
103 |
void tst_QWMatrix::mapRect_data() |
|
104 |
{ |
|
105 |
mapping_data(); |
|
106 |
} |
|
107 |
||
108 |
void tst_QWMatrix::operator_star_qrect_data() |
|
109 |
{ |
|
110 |
mapping_data(); |
|
111 |
} |
|
112 |
||
113 |
void tst_QWMatrix::mapToPolygon_data() |
|
114 |
{ |
|
115 |
mapping_data(); |
|
116 |
} |
|
117 |
||
118 |
void tst_QWMatrix::mapping_data() |
|
119 |
{ |
|
120 |
//create the testtable instance and define the elements |
|
121 |
QTest::addColumn<QMatrix>("matrix"); |
|
122 |
QTest::addColumn<QRect>("src"); |
|
123 |
QTest::addColumn<QPolygon>("res"); |
|
124 |
||
125 |
//next we fill it with data |
|
126 |
||
127 |
// identity |
|
128 |
QTest::newRow( "identity" ) << QMatrix( 1, 0, 0, 1, 0, 0 ) |
|
129 |
<< QRect( 10, 20, 30, 40 ) |
|
130 |
<< QPolygon( QRect( 10, 20, 30, 40 ) ); |
|
131 |
// scaling |
|
132 |
QTest::newRow( "scale 0" ) << QMatrix( 2, 0, 0, 2, 0, 0 ) |
|
133 |
<< QRect( 10, 20, 30, 40 ) |
|
134 |
<< QPolygon( QRect( 20, 40, 60, 80 ) ); |
|
135 |
QTest::newRow( "scale 1" ) << QMatrix( 10, 0, 0, 10, 0, 0 ) |
|
136 |
<< QRect( 10, 20, 30, 40 ) |
|
137 |
<< QPolygon( QRect( 100, 200, 300, 400 ) ); |
|
138 |
// mirroring |
|
139 |
QTest::newRow( "mirror 0" ) << QMatrix( -1, 0, 0, 1, 0, 0 ) |
|
140 |
<< QRect( 10, 20, 30, 40 ) |
|
141 |
<< QPolygon( QRect( -40, 20, 30, 40 ) ); |
|
142 |
QTest::newRow( "mirror 1" ) << QMatrix( 1, 0, 0, -1, 0, 0 ) |
|
143 |
<< QRect( 10, 20, 30, 40 ) |
|
144 |
<< QPolygon( QRect( 10, -60, 30, 40 ) ); |
|
145 |
QTest::newRow( "mirror 2" ) << QMatrix( -1, 0, 0, -1, 0, 0 ) |
|
146 |
<< QRect( 10, 20, 30, 40 ) |
|
147 |
<< QPolygon( QRect( -40, -60, 30, 40 ) ); |
|
148 |
QTest::newRow( "mirror 3" ) << QMatrix( -2, 0, 0, -2, 0, 0 ) |
|
149 |
<< QRect( 10, 20, 30, 40 ) |
|
150 |
<< QPolygon( QRect( -80, -120, 60, 80 ) ); |
|
151 |
QTest::newRow( "mirror 4" ) << QMatrix( -10, 0, 0, -10, 0, 0 ) |
|
152 |
<< QRect( 10, 20, 30, 40 ) |
|
153 |
<< QPolygon( QRect( -400, -600, 300, 400 ) ); |
|
154 |
QTest::newRow( "mirror 5" ) << QMatrix( -1, 0, 0, 1, 0, 0 ) |
|
155 |
<< QRect( 0, 0, 30, 40 ) |
|
156 |
<< QPolygon( QRect( -30, 0, 30, 40 ) ); |
|
157 |
QTest::newRow( "mirror 6" ) << QMatrix( 1, 0, 0, -1, 0, 0 ) |
|
158 |
<< QRect( 0, 0, 30, 40 ) |
|
159 |
<< QPolygon( QRect( 0, -40, 30, 40 ) ); |
|
160 |
QTest::newRow( "mirror 7" ) << QMatrix( -1, 0, 0, -1, 0, 0 ) |
|
161 |
<< QRect( 0, 0, 30, 40 ) |
|
162 |
<< QPolygon( QRect( -30, -40, 30, 40 ) ); |
|
163 |
QTest::newRow( "mirror 8" ) << QMatrix( -2, 0, 0, -2, 0, 0 ) |
|
164 |
<< QRect( 0, 0, 30, 40 ) |
|
165 |
<< QPolygon( QRect( -60, -80, 60, 80 ) ); |
|
166 |
QTest::newRow( "mirror 9" ) << QMatrix( -10, 0, 0, -10, 0, 0 ) |
|
167 |
<< QRect( 0, 0, 30, 40 ) |
|
168 |
<< QPolygon( QRect( -300, -400, 300, 400 ) ); |
|
169 |
||
170 |
#if defined(Q_OS_WIN32) || defined(Q_OS_WINCE) |
|
171 |
#define M_PI 3.14159265897932384626433832795f |
|
172 |
#endif |
|
173 |
||
174 |
// rotations |
|
175 |
float deg = 0.; |
|
176 |
QTest::newRow( "rot 0 a" ) << QMatrix( cos( M_PI*deg/180. ), -sin( M_PI*deg/180. ), |
|
177 |
sin( M_PI*deg/180. ), cos( M_PI*deg/180. ), 0, 0 ) |
|
178 |
<< QRect( 0, 0, 30, 40 ) |
|
179 |
<< QPolygon ( QRect( 0, 0, 30, 40 ) ); |
|
180 |
deg = 0.00001f; |
|
181 |
QTest::newRow( "rot 0 b" ) << QMatrix( cos( M_PI*deg/180. ), -sin( M_PI*deg/180. ), |
|
182 |
sin( M_PI*deg/180. ), cos( M_PI*deg/180. ), 0, 0 ) |
|
183 |
<< QRect( 0, 0, 30, 40 ) |
|
184 |
<< QPolygon ( QRect( 0, 0, 30, 40 ) ); |
|
185 |
deg = 0.; |
|
186 |
QTest::newRow( "rot 0 c" ) << QMatrix( cos( M_PI*deg/180. ), -sin( M_PI*deg/180. ), |
|
187 |
sin( M_PI*deg/180. ), cos( M_PI*deg/180. ), 0, 0 ) |
|
188 |
<< QRect( 10, 20, 30, 40 ) |
|
189 |
<< QPolygon ( QRect( 10, 20, 30, 40 ) ); |
|
190 |
deg = 0.00001f; |
|
191 |
QTest::newRow( "rot 0 d" ) << QMatrix( cos( M_PI*deg/180. ), -sin( M_PI*deg/180. ), |
|
192 |
sin( M_PI*deg/180. ), cos( M_PI*deg/180. ), 0, 0 ) |
|
193 |
<< QRect( 10, 20, 30, 40 ) |
|
194 |
<< QPolygon ( QRect( 10, 20, 30, 40 ) ); |
|
195 |
||
196 |
#if 0 |
|
197 |
// rotations |
|
198 |
deg = 90.; |
|
199 |
QTest::newRow( "rotscale 90 a" ) << QMatrix( 10*cos( M_PI*deg/180. ), -10*sin( M_PI*deg/180. ), |
|
200 |
10*sin( M_PI*deg/180. ), 10*cos( M_PI*deg/180. ), 0, 0 ) |
|
201 |
<< QRect( 0, 0, 30, 40 ) |
|
202 |
<< QPolygon( QRect( 0, -299, 400, 300 ) ); |
|
203 |
deg = 90.00001; |
|
204 |
QTest::newRow( "rotscale 90 b" ) << QMatrix( 10*cos( M_PI*deg/180. ), -10*sin( M_PI*deg/180. ), |
|
205 |
10*sin( M_PI*deg/180. ), 10*cos( M_PI*deg/180. ), 0, 0 ) |
|
206 |
<< QRect( 0, 0, 30, 40 ) |
|
207 |
<< QPolygon( QRect( 0, -299, 400, 300 ) ); |
|
208 |
deg = 90.; |
|
209 |
QTest::newRow( "rotscale 90 c" ) << QMatrix( 10*cos( M_PI*deg/180. ), -10*sin( M_PI*deg/180. ), |
|
210 |
10*sin( M_PI*deg/180. ), 10*cos( M_PI*deg/180. ), 0, 0 ) |
|
211 |
<< QRect( 10, 20, 30, 40 ) |
|
212 |
<< QPolygon( QRect( 200, -399, 400, 300 ) ); |
|
213 |
deg = 90.00001; |
|
214 |
QTest::newRow( "rotscale 90 d" ) << QMatrix( 10*cos( M_PI*deg/180. ), -10*sin( M_PI*deg/180. ), |
|
215 |
10*sin( M_PI*deg/180. ), 10*cos( M_PI*deg/180. ), 0, 0 ) |
|
216 |
<< QRect( 10, 20, 30, 40 ) |
|
217 |
<< QPolygon( QRect( 200, -399, 400, 300 ) ); |
|
218 |
||
219 |
deg = 180.; |
|
220 |
QTest::newRow( "rotscale 180 a" ) << QMatrix( 10*cos( M_PI*deg/180. ), -10*sin( M_PI*deg/180. ), |
|
221 |
10*sin( M_PI*deg/180. ), 10*cos( M_PI*deg/180. ), 0, 0 ) |
|
222 |
<< QRect( 0, 0, 30, 40 ) |
|
223 |
<< QPolygon( QRect( -299, -399, 300, 400 ) ); |
|
224 |
deg = 180.000001; |
|
225 |
QTest::newRow( "rotscale 180 b" ) << QMatrix( 10*cos( M_PI*deg/180. ), -10*sin( M_PI*deg/180. ), |
|
226 |
10*sin( M_PI*deg/180. ), 10*cos( M_PI*deg/180. ), 0, 0 ) |
|
227 |
<< QRect( 0, 0, 30, 40 ) |
|
228 |
<< QPolygon( QRect( -299, -399, 300, 400 ) ); |
|
229 |
deg = 180.; |
|
230 |
QTest::newRow( "rotscale 180 c" ) << QMatrix( 10*cos( M_PI*deg/180. ), -10*sin( M_PI*deg/180. ), |
|
231 |
10*sin( M_PI*deg/180. ), 10*cos( M_PI*deg/180. ), 0, 0 ) |
|
232 |
<< QRect( 10, 20, 30, 40 ) |
|
233 |
<< QPolygon( QRect( -399, -599, 300, 400 ) ); |
|
234 |
deg = 180.000001; |
|
235 |
QTest::newRow( "rotscale 180 d" ) << QMatrix( 10*cos( M_PI*deg/180. ), -10*sin( M_PI*deg/180. ), |
|
236 |
10*sin( M_PI*deg/180. ), 10*cos( M_PI*deg/180. ), 0, 0 ) |
|
237 |
<< QRect( 10, 20, 30, 40 ) |
|
238 |
<< QPolygon( QRect( -399, -599, 300, 400 ) ); |
|
239 |
||
240 |
deg = 270.; |
|
241 |
QTest::newRow( "rotscale 270 a" ) << QMatrix( 10*cos( M_PI*deg/180. ), -10*sin( M_PI*deg/180. ), |
|
242 |
10*sin( M_PI*deg/180. ), 10*cos( M_PI*deg/180. ), 0, 0 ) |
|
243 |
<< QRect( 0, 0, 30, 40 ) |
|
244 |
<< QPolygon( QRect( -399, 00, 400, 300 ) ); |
|
245 |
deg = 270.0000001; |
|
246 |
QTest::newRow( "rotscale 270 b" ) << QMatrix( 10*cos( M_PI*deg/180. ), -10*sin( M_PI*deg/180. ), |
|
247 |
10*sin( M_PI*deg/180. ), 10*cos( M_PI*deg/180. ), 0, 0 ) |
|
248 |
<< QRect( 0, 0, 30, 40 ) |
|
249 |
<< QPolygon( QRect( -399, 00, 400, 300 ) ); |
|
250 |
deg = 270.; |
|
251 |
QTest::newRow( "rotscale 270 c" ) << QMatrix( 10*cos( M_PI*deg/180. ), -10*sin( M_PI*deg/180. ), |
|
252 |
10*sin( M_PI*deg/180. ), 10*cos( M_PI*deg/180. ), 0, 0 ) |
|
253 |
<< QRect( 10, 20, 30, 40 ) |
|
254 |
<< QPolygon( QRect( -599, 100, 400, 300 ) ); |
|
255 |
deg = 270.000001; |
|
256 |
QTest::newRow( "rotscale 270 d" ) << QMatrix( 10*cos( M_PI*deg/180. ), -10*sin( M_PI*deg/180. ), |
|
257 |
10*sin( M_PI*deg/180. ), 10*cos( M_PI*deg/180. ), 0, 0 ) |
|
258 |
<< QRect( 10, 20, 30, 40 ) |
|
259 |
<< QPolygon( QRect( -599, 100, 400, 300 ) ); |
|
260 |
||
261 |
// rotations that are not multiples of 90 degrees. mapRect returns the bounding rect here. |
|
262 |
deg = 45; |
|
263 |
QTest::newRow( "rot 45 a" ) << QMatrix( cos( M_PI*deg/180. ), -sin( M_PI*deg/180. ), |
|
264 |
sin( M_PI*deg/180. ), cos( M_PI*deg/180. ), 0, 0 ) |
|
265 |
<< QRect( 0, 0, 10, 10 ) |
|
266 |
<< QPolygon( QRect( 0, -7, 14, 14 ) ); |
|
267 |
QTest::newRow( "rot 45 b" ) << QMatrix( cos( M_PI*deg/180. ), -sin( M_PI*deg/180. ), |
|
268 |
sin( M_PI*deg/180. ), cos( M_PI*deg/180. ), 0, 0 ) |
|
269 |
<< QRect( 10, 20, 30, 40 ) |
|
270 |
<< QPolygon( QRect( 21, -14, 49, 49 ) ); |
|
271 |
QTest::newRow( "rot 45 c" ) << QMatrix( 10*cos( M_PI*deg/180. ), -10*sin( M_PI*deg/180. ), |
|
272 |
10*sin( M_PI*deg/180. ), 10*cos( M_PI*deg/180. ), 0, 0 ) |
|
273 |
<< QRect( 0, 0, 10, 10 ) |
|
274 |
<< QPolygon( QRect( 0, -70, 141, 141 ) ); |
|
275 |
QTest::newRow( "rot 45 d" ) << QMatrix( 10*cos( M_PI*deg/180. ), -10*sin( M_PI*deg/180. ), |
|
276 |
10*sin( M_PI*deg/180. ), 10*cos( M_PI*deg/180. ), 0, 0 ) |
|
277 |
<< QRect( 10, 20, 30, 40 ) |
|
278 |
<< QPolygon( QRect( 212, -141, 495, 495 ) ); |
|
279 |
||
280 |
deg = -45; |
|
281 |
QTest::newRow( "rot -45 a" ) << QMatrix( cos( M_PI*deg/180. ), -sin( M_PI*deg/180. ), |
|
282 |
sin( M_PI*deg/180. ), cos( M_PI*deg/180. ), 0, 0 ) |
|
283 |
<< QRect( 0, 0, 10, 10 ) |
|
284 |
<< QPolygon( QRect( -7, 0, 14, 14 ) ); |
|
285 |
QTest::newRow( "rot -45 b" ) << QMatrix( cos( M_PI*deg/180. ), -sin( M_PI*deg/180. ), |
|
286 |
sin( M_PI*deg/180. ), cos( M_PI*deg/180. ), 0, 0 ) |
|
287 |
<< QRect( 10, 20, 30, 40 ) |
|
288 |
<< QPolygon( QRect( -35, 21, 49, 49 ) ); |
|
289 |
QTest::newRow( "rot -45 c" ) << QMatrix( 10*cos( M_PI*deg/180. ), -10*sin( M_PI*deg/180. ), |
|
290 |
10*sin( M_PI*deg/180. ), 10*cos( M_PI*deg/180. ), 0, 0 ) |
|
291 |
<< QRect( 0, 0, 10, 10 ) |
|
292 |
<< QPolygon( QRect( -70, 0, 141, 141 ) ); |
|
293 |
QTest::newRow( "rot -45 d" ) << QMatrix( 10*cos( M_PI*deg/180. ), -10*sin( M_PI*deg/180. ), |
|
294 |
10*sin( M_PI*deg/180. ), 10*cos( M_PI*deg/180. ), 0, 0 ) |
|
295 |
<< QRect( 10, 20, 30, 40 ) |
|
296 |
<< QPolygon( QRect( -353, 212, 495, 495 ) ); |
|
297 |
#endif |
|
298 |
} |
|
299 |
||
300 |
void tst_QWMatrix::mapRect() |
|
301 |
{ |
|
302 |
QFETCH( QMatrix, matrix ); |
|
303 |
QFETCH( QRect, src ); |
|
304 |
// qDebug( "got src: %d/%d (%d/%d), matrix=[ %f %f %f %f %f %f ]", |
|
305 |
// src.x(), src.y(), src.width(), src.height(), |
|
306 |
// matrix.m11(), matrix.m12(), matrix.m21(), matrix.m22(), matrix.dx(), matrix.dy() ); |
|
307 |
QTEST( QPolygon( matrix.mapRect(src) ), "res" ); |
|
308 |
} |
|
309 |
||
310 |
void tst_QWMatrix::operator_star_qrect() |
|
311 |
{ |
|
312 |
#if 0 // QT_VERSION >= 0x030100 |
|
313 |
QFETCH( QMatrix, matrix ); |
|
314 |
QFETCH( QRect, src ); |
|
315 |
QFETCH( QPolygon, res ); |
|
316 |
||
317 |
QCOMPARE( (matrix * src), QRegion(res) ); |
|
318 |
#else |
|
319 |
QSKIP( "Not tested with Qt versions < 3.1", SkipAll); |
|
320 |
#endif |
|
321 |
} |
|
322 |
||
323 |
||
324 |
void tst_QWMatrix::operator_star_qwmatrix() |
|
325 |
{ |
|
326 |
#if 0 |
|
327 |
// Left out until the matrix multiply operator behaves properly.. |
|
328 |
QMatrix m1( 2, 3, 4, 5, 6, 7 ); |
|
329 |
QMatrix m2( 3, 4, 5, 6, 7, 8 ); |
|
330 |
||
331 |
QMatrix result1x2( 21, 26, 37, 46, 44, 75 ); |
|
332 |
QMatrix result2x1( 22, 29, 34, 45, 53, 80); |
|
333 |
||
334 |
QMatrix product12 = m1*m2; |
|
335 |
QMatrix product21 = m2*m1; |
|
336 |
||
337 |
QVERIFY( product12==result1x2 ); |
|
338 |
QVERIFY( product21==result2x1 ); |
|
339 |
#else |
|
340 |
QSKIP( "Not tested with Qt versions since the operator is broken..", |
|
341 |
SkipAll ); |
|
342 |
#endif |
|
343 |
} |
|
344 |
||
345 |
||
346 |
void tst_QWMatrix::assignments() |
|
347 |
{ |
|
348 |
QMatrix m; |
|
349 |
m.scale(2, 3); |
|
350 |
m.rotate(45); |
|
351 |
m.shear(4, 5); |
|
352 |
||
353 |
QMatrix c1(m); |
|
354 |
||
355 |
QCOMPARE(m.m11(), c1.m11()); |
|
356 |
QCOMPARE(m.m12(), c1.m12()); |
|
357 |
QCOMPARE(m.m21(), c1.m21()); |
|
358 |
QCOMPARE(m.m22(), c1.m22()); |
|
359 |
QCOMPARE(m.dx(), c1.dx()); |
|
360 |
QCOMPARE(m.dy(), c1.dy()); |
|
361 |
||
362 |
QMatrix c2 = m; |
|
363 |
QCOMPARE(m.m11(), c2.m11()); |
|
364 |
QCOMPARE(m.m12(), c2.m12()); |
|
365 |
QCOMPARE(m.m21(), c2.m21()); |
|
366 |
QCOMPARE(m.m22(), c2.m22()); |
|
367 |
QCOMPARE(m.dx(), c2.dx()); |
|
368 |
QCOMPARE(m.dy(), c2.dy()); |
|
369 |
} |
|
370 |
||
371 |
||
372 |
void tst_QWMatrix::mapToPolygon() |
|
373 |
{ |
|
374 |
QFETCH( QMatrix, matrix ); |
|
375 |
QFETCH( QRect, src ); |
|
376 |
QFETCH( QPolygon, res ); |
|
377 |
||
378 |
QCOMPARE( matrix.mapToPolygon( src ), res ); |
|
379 |
} |
|
380 |
||
381 |
||
382 |
void tst_QWMatrix::translate() |
|
383 |
{ |
|
384 |
QMatrix m( 1, 2, 3, 4, 5, 6 ); |
|
385 |
QMatrix res2( m ); |
|
386 |
QMatrix res( 1, 2, 3, 4, 75, 106 ); |
|
387 |
m.translate( 10, 20 ); |
|
388 |
QVERIFY( m == res ); |
|
389 |
m.translate( -10, -20 ); |
|
390 |
QVERIFY( m == res2 ); |
|
391 |
} |
|
392 |
||
393 |
void tst_QWMatrix::scale() |
|
394 |
{ |
|
395 |
QMatrix m( 1, 2, 3, 4, 5, 6 ); |
|
396 |
QMatrix res2( m ); |
|
397 |
QMatrix res( 10, 20, 60, 80, 5, 6 ); |
|
398 |
m.scale( 10, 20 ); |
|
399 |
QVERIFY( m == res ); |
|
400 |
m.scale( 1./10., 1./20. ); |
|
401 |
QVERIFY( m == res2 ); |
|
402 |
} |
|
403 |
||
404 |
void tst_QWMatrix::mapPolygon() |
|
405 |
{ |
|
406 |
QPolygon poly; |
|
407 |
poly << QPoint(0, 0) << QPoint(1, 1) << QPoint(100, 1) << QPoint(1, 100) << QPoint(-1, -1) << QPoint(-1000, 1000); |
|
408 |
||
409 |
{ |
|
410 |
QMatrix m; |
|
411 |
m.rotate(90); |
|
412 |
||
413 |
// rotating 90 degrees four times should result in original poly |
|
414 |
QPolygon mapped = m.map(m.map(m.map(m.map(poly)))); |
|
415 |
QCOMPARE(mapped, poly); |
|
416 |
||
417 |
QMatrix m2; |
|
418 |
m2.scale(10, 10); |
|
419 |
QMatrix m3; |
|
420 |
m3.scale(0.1, 0.1); |
|
421 |
||
422 |
mapped = m3.map(m2.map(poly)); |
|
423 |
QCOMPARE(mapped, poly); |
|
424 |
} |
|
425 |
||
426 |
{ |
|
427 |
QMatrix m(1, 2, 3, 4, 5, 6); |
|
428 |
||
429 |
QPolygon mapped = m.map(poly); |
|
430 |
for (int i = 0; i < mapped.size(); ++i) |
|
431 |
QCOMPARE(mapped.at(i), m.map(poly.at(i))); |
|
432 |
} |
|
433 |
} |
|
434 |
||
435 |
QTEST_APPLESS_MAIN(tst_QWMatrix) |
|
436 |
#include "tst_qwmatrix.moc" |