0
|
1 |
/****************************************************************************
|
|
2 |
**
|
18
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
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 |
#include "private/qpathclipper_p.h"
|
|
42 |
#include "paths.h"
|
30
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
43 |
#include "pathcompare.h"
|
0
|
44 |
|
|
45 |
#include <QtTest/QtTest>
|
|
46 |
|
|
47 |
#include <qpainterpath.h>
|
|
48 |
#include <qpolygon.h>
|
|
49 |
#include <qdebug.h>
|
|
50 |
#include <qpainter.h>
|
|
51 |
|
|
52 |
#include <math.h>
|
|
53 |
|
|
54 |
class tst_QPathClipper : public QObject
|
|
55 |
{
|
|
56 |
Q_OBJECT
|
|
57 |
|
|
58 |
public:
|
|
59 |
tst_QPathClipper();
|
|
60 |
virtual ~tst_QPathClipper();
|
|
61 |
|
|
62 |
private:
|
|
63 |
void clipTest(int subjectIndex, int clipIndex, QPathClipper::Operation op);
|
|
64 |
|
|
65 |
QList<QPainterPath> paths;
|
|
66 |
|
|
67 |
public slots:
|
|
68 |
void initTestCase();
|
|
69 |
|
|
70 |
private slots:
|
|
71 |
void testWingedEdge();
|
|
72 |
|
|
73 |
void testComparePaths();
|
|
74 |
|
|
75 |
void clip_data();
|
|
76 |
void clip();
|
|
77 |
|
|
78 |
void clip2();
|
|
79 |
void clip3();
|
|
80 |
|
|
81 |
void testIntersections();
|
|
82 |
void testIntersections2();
|
|
83 |
void testIntersections3();
|
|
84 |
void testIntersections4();
|
|
85 |
void testIntersections5();
|
|
86 |
void testIntersections6();
|
|
87 |
void testIntersections7();
|
|
88 |
void testIntersections8();
|
|
89 |
void testIntersections9();
|
|
90 |
|
|
91 |
void zeroDerivativeCurves();
|
|
92 |
|
|
93 |
void task204301_data();
|
|
94 |
void task204301();
|
|
95 |
|
|
96 |
void task209056();
|
|
97 |
void task251909();
|
30
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
98 |
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
99 |
void qtbug3778();
|
0
|
100 |
};
|
|
101 |
|
|
102 |
Q_DECLARE_METATYPE(QPainterPath)
|
|
103 |
Q_DECLARE_METATYPE(QPathClipper::Operation)
|
|
104 |
|
|
105 |
tst_QPathClipper::tst_QPathClipper()
|
|
106 |
{
|
|
107 |
}
|
|
108 |
|
|
109 |
tst_QPathClipper::~tst_QPathClipper()
|
|
110 |
{
|
|
111 |
}
|
|
112 |
|
|
113 |
void tst_QPathClipper::initTestCase()
|
|
114 |
{
|
|
115 |
paths << Paths::rect();
|
|
116 |
paths << Paths::heart();
|
|
117 |
paths << Paths::body();
|
|
118 |
paths << Paths::mailbox();
|
|
119 |
paths << Paths::deer();
|
|
120 |
paths << Paths::fire();
|
|
121 |
|
|
122 |
paths << Paths::random1();
|
|
123 |
paths << Paths::random2();
|
|
124 |
|
|
125 |
paths << Paths::heart2();
|
|
126 |
paths << Paths::rect2();
|
|
127 |
paths << Paths::rect3();
|
|
128 |
paths << Paths::rect4();
|
|
129 |
paths << Paths::rect5();
|
|
130 |
paths << Paths::rect6();
|
|
131 |
|
|
132 |
paths << Paths::frame1();
|
|
133 |
paths << Paths::frame2();
|
|
134 |
paths << Paths::frame3();
|
|
135 |
paths << Paths::frame4();
|
|
136 |
|
|
137 |
paths << Paths::triangle1();
|
|
138 |
paths << Paths::triangle2();
|
|
139 |
|
|
140 |
paths << Paths::node();
|
|
141 |
paths << Paths::interRect();
|
|
142 |
|
|
143 |
paths << Paths::simpleCurve();
|
|
144 |
paths << Paths::simpleCurve2();
|
|
145 |
paths << Paths::simpleCurve3();
|
|
146 |
|
|
147 |
paths << Paths::bezier1();
|
|
148 |
paths << Paths::bezier2();
|
|
149 |
paths << Paths::bezier3();
|
|
150 |
paths << Paths::bezier4();
|
|
151 |
|
|
152 |
paths << Paths::bezierFlower();
|
|
153 |
paths << Paths::lips();
|
|
154 |
paths << Paths::clover();
|
|
155 |
paths << Paths::ellipses();
|
|
156 |
paths << Paths::windingFill();
|
|
157 |
paths << Paths::oddEvenFill();
|
|
158 |
paths << Paths::squareWithHole();
|
|
159 |
paths << Paths::circleWithHole();
|
|
160 |
paths << Paths::bezierQuadrant();
|
|
161 |
|
|
162 |
// make sure all the bounding rects are centered at the origin
|
|
163 |
for (int i = 0; i < paths.size(); ++i) {
|
|
164 |
QRectF bounds = paths[i].boundingRect();
|
|
165 |
|
|
166 |
QMatrix m(1, 0,
|
|
167 |
0, 1,
|
|
168 |
-bounds.center().x(), -bounds.center().y());
|
|
169 |
|
|
170 |
paths[i] = m.map(paths[i]);
|
|
171 |
}
|
|
172 |
}
|
|
173 |
|
|
174 |
static QPainterPath samplePath1()
|
|
175 |
{
|
|
176 |
QPainterPath path;
|
|
177 |
path.moveTo(QPointF(200, 246.64789));
|
|
178 |
path.lineTo(QPointF(200, 206.64789));
|
|
179 |
path.lineTo(QPointF(231.42858, 206.64789));
|
|
180 |
path.lineTo(QPointF(231.42858, 246.64789));
|
|
181 |
path.lineTo(QPointF(200, 246.64789));
|
|
182 |
return path;
|
|
183 |
}
|
|
184 |
|
|
185 |
static QPainterPath samplePath2()
|
|
186 |
{
|
|
187 |
QPainterPath path;
|
|
188 |
path.moveTo(QPointF(200, 146.64789));
|
|
189 |
path.lineTo(QPointF(200, 106.64789));
|
|
190 |
path.lineTo(QPointF(231.42858, 106.64789));
|
|
191 |
path.lineTo(QPointF(231.42858, 146.64789));
|
|
192 |
path.lineTo(QPointF(200, 146.64789));
|
|
193 |
return path;
|
|
194 |
}
|
|
195 |
|
|
196 |
static QPainterPath samplePath3()
|
|
197 |
{
|
|
198 |
QPainterPath path;
|
|
199 |
path.moveTo(QPointF(231.42858, 80.933609));
|
|
200 |
path.lineTo(QPointF(200, 80.933609));
|
|
201 |
path.lineTo(QPointF(200, 96.64788999999999));
|
|
202 |
path.lineTo(QPointF(231.42858, 96.64788999999999));
|
|
203 |
path.lineTo(QPointF(231.42858, 80.933609));
|
|
204 |
return path;
|
|
205 |
}
|
|
206 |
|
|
207 |
static QPainterPath samplePath4()
|
|
208 |
{
|
|
209 |
QPainterPath path;
|
|
210 |
path.moveTo(QPointF(288.571434, 80.933609));
|
|
211 |
path.lineTo(QPointF(431.42858, 80.933609));
|
|
212 |
path.lineTo(QPointF(431.42858, 96.64788999999999));
|
|
213 |
path.lineTo(QPointF(288.571434, 96.64788999999999));
|
|
214 |
path.lineTo(QPointF(288.571434, 80.933609));
|
|
215 |
return path;
|
|
216 |
}
|
|
217 |
|
|
218 |
static QPainterPath samplePath5()
|
|
219 |
{
|
|
220 |
QPainterPath path;
|
|
221 |
path.moveTo(QPointF(588.571434, 80.933609));
|
|
222 |
path.lineTo(QPointF(682.85715, 80.933609));
|
|
223 |
path.lineTo(QPointF(682.85715, 96.64788999999999));
|
|
224 |
path.lineTo(QPointF(588.571434, 96.64788999999999));
|
|
225 |
path.lineTo(QPointF(588.571434, 80.933609));
|
|
226 |
return path;
|
|
227 |
}
|
|
228 |
|
|
229 |
static QPainterPath samplePath6()
|
|
230 |
{
|
|
231 |
QPainterPath path;
|
|
232 |
path.moveTo(QPointF(588.571434, 80.933609));
|
|
233 |
path.lineTo(QPointF(200, 80.933609));
|
|
234 |
path.lineTo(QPointF(200, 446.6479));
|
|
235 |
path.lineTo(QPointF(682.85715, 446.6479));
|
|
236 |
path.lineTo(QPointF(682.85715, 96.64788999999999));
|
|
237 |
path.lineTo(QPointF(731.42858, 96.64788999999999));
|
|
238 |
path.lineTo(QPointF(731.42858, 56.64788999999999));
|
|
239 |
path.lineTo(QPointF(588.571434, 56.64788999999999));
|
|
240 |
path.lineTo(QPointF(588.571434, 80.933609));
|
|
241 |
return path;
|
|
242 |
}
|
|
243 |
|
|
244 |
static QPainterPath samplePath7()
|
|
245 |
{
|
|
246 |
QPainterPath path;
|
|
247 |
path.moveTo(QPointF(682.85715, 206.64789));
|
|
248 |
path.lineTo(QPointF(682.85715, 246.64789));
|
|
249 |
path.lineTo(QPointF(588.571434, 246.64789));
|
|
250 |
path.lineTo(QPointF(588.571434, 206.64789));
|
|
251 |
path.lineTo(QPointF(682.85715, 206.64789));
|
|
252 |
return path;
|
|
253 |
}
|
|
254 |
|
|
255 |
static QPainterPath samplePath8()
|
|
256 |
{
|
|
257 |
QPainterPath path;
|
|
258 |
path.moveTo(QPointF(682.85715, 406.64789));
|
|
259 |
path.lineTo(QPointF(682.85715, 446.64789));
|
|
260 |
path.lineTo(QPointF(588.571434, 446.64789));
|
|
261 |
path.lineTo(QPointF(588.571434, 406.64789));
|
|
262 |
path.lineTo(QPointF(682.85715, 406.64789));
|
|
263 |
return path;
|
|
264 |
}
|
|
265 |
|
|
266 |
static QPainterPath samplePath9()
|
|
267 |
{
|
|
268 |
QPainterPath path;
|
|
269 |
path.moveTo(QPointF(682.85715, 426.64789));
|
|
270 |
path.lineTo(QPointF(682.85715, 446.6479));
|
|
271 |
path.lineTo(QPointF(568.571434, 446.6479));
|
|
272 |
path.lineTo(QPointF(568.571434, 426.64789));
|
|
273 |
path.lineTo(QPointF(682.85715, 426.64789));
|
|
274 |
return path;
|
|
275 |
}
|
|
276 |
|
|
277 |
static QPainterPath samplePath10()
|
|
278 |
{
|
|
279 |
QPainterPath path;
|
|
280 |
path.moveTo(QPointF(511.42858, 446.6479));
|
|
281 |
path.lineTo(QPointF(368.571434, 446.6479));
|
|
282 |
path.lineTo(QPointF(368.571434, 426.64789));
|
|
283 |
path.lineTo(QPointF(511.42858, 426.64789));
|
|
284 |
path.lineTo(QPointF(511.42858, 446.6479));
|
|
285 |
return path;
|
|
286 |
}
|
|
287 |
|
|
288 |
static QPainterPath samplePath13()
|
|
289 |
{
|
|
290 |
QPainterPath path;
|
|
291 |
path.moveTo(QPointF(160, 200));
|
|
292 |
path.lineTo(QPointF(100, 200));
|
|
293 |
path.lineTo(QPointF(100, 130));
|
|
294 |
path.lineTo(QPointF(160, 130));
|
|
295 |
path.lineTo(QPointF(160, 200));
|
|
296 |
return path;
|
|
297 |
}
|
|
298 |
|
|
299 |
static QPainterPath samplePath14()
|
|
300 |
{
|
|
301 |
QPainterPath path;
|
30
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
302 |
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
303 |
path.moveTo(160, 80);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
304 |
path.lineTo(160, 180);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
305 |
path.lineTo(100, 180);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
306 |
path.lineTo(100, 80);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
307 |
path.lineTo(160, 80);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
308 |
path.moveTo(160, 80);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
309 |
path.lineTo(160, 100);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
310 |
path.lineTo(120, 100);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
311 |
path.lineTo(120, 80);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
312 |
|
0
|
313 |
return path;
|
|
314 |
}
|
|
315 |
|
|
316 |
void tst_QPathClipper::clip_data()
|
|
317 |
{
|
|
318 |
//create the testtable instance and define the elements
|
|
319 |
QTest::addColumn<QPainterPath>("subject");
|
|
320 |
QTest::addColumn<QPainterPath>("clip");
|
|
321 |
QTest::addColumn<QPathClipper::Operation>("op");
|
|
322 |
QTest::addColumn<QPainterPath>("result");
|
|
323 |
|
|
324 |
//next we fill it with data
|
|
325 |
QTest::newRow( "simple1" ) << Paths::frame3()
|
|
326 |
<< Paths::frame4()
|
|
327 |
<< QPathClipper::BoolAnd
|
|
328 |
<< samplePath1();
|
|
329 |
|
|
330 |
QTest::newRow( "simple2" ) << Paths::frame3()
|
|
331 |
<< Paths::frame4() * QTransform().translate(0, -100)
|
|
332 |
<< QPathClipper::BoolAnd
|
|
333 |
<< samplePath2();
|
|
334 |
|
|
335 |
QTest::newRow( "simple3" ) << Paths::frame3()
|
|
336 |
<< Paths::frame4() * QTransform().translate(0, -150)
|
|
337 |
<< QPathClipper::BoolAnd
|
|
338 |
<< samplePath3();
|
|
339 |
|
|
340 |
QTest::newRow( "simple4" ) << Paths::frame3()
|
|
341 |
<< Paths::frame4() * QTransform().translate(200, -150)
|
|
342 |
<< QPathClipper::BoolAnd
|
|
343 |
<< samplePath4();
|
|
344 |
|
|
345 |
QTest::newRow( "simple5" ) << Paths::frame3()
|
|
346 |
<< Paths::frame4() * QTransform().translate(500, -150)
|
|
347 |
<< QPathClipper::BoolAnd
|
|
348 |
<< samplePath5();
|
|
349 |
|
|
350 |
QTest::newRow( "simple6" ) << Paths::frame3()
|
|
351 |
<< Paths::frame4() * QTransform().translate(500, -150)
|
|
352 |
<< QPathClipper::BoolOr
|
|
353 |
<< samplePath6();
|
|
354 |
|
|
355 |
QTest::newRow( "simple7" ) << Paths::frame3()
|
|
356 |
<< Paths::frame4() * QTransform().translate(500, 0)
|
|
357 |
<< QPathClipper::BoolAnd
|
|
358 |
<< samplePath7();
|
|
359 |
|
|
360 |
QTest::newRow( "simple8" ) << Paths::frame3()
|
|
361 |
<< Paths::frame4() * QTransform().translate(500, 200)
|
|
362 |
<< QPathClipper::BoolAnd
|
|
363 |
<< samplePath8();
|
|
364 |
|
|
365 |
QTest::newRow( "simple9" ) << Paths::frame3()
|
|
366 |
<< Paths::frame4() * QTransform().translate(480, 220)
|
|
367 |
<< QPathClipper::BoolAnd
|
|
368 |
<< samplePath9();
|
|
369 |
|
|
370 |
QTest::newRow( "simple10" ) << Paths::frame3()
|
|
371 |
<< Paths::frame4() * QTransform().translate(280, 220)
|
|
372 |
<< QPathClipper::BoolAnd
|
|
373 |
<< samplePath10();
|
|
374 |
|
|
375 |
QTest::newRow( "simple_move_to1" ) << Paths::rect4()
|
|
376 |
<< Paths::rect2() * QTransform().translate(-20, 50)
|
|
377 |
<< QPathClipper::BoolAnd
|
|
378 |
<< samplePath13();
|
|
379 |
|
|
380 |
QTest::newRow( "simple_move_to2" ) << Paths::rect4()
|
|
381 |
<< Paths::rect2() * QTransform().translate(-20, 0)
|
|
382 |
<< QPathClipper::BoolAnd
|
|
383 |
<< samplePath14();
|
|
384 |
}
|
|
385 |
|
|
386 |
// sanity check to make sure comparePaths declared above works
|
|
387 |
void tst_QPathClipper::testComparePaths()
|
|
388 |
{
|
|
389 |
QPainterPath a;
|
|
390 |
QPainterPath b;
|
|
391 |
|
|
392 |
a.addRect(0, 0, 10, 10);
|
|
393 |
b.addRect(0, 0, 10.00001, 10.00001);
|
|
394 |
|
30
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
395 |
QVERIFY(!QPathCompare::comparePaths(a, b));
|
0
|
396 |
|
|
397 |
b = QPainterPath();
|
|
398 |
b.addRect(0, 0, 10.00000000001, 10.00000000001);
|
|
399 |
|
30
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
400 |
QVERIFY(QPathCompare::comparePaths(a, b));
|
0
|
401 |
|
|
402 |
b = QPainterPath();
|
|
403 |
b.moveTo(10, 0);
|
|
404 |
b.lineTo(0, 0);
|
|
405 |
b.lineTo(0, 10);
|
|
406 |
b.lineTo(10, 10);
|
|
407 |
|
30
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
408 |
QVERIFY(QPathCompare::comparePaths(a, b));
|
0
|
409 |
b.lineTo(10, 0);
|
30
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
410 |
QVERIFY(QPathCompare::comparePaths(a, b));
|
0
|
411 |
|
|
412 |
b = QPainterPath();
|
|
413 |
b.moveTo(10, 0);
|
|
414 |
b.lineTo(0, 10);
|
|
415 |
b.lineTo(0, 0);
|
|
416 |
b.lineTo(10, 10);
|
|
417 |
|
30
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
418 |
QVERIFY(!QPathCompare::comparePaths(a, b));
|
0
|
419 |
}
|
|
420 |
|
|
421 |
void tst_QPathClipper::clip()
|
|
422 |
{
|
|
423 |
if (sizeof(double) != sizeof(qreal)) {
|
|
424 |
QSKIP("This test only works for qreal=double, otherwise ends in rounding errors", SkipAll);
|
|
425 |
}
|
|
426 |
QFETCH( QPainterPath, subject );
|
|
427 |
QFETCH( QPainterPath, clip );
|
|
428 |
QFETCH( QPathClipper::Operation, op );
|
|
429 |
QFETCH( QPainterPath, result);
|
|
430 |
QPathClipper clipper(subject, clip);
|
|
431 |
QPainterPath x = clipper.clip(op);
|
|
432 |
|
30
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
433 |
QVERIFY(QPathCompare::comparePaths(x, result));
|
0
|
434 |
}
|
|
435 |
|
|
436 |
static inline QPointF randomPointInRect(const QRectF &rect)
|
|
437 |
{
|
|
438 |
qreal rx = qrand() / (RAND_MAX + 1.);
|
|
439 |
qreal ry = qrand() / (RAND_MAX + 1.);
|
|
440 |
|
|
441 |
return QPointF(rect.left() + rx * rect.width(),
|
|
442 |
rect.top() + ry * rect.height());
|
|
443 |
}
|
|
444 |
|
|
445 |
void tst_QPathClipper::clipTest(int subjectIndex, int clipIndex, QPathClipper::Operation op)
|
|
446 |
{
|
|
447 |
const QPainterPath &subject = paths[subjectIndex];
|
|
448 |
const QPainterPath &clip = paths[clipIndex];
|
|
449 |
const int count = 40;
|
|
450 |
|
|
451 |
QRectF bounds = subject.boundingRect().united(clip.boundingRect());
|
|
452 |
|
|
453 |
const qreal adjustX = bounds.width() * 0.01;
|
|
454 |
const qreal adjustY = bounds.height() * 0.01;
|
|
455 |
|
|
456 |
// make sure we test some points that are outside both paths as well
|
|
457 |
bounds = bounds.adjusted(-adjustX, -adjustY, adjustX, adjustY);
|
|
458 |
|
|
459 |
const int dim = 256;
|
|
460 |
const qreal scale = qMin(dim / bounds.width(), dim / bounds.height());
|
|
461 |
|
|
462 |
QPathClipper clipper(subject, clip);
|
|
463 |
QPainterPath result = clipper.clip(op);
|
|
464 |
|
|
465 |
// using the image here is a bit of a hacky way to make sure we don't test points that
|
|
466 |
// are too close to the path edges to avoid test fails that are due to numerical errors
|
|
467 |
QImage img(dim, dim, QImage::Format_ARGB32_Premultiplied);
|
|
468 |
img.fill(0x0);
|
|
469 |
QPainter p(&img);
|
|
470 |
p.setRenderHint(QPainter::Antialiasing);
|
|
471 |
p.scale(scale, scale);
|
|
472 |
p.translate(-bounds.topLeft());
|
|
473 |
p.setPen(Qt::black);
|
|
474 |
p.drawPath(subject);
|
|
475 |
p.setPen(Qt::red);
|
|
476 |
p.drawPath(clip);
|
|
477 |
p.end();
|
|
478 |
|
|
479 |
for (int i = 0; i < count; ++i) {
|
|
480 |
QPointF point;
|
|
481 |
QRgb pixel;
|
|
482 |
do {
|
|
483 |
point = randomPointInRect(bounds);
|
|
484 |
const QPointF imagePoint = (point - bounds.topLeft()) * scale;
|
|
485 |
|
|
486 |
pixel = img.pixel(int(imagePoint.x()), int(imagePoint.y()));
|
|
487 |
} while (qAlpha(pixel) > 0);
|
|
488 |
|
|
489 |
const bool inSubject = subject.contains(point);
|
|
490 |
const bool inClip = clip.contains(point);
|
|
491 |
|
|
492 |
const bool inResult = result.contains(point);
|
|
493 |
|
|
494 |
bool expected = false;
|
|
495 |
switch (op) {
|
|
496 |
case QPathClipper::BoolAnd:
|
|
497 |
expected = inSubject && inClip;
|
|
498 |
break;
|
|
499 |
case QPathClipper::BoolOr:
|
|
500 |
expected = inSubject || inClip;
|
|
501 |
break;
|
|
502 |
case QPathClipper::BoolSub:
|
|
503 |
expected = inSubject && !inClip;
|
|
504 |
break;
|
|
505 |
default:
|
|
506 |
break;
|
|
507 |
}
|
|
508 |
|
|
509 |
if (expected != inResult) {
|
|
510 |
char str[256];
|
|
511 |
const char *opStr =
|
|
512 |
op == QPathClipper::BoolAnd ? "and" :
|
|
513 |
op == QPathClipper::BoolOr ? "or" : "sub";
|
|
514 |
sprintf(str, "Expected: %d, actual: %d, subject: %d, clip: %d, op: %s\n",
|
|
515 |
int(expected), int(inResult), subjectIndex, clipIndex, opStr);
|
|
516 |
|
|
517 |
// debugging
|
|
518 |
#if 0
|
|
519 |
QRect rect = bounds.toAlignedRect();
|
|
520 |
|
|
521 |
QPainter p(&img);
|
|
522 |
p.scale(scale, scale);
|
|
523 |
p.translate(-bounds.topLeft());
|
|
524 |
|
|
525 |
p.setPen(Qt::NoPen);
|
|
526 |
p.setBrush(QColor(0x700ff00));
|
|
527 |
p.drawPath(result);
|
|
528 |
|
|
529 |
p.setPen(Qt::blue);
|
|
530 |
p.drawPoint(point);
|
|
531 |
p.end();
|
|
532 |
|
|
533 |
char str2[256];
|
|
534 |
sprintf(str2, "fail-%d-%d-%s.png", subjectIndex, clipIndex, opStr);
|
|
535 |
img.save(str2);
|
|
536 |
#endif
|
|
537 |
QFAIL(str);
|
|
538 |
}
|
|
539 |
}
|
|
540 |
}
|
|
541 |
|
|
542 |
void tst_QPathClipper::clip2()
|
|
543 |
{
|
|
544 |
if (sizeof(double) != sizeof(qreal))
|
|
545 |
QSKIP("This test only works for qreal=double, otherwise ends in rounding errors", SkipAll);
|
|
546 |
|
|
547 |
int operation = 0;
|
|
548 |
|
|
549 |
for (int i = 0; i < paths.size(); ++i) {
|
|
550 |
for (int j = 0; j <= i; ++j) {
|
|
551 |
QPathClipper::Operation op = QPathClipper::Operation((operation++) % 3);
|
|
552 |
clipTest(i, j, op);
|
|
553 |
}
|
|
554 |
}
|
|
555 |
}
|
|
556 |
|
|
557 |
void tst_QPathClipper::clip3()
|
|
558 |
{
|
|
559 |
int operation = 0;
|
|
560 |
|
|
561 |
// this subset should work correctly for qreal = float
|
|
562 |
for (int i = 0; i < 20; ++i) {
|
|
563 |
for (int j = 0; j <= i; ++j) {
|
|
564 |
QPathClipper::Operation op = QPathClipper::Operation((operation++) % 3);
|
|
565 |
clipTest(i, j, op);
|
|
566 |
}
|
|
567 |
}
|
|
568 |
}
|
|
569 |
|
|
570 |
void tst_QPathClipper::testIntersections()
|
|
571 |
{
|
|
572 |
QPainterPath path1;
|
|
573 |
QPainterPath path2;
|
|
574 |
|
|
575 |
path1.addRect(0, 0, 100, 100);
|
|
576 |
path2.addRect(20, 20, 20, 20);
|
|
577 |
QVERIFY(path1.intersects(path2));
|
|
578 |
QVERIFY(path2.intersects(path1));
|
|
579 |
QVERIFY(path1.contains(path2));
|
|
580 |
QVERIFY(!path2.contains(path1));
|
|
581 |
|
|
582 |
path1 = QPainterPath();
|
|
583 |
path2 = QPainterPath();
|
|
584 |
path1.addEllipse(0, 0, 100, 100);
|
|
585 |
path2.addEllipse(200, 200, 100, 100);
|
|
586 |
QVERIFY(!path1.intersects(path2));
|
|
587 |
QVERIFY(!path2.intersects(path1));
|
|
588 |
QVERIFY(!path1.contains(path2));
|
|
589 |
QVERIFY(!path2.contains(path1));
|
|
590 |
|
|
591 |
path1 = QPainterPath();
|
|
592 |
path2 = QPainterPath();
|
|
593 |
path1.addEllipse(0, 0, 100, 100);
|
|
594 |
path2.addEllipse(50, 50, 100, 100);
|
|
595 |
QVERIFY(path1.intersects(path2));
|
|
596 |
QVERIFY(path2.intersects(path1));
|
|
597 |
QVERIFY(!path1.contains(path2));
|
|
598 |
QVERIFY(!path2.contains(path1));
|
|
599 |
|
|
600 |
path1 = QPainterPath();
|
|
601 |
path2 = QPainterPath();
|
|
602 |
path1.addRect(100, 100, 100, 100);
|
|
603 |
path2.addRect(50, 100, 100, 20);
|
|
604 |
QVERIFY(path1.intersects(path2));
|
|
605 |
QVERIFY(path2.intersects(path1));
|
|
606 |
QVERIFY(!path1.contains(path2));
|
|
607 |
QVERIFY(!path2.contains(path1));
|
|
608 |
|
|
609 |
path1 = QPainterPath();
|
|
610 |
path2 = QPainterPath();
|
|
611 |
path1.addRect(100, 100, 100, 100);
|
|
612 |
path2.addRect(110, 201, 100, 20);
|
|
613 |
QVERIFY(!path1.intersects(path2));
|
|
614 |
QVERIFY(!path2.intersects(path1));
|
|
615 |
QVERIFY(!path1.contains(path2));
|
|
616 |
QVERIFY(!path2.contains(path1));
|
|
617 |
|
|
618 |
path1 = QPainterPath();
|
|
619 |
path2 = QPainterPath();
|
|
620 |
path1.addRect(0, 0, 100, 100);
|
|
621 |
path2.addRect(20, 20, 20, 20);
|
|
622 |
path2.addRect(25, 25, 5, 5);
|
|
623 |
QVERIFY(path1.intersects(path2));
|
|
624 |
QVERIFY(path2.intersects(path1));
|
|
625 |
QVERIFY(path1.contains(path2));
|
|
626 |
QVERIFY(!path2.contains(path1));
|
|
627 |
}
|
|
628 |
|
|
629 |
void tst_QPathClipper::testIntersections2()
|
|
630 |
{
|
|
631 |
QPainterPath path1;
|
|
632 |
QPainterPath path2;
|
|
633 |
|
|
634 |
path1 = QPainterPath();
|
|
635 |
path2 = QPainterPath();
|
|
636 |
|
|
637 |
path1.moveTo(-8,-8);
|
|
638 |
path1.lineTo(107,-8);
|
|
639 |
path1.lineTo(107,107);
|
|
640 |
path1.lineTo(-8,107);
|
|
641 |
|
|
642 |
path2.moveTo(0,0);
|
|
643 |
path2.lineTo(100,0);
|
|
644 |
path2.lineTo(100,100);
|
|
645 |
path2.lineTo(0,100);
|
|
646 |
path2.lineTo(0,0);
|
|
647 |
|
|
648 |
QVERIFY(path1.intersects(path2));
|
|
649 |
QVERIFY(path2.intersects(path1));
|
|
650 |
QVERIFY(path1.contains(path2));
|
|
651 |
QVERIFY(!path2.contains(path1));
|
|
652 |
|
|
653 |
path1.closeSubpath();
|
|
654 |
|
|
655 |
QVERIFY(path1.intersects(path2));
|
|
656 |
QVERIFY(path2.intersects(path1));
|
|
657 |
QVERIFY(path1.contains(path2));
|
|
658 |
QVERIFY(!path2.contains(path1));
|
|
659 |
}
|
|
660 |
|
|
661 |
void tst_QPathClipper::testIntersections3()
|
|
662 |
{
|
|
663 |
QPainterPath path1 = Paths::node();
|
|
664 |
QPainterPath path2 = Paths::interRect();
|
|
665 |
|
|
666 |
QVERIFY(path1.intersects(path2));
|
|
667 |
QVERIFY(path2.intersects(path1));
|
|
668 |
}
|
|
669 |
|
|
670 |
void tst_QPathClipper::testIntersections4()
|
|
671 |
{
|
|
672 |
QPainterPath path1;
|
|
673 |
QPainterPath path2;
|
|
674 |
|
|
675 |
path1.moveTo(-5, 0);
|
|
676 |
path1.lineTo(5, 0);
|
|
677 |
|
|
678 |
path2.moveTo(0, -5);
|
|
679 |
path2.lineTo(0, 5);
|
|
680 |
|
|
681 |
QVERIFY(path1.intersects(path2));
|
|
682 |
QVERIFY(path2.intersects(path1));
|
|
683 |
}
|
|
684 |
|
|
685 |
void tst_QPathClipper::testIntersections5()
|
|
686 |
{
|
|
687 |
QPainterPath path1;
|
|
688 |
QPainterPath path2;
|
|
689 |
|
|
690 |
path1.addRect(0, 0, 4, 4);
|
|
691 |
path1.addRect(2, 1, 1, 1);
|
|
692 |
path2.addRect(0.5, 2, 1, 1);
|
|
693 |
|
|
694 |
QVERIFY(path1.intersects(path2));
|
|
695 |
QVERIFY(path2.intersects(path1));
|
|
696 |
}
|
|
697 |
|
|
698 |
void tst_QPathClipper::testIntersections6()
|
|
699 |
{
|
|
700 |
QPainterPath path1;
|
|
701 |
QPainterPath path2;
|
|
702 |
|
|
703 |
path1.moveTo(QPointF(-115.567, -98.3254));
|
|
704 |
path1.lineTo(QPointF(-45.9007, -98.3254));
|
|
705 |
path1.lineTo(QPointF(-45.9007, -28.6588));
|
|
706 |
path1.lineTo(QPointF(-115.567, -28.6588));
|
|
707 |
|
|
708 |
path2.moveTo(QPointF(-110, -110));
|
|
709 |
path2.lineTo(QPointF(110, -110));
|
|
710 |
path2.lineTo(QPointF(110, 110));
|
|
711 |
path2.lineTo(QPointF(-110, 110));
|
|
712 |
path2.lineTo(QPointF(-110, -110));
|
|
713 |
|
|
714 |
QVERIFY(path1.intersects(path2));
|
|
715 |
QVERIFY(path2.intersects(path1));
|
|
716 |
}
|
|
717 |
|
|
718 |
|
|
719 |
void tst_QPathClipper::testIntersections7()
|
|
720 |
{
|
|
721 |
QPainterPath path1;
|
|
722 |
QPainterPath path2;
|
|
723 |
|
|
724 |
path1.addRect(0, 0, 10, 10);
|
|
725 |
path2.addRect(5, 0, 10, 10);
|
|
726 |
|
|
727 |
QVERIFY(path1.intersects(path2));
|
|
728 |
QVERIFY(path2.intersects(path1));
|
|
729 |
|
|
730 |
path1 = QPainterPath();
|
|
731 |
path2 = QPainterPath();
|
|
732 |
path1.addRect(0, 0, 10, 10);
|
|
733 |
path2.addRect(0, 5, 10, 10);
|
|
734 |
|
|
735 |
QVERIFY(path1.intersects(path2));
|
|
736 |
QVERIFY(path2.intersects(path1));
|
|
737 |
|
|
738 |
path1 = QPainterPath();
|
|
739 |
path2 = QPainterPath();
|
|
740 |
path1.addRect(0, 0, 10, 10);
|
|
741 |
path2.addRect(0, 0, 10, 10);
|
|
742 |
|
|
743 |
QVERIFY(path1.intersects(path2));
|
|
744 |
QVERIFY(path2.intersects(path1));
|
|
745 |
|
|
746 |
///
|
|
747 |
path1 = QPainterPath();
|
|
748 |
path2 = QPainterPath();
|
|
749 |
path1.addRect(1, 1, 10, 10);
|
|
750 |
path2.addRect(5, 1, 10, 10);
|
|
751 |
|
|
752 |
QVERIFY(path1.intersects(path2));
|
|
753 |
QVERIFY(path2.intersects(path1));
|
|
754 |
|
|
755 |
path1 = QPainterPath();
|
|
756 |
path2 = QPainterPath();
|
|
757 |
path1.addRect(1, 1, 10, 10);
|
|
758 |
path2.addRect(1, 5, 10, 10);
|
|
759 |
|
|
760 |
QVERIFY(path1.intersects(path2));
|
|
761 |
QVERIFY(path2.intersects(path1));
|
|
762 |
|
|
763 |
path1 = QPainterPath();
|
|
764 |
path2 = QPainterPath();
|
|
765 |
path1.addRect(1, 1, 10, 10);
|
|
766 |
path2.addRect(1, 1, 10, 10);
|
|
767 |
|
|
768 |
QVERIFY(path1.intersects(path2));
|
|
769 |
QVERIFY(path2.intersects(path1));
|
|
770 |
|
|
771 |
path1 = QPainterPath();
|
|
772 |
path2 = QPainterPath();
|
|
773 |
path1.addRect(1, 1, 10, 10);
|
|
774 |
path2.addRect(5, 5, 10, 10);
|
|
775 |
|
|
776 |
QVERIFY(path1.intersects(path2));
|
|
777 |
QVERIFY(path2.intersects(path1));
|
|
778 |
|
|
779 |
path1 = QPainterPath();
|
|
780 |
path2 = QPainterPath();
|
|
781 |
path1.addRect(1, 1, 10, 10);
|
|
782 |
path2.addRect(9, 9, 10, 10);
|
|
783 |
|
|
784 |
QVERIFY(path1.intersects(path2));
|
|
785 |
QVERIFY(path2.intersects(path1));
|
|
786 |
|
|
787 |
path1 = QPainterPath();
|
|
788 |
path2 = QPainterPath();
|
|
789 |
path1.addRect(1, 1, 10, 10);
|
|
790 |
path2.addRect(10, 10, 10, 10);
|
|
791 |
|
|
792 |
QVERIFY(path1.intersects(path2));
|
|
793 |
QVERIFY(path2.intersects(path1));
|
|
794 |
|
|
795 |
path1 = QPainterPath();
|
|
796 |
path2 = QPainterPath();
|
|
797 |
path1.addRect(1, 1, 9, 9);
|
|
798 |
path2.addRect(11, 11, 10, 10);
|
|
799 |
|
|
800 |
QVERIFY(!path1.intersects(path2));
|
|
801 |
QVERIFY(!path2.intersects(path1));
|
|
802 |
|
|
803 |
path1 = QPainterPath();
|
|
804 |
path2 = QPainterPath();
|
|
805 |
path1.addRect(1, 1, 10, 10);
|
|
806 |
path2.addRect(12, 12, 10, 10);
|
|
807 |
|
|
808 |
QVERIFY(!path1.intersects(path2));
|
|
809 |
QVERIFY(!path2.intersects(path1));
|
|
810 |
|
|
811 |
path1 = QPainterPath();
|
|
812 |
path2 = QPainterPath();
|
|
813 |
path1.addRect(11, 11, 10, 10);
|
|
814 |
path2.addRect(12, 12, 10, 10);
|
|
815 |
|
|
816 |
QVERIFY(path1.intersects(path2));
|
|
817 |
QVERIFY(path2.intersects(path1));
|
|
818 |
|
|
819 |
path1 = QPainterPath();
|
|
820 |
path2 = QPainterPath();
|
|
821 |
path1.addRect(11, 11, 10, 10);
|
|
822 |
path2.addRect(10, 10, 10, 10);
|
|
823 |
|
|
824 |
QVERIFY(path1.intersects(path2));
|
|
825 |
QVERIFY(path2.intersects(path1));
|
|
826 |
}
|
|
827 |
|
|
828 |
|
|
829 |
void tst_QPathClipper::testIntersections8()
|
|
830 |
{
|
|
831 |
QPainterPath path1 = Paths::node() * QTransform().translate(100, 50);
|
|
832 |
QPainterPath path2 = Paths::node() * QTransform().translate(150, 50);;
|
|
833 |
|
|
834 |
QVERIFY(path1.intersects(path2));
|
|
835 |
QVERIFY(path2.intersects(path1));
|
|
836 |
|
|
837 |
path1 = Paths::node();
|
|
838 |
path2 = Paths::node();
|
|
839 |
|
|
840 |
QVERIFY(path1.intersects(path2));
|
|
841 |
QVERIFY(path2.intersects(path1));
|
|
842 |
|
|
843 |
path1 = Paths::node();
|
|
844 |
path2 = Paths::node() * QTransform().translate(0, 30);
|
|
845 |
|
|
846 |
QVERIFY(path1.intersects(path2));
|
|
847 |
QVERIFY(path2.intersects(path1));
|
|
848 |
|
|
849 |
path1 = Paths::node();
|
|
850 |
path2 = Paths::node() * QTransform().translate(30, 0);
|
|
851 |
|
|
852 |
QVERIFY(path1.intersects(path2));
|
|
853 |
QVERIFY(path2.intersects(path1));
|
|
854 |
|
|
855 |
path1 = Paths::node();
|
|
856 |
path2 = Paths::node() * QTransform().translate(30, 30);
|
|
857 |
|
|
858 |
QVERIFY(path1.intersects(path2));
|
|
859 |
QVERIFY(path2.intersects(path1));
|
|
860 |
|
|
861 |
path1 = Paths::node();
|
|
862 |
path2 = Paths::node() * QTransform().translate(1, 1);
|
|
863 |
|
|
864 |
QVERIFY(path1.intersects(path2));
|
|
865 |
QVERIFY(path2.intersects(path1));
|
|
866 |
}
|
|
867 |
|
|
868 |
|
|
869 |
void tst_QPathClipper::testIntersections9()
|
|
870 |
{
|
|
871 |
QPainterPath path1;
|
|
872 |
QPainterPath path2;
|
|
873 |
|
|
874 |
path1.addRect(QRectF(-1,143, 146, 106));
|
|
875 |
path2.addRect(QRectF(-9,145, 150, 100));
|
|
876 |
|
|
877 |
QVERIFY(path1.intersects(path2));
|
|
878 |
QVERIFY(path2.intersects(path1));
|
|
879 |
|
|
880 |
path1 = QPainterPath();;
|
|
881 |
path2 = QPainterPath();
|
|
882 |
|
|
883 |
path1.addRect(QRectF(-1,191, 136, 106));
|
|
884 |
path2.addRect(QRectF(-19,194, 150, 100));
|
|
885 |
QVERIFY(path1.intersects(path2));
|
|
886 |
QVERIFY(path2.intersects(path1));
|
|
887 |
|
|
888 |
path1 = QPainterPath();;
|
|
889 |
path2 = QPainterPath();
|
|
890 |
|
|
891 |
path1.moveTo(-1 , 143);
|
|
892 |
path1.lineTo(148 , 143);
|
|
893 |
path1.lineTo(148 , 250);
|
|
894 |
path1.lineTo(-1 , 250);
|
|
895 |
|
|
896 |
path2.moveTo(-5 , 146);
|
|
897 |
path2.lineTo(145 , 146);
|
|
898 |
path2.lineTo(145 , 246);
|
|
899 |
path2.lineTo(-5 , 246);
|
|
900 |
path2.lineTo(-5 , 146);
|
|
901 |
|
|
902 |
QVERIFY(path1.intersects(path2));
|
|
903 |
QVERIFY(path2.intersects(path1));
|
|
904 |
}
|
|
905 |
|
|
906 |
QPainterPath pathFromRect(qreal x, qreal y, qreal w, qreal h)
|
|
907 |
{
|
|
908 |
QPainterPath path;
|
|
909 |
path.addRect(QRectF(x, y, w, h));
|
|
910 |
return path;
|
|
911 |
}
|
|
912 |
|
|
913 |
QPainterPath pathFromLine(qreal x1, qreal y1, qreal x2, qreal y2)
|
|
914 |
{
|
|
915 |
QPainterPath path;
|
|
916 |
path.moveTo(x1, y1);
|
|
917 |
path.lineTo(x2, y2);
|
|
918 |
return path;
|
|
919 |
}
|
|
920 |
|
|
921 |
static int loopLength(const QWingedEdge &list, QWingedEdge::TraversalStatus status)
|
|
922 |
{
|
|
923 |
int start = status.edge;
|
|
924 |
|
|
925 |
int length = 0;
|
|
926 |
do {
|
|
927 |
++length;
|
|
928 |
status = list.next(status);
|
|
929 |
} while (status.edge != start);
|
|
930 |
|
|
931 |
return length;
|
|
932 |
}
|
|
933 |
|
|
934 |
void tst_QPathClipper::testWingedEdge()
|
|
935 |
{
|
|
936 |
{
|
|
937 |
QWingedEdge list;
|
|
938 |
int e1 = list.addEdge(QPointF(0, 0), QPointF(10, 0));
|
|
939 |
int e2 = list.addEdge(QPointF(0, 0), QPointF(0, 10));
|
|
940 |
int e3 = list.addEdge(QPointF(0, 0), QPointF(-10, 0));
|
|
941 |
int e4 = list.addEdge(QPointF(0, 0), QPointF(0, -10));
|
|
942 |
|
|
943 |
QCOMPARE(list.edgeCount(), 4);
|
|
944 |
QCOMPARE(list.vertexCount(), 5);
|
|
945 |
|
|
946 |
QWingedEdge::TraversalStatus status = { e1, QPathEdge::RightTraversal, QPathEdge::Forward };
|
|
947 |
|
|
948 |
status = list.next(status);
|
|
949 |
QCOMPARE(status.direction, QPathEdge::Backward);
|
|
950 |
QCOMPARE(status.traversal, QPathEdge::LeftTraversal);
|
|
951 |
QCOMPARE(status.edge, e1);
|
|
952 |
|
|
953 |
status = list.next(status);
|
|
954 |
QCOMPARE(status.direction, QPathEdge::Forward);
|
|
955 |
QCOMPARE(status.traversal, QPathEdge::RightTraversal);
|
|
956 |
QCOMPARE(status.edge, e4);
|
|
957 |
|
|
958 |
status = list.next(status);
|
|
959 |
QCOMPARE(status.direction, QPathEdge::Backward);
|
|
960 |
QCOMPARE(status.traversal, QPathEdge::LeftTraversal);
|
|
961 |
QCOMPARE(status.edge, e4);
|
|
962 |
|
|
963 |
status = list.next(status);
|
|
964 |
QCOMPARE(status.direction, QPathEdge::Forward);
|
|
965 |
QCOMPARE(status.traversal, QPathEdge::RightTraversal);
|
|
966 |
QCOMPARE(status.edge, e3);
|
|
967 |
|
|
968 |
status = list.next(status);
|
|
969 |
QCOMPARE(status.direction, QPathEdge::Backward);
|
|
970 |
QCOMPARE(status.traversal, QPathEdge::LeftTraversal);
|
|
971 |
QCOMPARE(status.edge, e3);
|
|
972 |
|
|
973 |
status = list.next(status);
|
|
974 |
QCOMPARE(status.direction, QPathEdge::Forward);
|
|
975 |
QCOMPARE(status.traversal, QPathEdge::RightTraversal);
|
|
976 |
QCOMPARE(status.edge, e2);
|
|
977 |
|
|
978 |
status = list.next(status);
|
|
979 |
QCOMPARE(status.direction, QPathEdge::Backward);
|
|
980 |
QCOMPARE(status.traversal, QPathEdge::LeftTraversal);
|
|
981 |
QCOMPARE(status.edge, e2);
|
|
982 |
|
|
983 |
status = list.next(status);
|
|
984 |
QCOMPARE(status.direction, QPathEdge::Forward);
|
|
985 |
QCOMPARE(status.traversal, QPathEdge::RightTraversal);
|
|
986 |
QCOMPARE(status.edge, e1);
|
|
987 |
}
|
|
988 |
{
|
|
989 |
QWingedEdge list;
|
|
990 |
int e1 = list.addEdge(QPointF(5, 0), QPointF(5, 10));
|
|
991 |
int e2 = list.addEdge(QPointF(5, 0), QPointF(10, 5));
|
|
992 |
int e3 = list.addEdge(QPointF(10, 5), QPointF(5, 10));
|
|
993 |
int e4 = list.addEdge(QPointF(5, 0), QPointF(0, 5));
|
|
994 |
int e5 = list.addEdge(QPointF(0, 5), QPointF(5, 10));
|
|
995 |
|
|
996 |
QCOMPARE(list.edgeCount(), 5);
|
|
997 |
QCOMPARE(list.vertexCount(), 4);
|
|
998 |
|
|
999 |
QWingedEdge::TraversalStatus status = { e1, QPathEdge::RightTraversal, QPathEdge::Forward };
|
|
1000 |
|
|
1001 |
status = list.next(status);
|
|
1002 |
QCOMPARE(status.direction, QPathEdge::Backward);
|
|
1003 |
QCOMPARE(status.traversal, QPathEdge::LeftTraversal);
|
|
1004 |
QCOMPARE(status.edge, e5);
|
|
1005 |
|
|
1006 |
status = list.next(status);
|
|
1007 |
QCOMPARE(status.direction, QPathEdge::Backward);
|
|
1008 |
QCOMPARE(status.traversal, QPathEdge::LeftTraversal);
|
|
1009 |
QCOMPARE(status.edge, e4);
|
|
1010 |
|
|
1011 |
status = list.next(status);
|
|
1012 |
QCOMPARE(status.direction, QPathEdge::Forward);
|
|
1013 |
QCOMPARE(status.traversal, QPathEdge::RightTraversal);
|
|
1014 |
QCOMPARE(status.edge, e1);
|
|
1015 |
|
|
1016 |
QCOMPARE(loopLength(list, status), 3);
|
|
1017 |
|
|
1018 |
status.flip();
|
|
1019 |
QCOMPARE(status.direction, QPathEdge::Backward);
|
|
1020 |
QCOMPARE(status.traversal, QPathEdge::LeftTraversal);
|
|
1021 |
QCOMPARE(loopLength(list, status), 3);
|
|
1022 |
|
|
1023 |
status = list.next(status);
|
|
1024 |
QCOMPARE(status.direction, QPathEdge::Forward);
|
|
1025 |
QCOMPARE(status.traversal, QPathEdge::RightTraversal);
|
|
1026 |
QCOMPARE(status.edge, e2);
|
|
1027 |
|
|
1028 |
status = list.next(status);
|
|
1029 |
QCOMPARE(status.direction, QPathEdge::Forward);
|
|
1030 |
QCOMPARE(status.traversal, QPathEdge::RightTraversal);
|
|
1031 |
QCOMPARE(status.edge, e3);
|
|
1032 |
|
|
1033 |
status = list.next(status);
|
|
1034 |
QCOMPARE(status.direction, QPathEdge::Backward);
|
|
1035 |
QCOMPARE(status.traversal, QPathEdge::LeftTraversal);
|
|
1036 |
QCOMPARE(status.edge, e1);
|
|
1037 |
|
|
1038 |
status = list.next(status);
|
|
1039 |
status.flip();
|
|
1040 |
QCOMPARE(status.direction, QPathEdge::Backward);
|
|
1041 |
QCOMPARE(status.traversal, QPathEdge::LeftTraversal);
|
|
1042 |
QCOMPARE(status.edge, e2);
|
|
1043 |
QCOMPARE(loopLength(list, status), 4);
|
|
1044 |
|
|
1045 |
status = list.next(status);
|
|
1046 |
QCOMPARE(status.direction, QPathEdge::Forward);
|
|
1047 |
QCOMPARE(status.traversal, QPathEdge::RightTraversal);
|
|
1048 |
QCOMPARE(status.edge, e4);
|
|
1049 |
|
|
1050 |
status = list.next(status);
|
|
1051 |
QCOMPARE(status.direction, QPathEdge::Forward);
|
|
1052 |
QCOMPARE(status.traversal, QPathEdge::RightTraversal);
|
|
1053 |
QCOMPARE(status.edge, e5);
|
|
1054 |
|
|
1055 |
status = list.next(status);
|
|
1056 |
QCOMPARE(status.direction, QPathEdge::Backward);
|
|
1057 |
QCOMPARE(status.traversal, QPathEdge::LeftTraversal);
|
|
1058 |
QCOMPARE(status.edge, e3);
|
|
1059 |
|
|
1060 |
status = list.next(status);
|
|
1061 |
QCOMPARE(status.direction, QPathEdge::Backward);
|
|
1062 |
QCOMPARE(status.traversal, QPathEdge::LeftTraversal);
|
|
1063 |
QCOMPARE(status.edge, e2);
|
|
1064 |
}
|
|
1065 |
{
|
|
1066 |
QPainterPath path = pathFromRect(0, 0, 20, 20);
|
|
1067 |
QWingedEdge list(path, QPainterPath());
|
|
1068 |
|
|
1069 |
QCOMPARE(list.edgeCount(), 4);
|
|
1070 |
QCOMPARE(list.vertexCount(), 4);
|
|
1071 |
|
|
1072 |
QWingedEdge::TraversalStatus status = { 0, QPathEdge::RightTraversal, QPathEdge::Forward };
|
|
1073 |
|
|
1074 |
QPathEdge *edge = list.edge(status.edge);
|
|
1075 |
QCOMPARE(QPointF(*list.vertex(edge->first)), QPointF(0, 0));
|
|
1076 |
QCOMPARE(QPointF(*list.vertex(edge->second)), QPointF(20, 0));
|
|
1077 |
|
|
1078 |
status = list.next(status);
|
|
1079 |
QCOMPARE(status.edge, 1);
|
|
1080 |
|
|
1081 |
status = list.next(status);
|
|
1082 |
QCOMPARE(status.edge, 2);
|
|
1083 |
|
|
1084 |
status = list.next(status);
|
|
1085 |
QCOMPARE(status.edge, 3);
|
|
1086 |
|
|
1087 |
status = list.next(status);
|
|
1088 |
QCOMPARE(status.edge, 0);
|
|
1089 |
|
|
1090 |
status.flipDirection();
|
|
1091 |
status = list.next(status);
|
|
1092 |
QCOMPARE(status.edge, 3);
|
|
1093 |
|
|
1094 |
status = list.next(status);
|
|
1095 |
QCOMPARE(status.edge, 2);
|
|
1096 |
|
|
1097 |
status = list.next(status);
|
|
1098 |
QCOMPARE(status.edge, 1);
|
|
1099 |
|
|
1100 |
status = list.next(status);
|
|
1101 |
QCOMPARE(status.edge, 0);
|
|
1102 |
|
|
1103 |
QWingedEdge list2(path, pathFromRect(10, 5, 20, 10));
|
|
1104 |
|
|
1105 |
QCOMPARE(list2.edgeCount(), 12);
|
|
1106 |
QCOMPARE(list2.vertexCount(), 10);
|
|
1107 |
|
|
1108 |
status.flipDirection();
|
|
1109 |
QCOMPARE(loopLength(list2, status), 8);
|
|
1110 |
|
|
1111 |
status = list2.next(status);
|
|
1112 |
edge = list2.edge(status.edge);
|
|
1113 |
QCOMPARE(QPointF(*list2.vertex(edge->first)), QPointF(20, 0));
|
|
1114 |
QCOMPARE(QPointF(*list2.vertex(edge->second)), QPointF(20, 5));
|
|
1115 |
|
|
1116 |
status = list2.next(status);
|
|
1117 |
status.flipTraversal();
|
|
1118 |
|
|
1119 |
edge = list2.edge(status.edge);
|
|
1120 |
QCOMPARE(QPointF(*list2.vertex(edge->first)), QPointF(10, 5));
|
|
1121 |
QCOMPARE(QPointF(*list2.vertex(edge->second)), QPointF(20, 5));
|
|
1122 |
|
|
1123 |
QCOMPARE(loopLength(list2, status), 4);
|
|
1124 |
|
|
1125 |
status.flipDirection();
|
|
1126 |
status = list2.next(status);
|
|
1127 |
status.flipTraversal();
|
|
1128 |
|
|
1129 |
edge = list2.edge(status.edge);
|
|
1130 |
QCOMPARE(QPointF(*list2.vertex(edge->first)), QPointF(20, 5));
|
|
1131 |
QCOMPARE(QPointF(*list2.vertex(edge->second)), QPointF(20, 15));
|
|
1132 |
|
|
1133 |
QCOMPARE(loopLength(list2, status), 4);
|
|
1134 |
status = list2.next(status);
|
|
1135 |
status = list2.next(status);
|
|
1136 |
|
|
1137 |
edge = list2.edge(status.edge);
|
|
1138 |
QCOMPARE(QPointF(*list2.vertex(edge->first)), QPointF(30, 5));
|
|
1139 |
QCOMPARE(QPointF(*list2.vertex(edge->second)), QPointF(30, 15));
|
|
1140 |
}
|
|
1141 |
}
|
|
1142 |
|
|
1143 |
void tst_QPathClipper::zeroDerivativeCurves()
|
|
1144 |
{
|
|
1145 |
// zero derivative at end
|
|
1146 |
{
|
|
1147 |
QPainterPath a;
|
|
1148 |
a.cubicTo(100, 0, 100, 100, 100, 100);
|
|
1149 |
a.lineTo(100, 200);
|
|
1150 |
a.lineTo(0, 200);
|
|
1151 |
|
|
1152 |
QPainterPath b;
|
|
1153 |
b.moveTo(50, 100);
|
|
1154 |
b.lineTo(150, 100);
|
|
1155 |
b.lineTo(150, 150);
|
|
1156 |
b.lineTo(50, 150);
|
|
1157 |
|
|
1158 |
QPainterPath c = a.united(b);
|
|
1159 |
QVERIFY(c.contains(QPointF(25, 125)));
|
|
1160 |
QVERIFY(c.contains(QPointF(75, 125)));
|
|
1161 |
QVERIFY(c.contains(QPointF(125, 125)));
|
|
1162 |
}
|
|
1163 |
|
|
1164 |
// zero derivative at start
|
|
1165 |
{
|
|
1166 |
QPainterPath a;
|
|
1167 |
a.cubicTo(100, 0, 100, 100, 100, 100);
|
|
1168 |
a.lineTo(100, 200);
|
|
1169 |
a.lineTo(0, 200);
|
|
1170 |
|
|
1171 |
QPainterPath b;
|
|
1172 |
b.moveTo(50, 100);
|
|
1173 |
b.lineTo(150, 100);
|
|
1174 |
b.lineTo(150, 150);
|
|
1175 |
b.lineTo(50, 150);
|
|
1176 |
|
|
1177 |
QPainterPath c = a.united(b);
|
|
1178 |
QVERIFY(c.contains(QPointF(25, 125)));
|
|
1179 |
QVERIFY(c.contains(QPointF(75, 125)));
|
|
1180 |
QVERIFY(c.contains(QPointF(125, 125)));
|
|
1181 |
}
|
|
1182 |
}
|
|
1183 |
|
|
1184 |
static bool strictContains(const QPainterPath &a, const QPainterPath &b)
|
|
1185 |
{
|
|
1186 |
return b.subtracted(a) == QPainterPath();
|
|
1187 |
}
|
|
1188 |
|
|
1189 |
Q_DECLARE_METATYPE(QPolygonF)
|
|
1190 |
|
|
1191 |
void tst_QPathClipper::task204301_data()
|
|
1192 |
{
|
|
1193 |
QTest::addColumn<QPolygonF>("points");
|
|
1194 |
|
|
1195 |
{
|
|
1196 |
QPointF a(51.09013255685567855835, 31.30814891308546066284);
|
|
1197 |
QPointF b(98.39898971840739250183, 11.02079074829816818237);
|
|
1198 |
QPointF c(91.23911846894770860672, 45.86981737054884433746);
|
|
1199 |
QPointF d(66.58616356085985898972, 63.10526528395712375641);
|
|
1200 |
QPointF e(82.08219456479714892794, 94.90238165489137145414);
|
|
1201 |
QPointF f(16.09013040543221251255, 105.66263409332729850121);
|
|
1202 |
QPointF g(10.62811442650854587555, 65.09154842235147953033);
|
|
1203 |
QPointF h(5.16609844751656055450, 24.52046275138854980469);
|
|
1204 |
QPolygonF v;
|
|
1205 |
v << a << b << c << d << e << f << g << h;
|
|
1206 |
QTest::newRow("failed_on_linux") << v;
|
|
1207 |
}
|
|
1208 |
|
|
1209 |
{
|
|
1210 |
QPointF a(50.014648437500000, 24.392089843750000);
|
|
1211 |
QPointF b(92.836303710937500, 5.548706054687500);
|
|
1212 |
QPointF c(92.145690917968750, 54.390258789062500);
|
|
1213 |
QPointF d(65.402221679687500, 74.345092773437500);
|
|
1214 |
QPointF e(80.789794921787347, 124.298095703129690);
|
|
1215 |
QPointF f(34.961242675812954, 87.621459960852135);
|
|
1216 |
QPointF g(18.305969238281250, 57.426757812500000);
|
|
1217 |
QPointF h(1.650695800781250, 27.232055664062500);
|
|
1218 |
QPolygonF v;
|
|
1219 |
v << a << b << c << d << e << f << g << h;
|
|
1220 |
QTest::newRow("failed_on_windows") << v;
|
|
1221 |
}
|
|
1222 |
}
|
|
1223 |
|
|
1224 |
void tst_QPathClipper::task204301()
|
|
1225 |
{
|
|
1226 |
QFETCH(QPolygonF, points);
|
|
1227 |
|
|
1228 |
QPointF a = points[0];
|
|
1229 |
QPointF b = points[1];
|
|
1230 |
QPointF c = points[2];
|
|
1231 |
QPointF d = points[3];
|
|
1232 |
QPointF e = points[4];
|
|
1233 |
QPointF f = points[5];
|
|
1234 |
QPointF g = points[6];
|
|
1235 |
QPointF h = points[7];
|
|
1236 |
|
|
1237 |
QPainterPath subA;
|
|
1238 |
subA.addPolygon(QPolygonF() << a << b << c << d);
|
|
1239 |
subA.closeSubpath();
|
|
1240 |
|
|
1241 |
QPainterPath subB;
|
|
1242 |
subB.addPolygon(QPolygonF() << f << e << d << g);
|
|
1243 |
subB.closeSubpath();
|
|
1244 |
|
|
1245 |
QPainterPath subC;
|
|
1246 |
subC.addPolygon(QPolygonF() << h << a << d << g);
|
|
1247 |
subC.closeSubpath();
|
|
1248 |
|
|
1249 |
QPainterPath path;
|
|
1250 |
path.addPath(subA);
|
|
1251 |
path.addPath(subB);
|
|
1252 |
path.addPath(subC);
|
|
1253 |
|
|
1254 |
QPainterPath simplified = path.simplified();
|
|
1255 |
|
|
1256 |
QVERIFY(strictContains(simplified, subA));
|
|
1257 |
QVERIFY(strictContains(simplified, subB));
|
|
1258 |
QVERIFY(strictContains(simplified, subC));
|
|
1259 |
}
|
|
1260 |
|
|
1261 |
void tst_QPathClipper::task209056()
|
|
1262 |
{
|
|
1263 |
QPainterPath p1;
|
|
1264 |
p1.moveTo( QPointF(188.506, 287.793) );
|
|
1265 |
p1.lineTo( QPointF(288.506, 287.793) );
|
|
1266 |
p1.lineTo( QPointF(288.506, 387.793) );
|
|
1267 |
p1.lineTo( QPointF(188.506, 387.793) );
|
|
1268 |
p1.lineTo( QPointF(188.506, 287.793) );
|
|
1269 |
|
|
1270 |
QPainterPath p2;
|
|
1271 |
p2.moveTo( QPointF(419.447, 164.383) );
|
|
1272 |
p2.cubicTo( QPointF(419.447, 69.5486), QPointF(419.447, 259.218),QPointF(419.447, 164.383) );
|
|
1273 |
|
|
1274 |
p2.cubicTo( QPointF(48.9378, 259.218), QPointF(131.879, 336.097),QPointF(234.192, 336.097) );
|
|
1275 |
p2.cubicTo( QPointF(336.506, 336.097), QPointF(419.447, 259.218),QPointF(419.447, 164.383) );
|
|
1276 |
|
|
1277 |
QPainterPath p3 = p1.intersected(p2);
|
|
1278 |
|
|
1279 |
QVERIFY(p3 != QPainterPath());
|
|
1280 |
}
|
|
1281 |
|
|
1282 |
void tst_QPathClipper::task251909()
|
|
1283 |
{
|
|
1284 |
QPainterPath p1;
|
|
1285 |
p1.moveTo(0, -10);
|
|
1286 |
p1.lineTo(10, -10);
|
|
1287 |
p1.lineTo(10, 0);
|
|
1288 |
p1.lineTo(0, 0);
|
|
1289 |
|
|
1290 |
QPainterPath p2;
|
|
1291 |
p2.moveTo(0, 8e-14);
|
|
1292 |
p2.lineTo(10, -8e-14);
|
|
1293 |
p2.lineTo(10, 10);
|
|
1294 |
p2.lineTo(0, 10);
|
|
1295 |
|
|
1296 |
QPainterPath result = p1.united(p2);
|
|
1297 |
|
|
1298 |
QVERIFY(result.elementCount() <= 5);
|
|
1299 |
}
|
|
1300 |
|
30
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
1301 |
void tst_QPathClipper::qtbug3778()
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
1302 |
{
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
1303 |
QPainterPath path1;
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
1304 |
path1.moveTo(200, 3.22409e-5);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
1305 |
// e-5 and higher leads to a bug
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
1306 |
// Using 3.22409e-4 starts to work correctly
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
1307 |
path1.lineTo(0, 0);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
1308 |
path1.lineTo(1.07025e-13, 1450);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
1309 |
path1.lineTo(750, 950);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
1310 |
path1.lineTo(950, 750);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
1311 |
path1.lineTo(200, 3.22409e-13);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
1312 |
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
1313 |
QPainterPath path2;
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
1314 |
path2.moveTo(0, 0);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
1315 |
path2.lineTo(200, 800);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
1316 |
path2.lineTo(600, 1500);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
1317 |
path2.lineTo(1500, 1400);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
1318 |
path2.lineTo(1900, 1200);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
1319 |
path2.lineTo(2000, 1000);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
1320 |
path2.lineTo(1400, 0);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
1321 |
path2.lineTo(0, 0);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
1322 |
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
1323 |
QPainterPath p12 = path1.intersected(path2);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
1324 |
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
1325 |
QVERIFY(p12.contains(QPointF(100, 100)));
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
1326 |
}
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
1327 |
|
0
|
1328 |
QTEST_APPLESS_MAIN(tst_QPathClipper)
|
|
1329 |
|
|
1330 |
|
|
1331 |
#include "tst_qpathclipper.moc"
|