painting/qpolygon.cpp

Source codeSwitch to Preprocessed file
LineSource CodeCoverage
1/**************************************************************************** -
2** -
3** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -
4** Contact: http://www.qt-project.org/legal -
5** -
6** This file is part of the QtGui module of the Qt Toolkit. -
7** -
8** $QT_BEGIN_LICENSE:LGPL$ -
9** Commercial License Usage -
10** Licensees holding valid commercial Qt licenses may use this file in -
11** accordance with the commercial license agreement provided with the -
12** Software or, alternatively, in accordance with the terms contained in -
13** a written agreement between you and Digia. For licensing terms and -
14** conditions see http://qt.digia.com/licensing. For further information -
15** use the contact form at http://qt.digia.com/contact-us. -
16** -
17** GNU Lesser General Public License Usage -
18** Alternatively, this file may be used under the terms of the GNU Lesser -
19** General Public License version 2.1 as published by the Free Software -
20** Foundation and appearing in the file LICENSE.LGPL included in the -
21** packaging of this file. Please review the following information to -
22** ensure the GNU Lesser General Public License version 2.1 requirements -
23** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -
24** -
25** In addition, as a special exception, Digia gives you certain additional -
26** rights. These rights are described in the Digia Qt LGPL Exception -
27** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -
28** -
29** GNU General Public License Usage -
30** Alternatively, this file may be used under the terms of the GNU -
31** General Public License version 3.0 as published by the Free Software -
32** Foundation and appearing in the file LICENSE.GPL included in the -
33** packaging of this file. Please review the following information to -
34** ensure the GNU General Public License version 3.0 requirements will be -
35** met: http://www.gnu.org/copyleft/gpl.html. -
36** -
37** -
38** $QT_END_LICENSE$ -
39** -
40****************************************************************************/ -
41 -
42#include "qpolygon.h" -
43#include "qrect.h" -
44#include "qdatastream.h" -
45#include "qmatrix.h" -
46#include "qdebug.h" -
47#include "qpainterpath.h" -
48#include "qvariant.h" -
49#include "qpainterpath_p.h" -
50#include "qbezier_p.h" -
51 -
52#include <stdarg.h> -
53 -
54QT_BEGIN_NAMESPACE -
55 -
56//same as qt_painterpath_isect_line in qpainterpath.cpp -
57static void qt_polygon_isect_line(const QPointF &p1, const QPointF &p2, const QPointF &pos, -
58 int *winding) -
59{ -
60 qreal x1 = p1.x();
never executed (the execution status of this line is deduced): qreal x1 = p1.x();
-
61 qreal y1 = p1.y();
never executed (the execution status of this line is deduced): qreal y1 = p1.y();
-
62 qreal x2 = p2.x();
never executed (the execution status of this line is deduced): qreal x2 = p2.x();
-
63 qreal y2 = p2.y();
never executed (the execution status of this line is deduced): qreal y2 = p2.y();
-
64 qreal y = pos.y();
never executed (the execution status of this line is deduced): qreal y = pos.y();
-
65 -
66 int dir = 1;
never executed (the execution status of this line is deduced): int dir = 1;
-
67 -
68 if (qFuzzyCompare(y1, y2)) {
never evaluated: qFuzzyCompare(y1, y2)
0
69 // ignore horizontal lines according to scan conversion rule -
70 return;
never executed: return;
0
71 } else if (y2 < y1) {
never evaluated: y2 < y1
0
72 qreal x_tmp = x2; x2 = x1; x1 = x_tmp;
never executed (the execution status of this line is deduced): qreal x_tmp = x2; x2 = x1; x1 = x_tmp;
-
73 qreal y_tmp = y2; y2 = y1; y1 = y_tmp;
never executed (the execution status of this line is deduced): qreal y_tmp = y2; y2 = y1; y1 = y_tmp;
-
74 dir = -1;
never executed (the execution status of this line is deduced): dir = -1;
-
75 }
never executed: }
0
76 -
77 if (y >= y1 && y < y2) {
never evaluated: y >= y1
never evaluated: y < y2
0
78 qreal x = x1 + ((x2 - x1) / (y2 - y1)) * (y - y1);
never executed (the execution status of this line is deduced): qreal x = x1 + ((x2 - x1) / (y2 - y1)) * (y - y1);
-
79 -
80 // count up the winding number if we're -
81 if (x<=pos.x()) {
never evaluated: x<=pos.x()
0
82 (*winding) += dir;
never executed (the execution status of this line is deduced): (*winding) += dir;
-
83 }
never executed: }
0
84 }
never executed: }
0
85}
never executed: }
0
86 -
87/*! -
88 \class QPolygon -
89 \brief The QPolygon class provides a vector of points using -
90 integer precision. -
91 \inmodule QtGui -
92 -
93 \reentrant -
94 -
95 \ingroup painting -
96 \ingroup shared -
97 -
98 A QPolygon object is a QVector<QPoint>. The easiest way to add -
99 points to a QPolygon is to use QVector's streaming operator, as -
100 illustrated below: -
101 -
102 \snippet polygon/polygon.cpp 0 -
103 -
104 In addition to the functions provided by QVector, QPolygon -
105 provides some point-specific functions. -
106 -
107 Each point in a polygon can be retrieved by passing its index to -
108 the point() function. To populate the polygon, QPolygon provides -
109 the setPoint() function to set the point at a given index, the -
110 setPoints() function to set all the points in the polygon -
111 (resizing it to the given number of points), and the putPoints() -
112 function which copies a number of given points into the polygon -
113 from a specified index (resizing the polygon if necessary). -
114 -
115 QPolygon provides the boundingRect() and translate() functions for -
116 geometry functions. Use the QMatrix::map() function for more -
117 general transformations of QPolygons. -
118 -
119 The QPolygon class is \l {Implicit Data Sharing}{implicitly -
120 shared}. -
121 -
122 \sa QVector, QPolygonF, QLine -
123*/ -
124 -
125 -
126/***************************************************************************** -
127 QPolygon member functions -
128 *****************************************************************************/ -
129 -
130/*! -
131 \fn QPolygon::QPolygon() -
132 -
133 Constructs a polygon with no points. -
134 -
135 \sa QVector::isEmpty() -
136*/ -
137 -
138/*! -
139 \fn QPolygon::QPolygon(int size) -
140 -
141 Constructs a polygon of the given \a size. Creates an empty -
142 polygon if \a size == 0. -
143 -
144 \sa QVector::isEmpty() -
145*/ -
146 -
147/*! -
148 \fn QPolygon::QPolygon(const QPolygon &polygon) -
149 -
150 Constructs a copy of the given \a polygon. -
151 -
152 \sa setPoints() -
153*/ -
154 -
155/*! -
156 \fn QPolygon::QPolygon(const QVector<QPoint> &points) -
157 -
158 Constructs a polygon containing the specified \a points. -
159 -
160 \sa setPoints() -
161*/ -
162 -
163/*! -
164 \fn QPolygon::QPolygon(const QRect &rectangle, bool closed) -
165 -
166 Constructs a polygon from the given \a rectangle. If \a closed is -
167 false, the polygon just contains the four points of the rectangle -
168 ordered clockwise, otherwise the polygon's fifth point is set to -
169 \a {rectangle}.topLeft(). -
170 -
171 Note that the bottom-right corner of the rectangle is located at -
172 (rectangle.x() + rectangle.width(), rectangle.y() + -
173 rectangle.height()). -
174 -
175 \sa setPoints() -
176*/ -
177 -
178QPolygon::QPolygon(const QRect &r, bool closed) -
179{ -
180 reserve(closed ? 5 : 4);
executed (the execution status of this line is deduced): reserve(closed ? 5 : 4);
-
181 *this << QPoint(r.x(), r.y())
executed (the execution status of this line is deduced): *this << QPoint(r.x(), r.y())
-
182 << QPoint(r.x() + r.width(), r.y())
executed (the execution status of this line is deduced): << QPoint(r.x() + r.width(), r.y())
-
183 << QPoint(r.x() + r.width(), r.y() + r.height())
executed (the execution status of this line is deduced): << QPoint(r.x() + r.width(), r.y() + r.height())
-
184 << QPoint(r.x(), r.y() + r.height());
executed (the execution status of this line is deduced): << QPoint(r.x(), r.y() + r.height());
-
185 if (closed)
evaluated: closed
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:119
2-119
186 *this << QPoint(r.left(), r.top());
executed: *this << QPoint(r.left(), r.top());
Execution Count:2
2
187}
executed: }
Execution Count:121
121
188 -
189/*! -
190 \internal -
191 Constructs a point array with \a nPoints points, taken from the -
192 \a points array. -
193 -
194 Equivalent to setPoints(nPoints, points). -
195*/ -
196 -
197QPolygon::QPolygon(int nPoints, const int *points) -
198{ -
199 setPoints(nPoints, points);
never executed (the execution status of this line is deduced): setPoints(nPoints, points);
-
200}
never executed: }
0
201 -
202 -
203/*! -
204 \fn QPolygon::~QPolygon() -
205 -
206 Destroys the polygon. -
207*/ -
208 -
209 -
210/*! -
211 Translates all points in the polygon by (\a{dx}, \a{dy}). -
212 -
213 \sa translated() -
214*/ -
215 -
216void QPolygon::translate(int dx, int dy) -
217{ -
218 if (dx == 0 && dy == 0)
never evaluated: dx == 0
never evaluated: dy == 0
0
219 return;
never executed: return;
0
220 -
221 register QPoint *p = data();
never executed (the execution status of this line is deduced): register QPoint *p = data();
-
222 register int i = size();
never executed (the execution status of this line is deduced): register int i = size();
-
223 QPoint pt(dx, dy);
never executed (the execution status of this line is deduced): QPoint pt(dx, dy);
-
224 while (i--) {
never evaluated: i--
0
225 *p += pt;
never executed (the execution status of this line is deduced): *p += pt;
-
226 ++p;
never executed (the execution status of this line is deduced): ++p;
-
227 }
never executed: }
0
228}
never executed: }
0
229 -
230/*! -
231 \fn void QPolygon::translate(const QPoint &offset) -
232 \overload -
233 -
234 Translates all points in the polygon by the given \a offset. -
235 -
236 \sa translated() -
237*/ -
238 -
239/*! -
240 Returns a copy of the polygon that is translated by (\a{dx}, \a{dy}). -
241 -
242 \since 4.6 -
243 \sa translate() -
244*/ -
245QPolygon QPolygon::translated(int dx, int dy) const -
246{ -
247 QPolygon copy(*this);
never executed (the execution status of this line is deduced): QPolygon copy(*this);
-
248 copy.translate(dx, dy);
never executed (the execution status of this line is deduced): copy.translate(dx, dy);
-
249 return copy;
never executed: return copy;
0
250} -
251 -
252/*! -
253 \fn void QPolygon::translated(const QPoint &offset) const -
254 \overload -
255 \since 4.6 -
256 -
257 Returns a copy of the polygon that is translated by the given \a offset. -
258 -
259 \sa translate() -
260*/ -
261 -
262/*! -
263 Extracts the coordinates of the point at the given \a index to -
264 *\a{x} and *\a{y} (if they are valid pointers). -
265 -
266 \sa setPoint() -
267*/ -
268 -
269void QPolygon::point(int index, int *x, int *y) const -
270{ -
271 QPoint p = at(index);
never executed (the execution status of this line is deduced): QPoint p = at(index);
-
272 if (x)
never evaluated: x
0
273 *x = (int)p.x();
never executed: *x = (int)p.x();
0
274 if (y)
never evaluated: y
0
275 *y = (int)p.y();
never executed: *y = (int)p.y();
0
276}
never executed: }
0
277 -
278/*! -
279 \fn QPoint QPolygon::point(int index) const -
280 \overload -
281 -
282 Returns the point at the given \a index. -
283*/ -
284 -
285/*! -
286 \fn void QPolygon::setPoint(int index, const QPoint &point) -
287 \overload -
288 -
289 Sets the point at the given \a index to the given \a point. -
290*/ -
291 -
292/*! -
293 \fn void QPolygon::setPoint(int index, int x, int y) -
294 -
295 Sets the point at the given \a index to the point specified by -
296 (\a{x}, \a{y}). -
297 -
298 \sa point(), putPoints(), setPoints(), -
299*/ -
300 -
301/*! -
302 Resizes the polygon to \a nPoints and populates it with the given -
303 \a points. -
304 -
305 The example code creates a polygon with two points (10, 20) and -
306 (30, 40): -
307 -
308 \snippet polygon/polygon.cpp 2 -
309 -
310 \sa setPoint(), putPoints() -
311*/ -
312 -
313void QPolygon::setPoints(int nPoints, const int *points) -
314{ -
315 resize(nPoints);
never executed (the execution status of this line is deduced): resize(nPoints);
-
316 int i = 0;
never executed (the execution status of this line is deduced): int i = 0;
-
317 while (nPoints--) {
never evaluated: nPoints--
0
318 setPoint(i++, *points, *(points+1));
never executed (the execution status of this line is deduced): setPoint(i++, *points, *(points+1));
-
319 points += 2;
never executed (the execution status of this line is deduced): points += 2;
-
320 }
never executed: }
0
321}
never executed: }
0
322 -
323/*! -
324 \overload -
325 -
326 Resizes the polygon to \a nPoints and populates it with the points -
327 specified by the variable argument list. The points are given as a -
328 sequence of integers, starting with \a firstx then \a firsty, and -
329 so on. -
330 -
331 The example code creates a polygon with two points (10, 20) and -
332 (30, 40): -
333 -
334 \snippet polygon/polygon.cpp 3 -
335*/ -
336 -
337void QPolygon::setPoints(int nPoints, int firstx, int firsty, ...) -
338{ -
339 va_list ap;
executed (the execution status of this line is deduced): va_list ap;
-
340 resize(nPoints);
executed (the execution status of this line is deduced): resize(nPoints);
-
341 setPoint(0, firstx, firsty);
executed (the execution status of this line is deduced): setPoint(0, firstx, firsty);
-
342 int i = 0, x, y;
executed (the execution status of this line is deduced): int i = 0, x, y;
-
343 va_start(ap, firsty);
executed (the execution status of this line is deduced): __builtin_va_start(ap,firsty);
-
344 while (--nPoints) {
evaluated: --nPoints
TRUEFALSE
yes
Evaluation Count:1703
yes
Evaluation Count:826
826-1703
345 x = va_arg(ap, int);
executed (the execution status of this line is deduced): x = __builtin_va_arg(ap,int);
-
346 y = va_arg(ap, int);
executed (the execution status of this line is deduced): y = __builtin_va_arg(ap,int);
-
347 setPoint(++i, x, y);
executed (the execution status of this line is deduced): setPoint(++i, x, y);
-
348 }
executed: }
Execution Count:1703
1703
349 va_end(ap);
executed (the execution status of this line is deduced): __builtin_va_end(ap);
-
350}
executed: }
Execution Count:826
826
351 -
352/*! -
353 \overload -
354 \internal -
355 -
356 Copies \a nPoints points from the \a points coord array into this -
357 point array, and resizes the point array if \c{index+nPoints} -
358 exceeds the size of the array. -
359 -
360 \sa setPoint() -
361*/ -
362 -
363void QPolygon::putPoints(int index, int nPoints, const int *points) -
364{ -
365 if (index + nPoints > size())
never evaluated: index + nPoints > size()
0
366 resize(index + nPoints);
never executed: resize(index + nPoints);
0
367 int i = index;
never executed (the execution status of this line is deduced): int i = index;
-
368 while (nPoints--) {
never evaluated: nPoints--
0
369 setPoint(i++, *points, *(points+1));
never executed (the execution status of this line is deduced): setPoint(i++, *points, *(points+1));
-
370 points += 2;
never executed (the execution status of this line is deduced): points += 2;
-
371 }
never executed: }
0
372}
never executed: }
0
373 -
374/*! -
375 Copies \a nPoints points from the variable argument list into this -
376 polygon from the given \a index. -
377 -
378 The points are given as a sequence of integers, starting with \a -
379 firstx then \a firsty, and so on. The polygon is resized if -
380 \c{index+nPoints} exceeds its current size. -
381 -
382 The example code creates a polygon with three points (4,5), (6,7) -
383 and (8,9), by expanding the polygon from 1 to 3 points: -
384 -
385 \snippet polygon/polygon.cpp 4 -
386 -
387 The following code has the same result, but here the putPoints() -
388 function overwrites rather than extends: -
389 -
390 \snippet polygon/polygon.cpp 5 -
391 -
392 \sa setPoints() -
393*/ -
394 -
395void QPolygon::putPoints(int index, int nPoints, int firstx, int firsty, ...) -
396{ -
397 va_list ap;
executed (the execution status of this line is deduced): va_list ap;
-
398 if (index + nPoints > size())
partially evaluated: index + nPoints > size()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2
0-2
399 resize(index + nPoints);
never executed: resize(index + nPoints);
0
400 if (nPoints <= 0)
partially evaluated: nPoints <= 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2
0-2
401 return;
never executed: return;
0
402 setPoint(index, firstx, firsty);
executed (the execution status of this line is deduced): setPoint(index, firstx, firsty);
-
403 int i = index, x, y;
executed (the execution status of this line is deduced): int i = index, x, y;
-
404 va_start(ap, firsty);
executed (the execution status of this line is deduced): __builtin_va_start(ap,firsty);
-
405 while (--nPoints) {
evaluated: --nPoints
TRUEFALSE
yes
Evaluation Count:14
yes
Evaluation Count:2
2-14
406 x = va_arg(ap, int);
executed (the execution status of this line is deduced): x = __builtin_va_arg(ap,int);
-
407 y = va_arg(ap, int);
executed (the execution status of this line is deduced): y = __builtin_va_arg(ap,int);
-
408 setPoint(++i, x, y);
executed (the execution status of this line is deduced): setPoint(++i, x, y);
-
409 }
executed: }
Execution Count:14
14
410 va_end(ap);
executed (the execution status of this line is deduced): __builtin_va_end(ap);
-
411}
executed: }
Execution Count:2
2
412 -
413 -
414/*! -
415 \fn void QPolygon::putPoints(int index, int nPoints, const QPolygon &fromPolygon, int fromIndex) -
416 \overload -
417 -
418 Copies \a nPoints points from the given \a fromIndex ( 0 by -
419 default) in \a fromPolygon into this polygon, starting at the -
420 specified \a index. For example: -
421 -
422 \snippet polygon/polygon.cpp 6 -
423*/ -
424 -
425void QPolygon::putPoints(int index, int nPoints, const QPolygon & from, int fromIndex) -
426{ -
427 if (index + nPoints > size())
never evaluated: index + nPoints > size()
0
428 resize(index + nPoints);
never executed: resize(index + nPoints);
0
429 if (nPoints <= 0)
never evaluated: nPoints <= 0
0
430 return;
never executed: return;
0
431 int n = 0;
never executed (the execution status of this line is deduced): int n = 0;
-
432 while(n < nPoints) {
never evaluated: n < nPoints
0
433 setPoint(index + n, from[fromIndex+n]);
never executed (the execution status of this line is deduced): setPoint(index + n, from[fromIndex+n]);
-
434 ++n;
never executed (the execution status of this line is deduced): ++n;
-
435 }
never executed: }
0
436}
never executed: }
0
437 -
438 -
439/*! -
440 Returns the bounding rectangle of the polygon, or QRect(0, 0, 0, -
441 0) if the polygon is empty. -
442 -
443 \sa QVector::isEmpty() -
444*/ -
445 -
446QRect QPolygon::boundingRect() const -
447{ -
448 if (isEmpty())
partially evaluated: isEmpty()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:249
0-249
449 return QRect(0, 0, 0, 0);
never executed: return QRect(0, 0, 0, 0);
0
450 register const QPoint *pd = constData();
executed (the execution status of this line is deduced): register const QPoint *pd = constData();
-
451 int minx, maxx, miny, maxy;
executed (the execution status of this line is deduced): int minx, maxx, miny, maxy;
-
452 minx = maxx = pd->x();
executed (the execution status of this line is deduced): minx = maxx = pd->x();
-
453 miny = maxy = pd->y();
executed (the execution status of this line is deduced): miny = maxy = pd->y();
-
454 ++pd;
executed (the execution status of this line is deduced): ++pd;
-
455 for (int i = 1; i < size(); ++i) {
evaluated: i < size()
TRUEFALSE
yes
Evaluation Count:537
yes
Evaluation Count:249
249-537
456 if (pd->x() < minx)
evaluated: pd->x() < minx
TRUEFALSE
yes
Evaluation Count:41
yes
Evaluation Count:496
41-496
457 minx = pd->x();
executed: minx = pd->x();
Execution Count:41
41
458 else if (pd->x() > maxx)
evaluated: pd->x() > maxx
TRUEFALSE
yes
Evaluation Count:341
yes
Evaluation Count:155
155-341
459 maxx = pd->x();
executed: maxx = pd->x();
Execution Count:341
341
460 if (pd->y() < miny)
evaluated: pd->y() < miny
TRUEFALSE
yes
Evaluation Count:115
yes
Evaluation Count:422
115-422
461 miny = pd->y();
executed: miny = pd->y();
Execution Count:115
115
462 else if (pd->y() > maxy)
evaluated: pd->y() > maxy
TRUEFALSE
yes
Evaluation Count:211
yes
Evaluation Count:211
211
463 maxy = pd->y();
executed: maxy = pd->y();
Execution Count:211
211
464 ++pd;
executed (the execution status of this line is deduced): ++pd;
-
465 }
executed: }
Execution Count:537
537
466 return QRect(QPoint(minx,miny), QPoint(maxx,maxy));
executed: return QRect(QPoint(minx,miny), QPoint(maxx,maxy));
Execution Count:249
249
467} -
468 -
469#ifndef QT_NO_DEBUG_STREAM -
470QDebug operator<<(QDebug dbg, const QPolygon &a) -
471{ -
472 dbg.nospace() << "QPolygon(";
executed (the execution status of this line is deduced): dbg.nospace() << "QPolygon(";
-
473 for (int i = 0; i < a.count(); ++i)
partially evaluated: i < a.count()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1
0-1
474 dbg.nospace() << a.at(i);
never executed: dbg.nospace() << a.at(i);
0
475 dbg.nospace() << ')';
executed (the execution status of this line is deduced): dbg.nospace() << ')';
-
476 return dbg.space();
executed: return dbg.space();
Execution Count:1
1
477} -
478#endif -
479 -
480 -
481/*! -
482 \class QPolygonF -
483 \brief The QPolygonF class provides a vector of points using -
484 floating point precision. -
485 \inmodule QtGui -
486 -
487 \reentrant -
488 \ingroup painting -
489 \ingroup shared -
490 -
491 A QPolygonF is a QVector<QPointF>. The easiest way to add points -
492 to a QPolygonF is to use its streaming operator, as illustrated -
493 below: -
494 -
495 \snippet polygon/polygon.cpp 1 -
496 -
497 In addition to the functions provided by QVector, QPolygonF -
498 provides the boundingRect() and translate() functions for geometry -
499 operations. Use the QMatrix::map() function for more general -
500 transformations of QPolygonFs. -
501 -
502 QPolygonF also provides the isClosed() function to determine -
503 whether a polygon's start and end points are the same, and the -
504 toPolygon() function returning an integer precision copy of this -
505 polygon. -
506 -
507 The QPolygonF class is \l {Implicit Data Sharing}{implicitly -
508 shared}. -
509 -
510 \sa QVector, QPolygon, QLineF -
511*/ -
512 -
513 -
514/***************************************************************************** -
515 QPolygonF member functions -
516 *****************************************************************************/ -
517 -
518/*! -
519 \fn QPolygonF::QPolygonF() -
520 -
521 Constructs a polygon with no points. -
522 -
523 \sa QVector::isEmpty() -
524*/ -
525 -
526/*! -
527 \fn QPolygonF::QPolygonF(int size) -
528 -
529 Constructs a polygon of the given \a size. Creates an empty -
530 polygon if \a size == 0. -
531 -
532 \sa QVector::isEmpty() -
533*/ -
534 -
535/*! -
536 \fn QPolygonF::QPolygonF(const QPolygonF &polygon) -
537 -
538 Constructs a copy of the given \a polygon. -
539*/ -
540 -
541/*! -
542 \fn QPolygonF::QPolygonF(const QVector<QPointF> &points) -
543 -
544 Constructs a polygon containing the specified \a points. -
545*/ -
546 -
547/*! -
548 \fn QPolygonF::QPolygonF(const QRectF &rectangle) -
549 -
550 Constructs a closed polygon from the specified \a rectangle. -
551 -
552 The polygon contains the four vertices of the rectangle in -
553 clockwise order starting and ending with the top-left vertex. -
554 -
555 \sa isClosed() -
556*/ -
557 -
558QPolygonF::QPolygonF(const QRectF &r) -
559{ -
560 reserve(5);
executed (the execution status of this line is deduced): reserve(5);
-
561 append(QPointF(r.x(), r.y()));
executed (the execution status of this line is deduced): append(QPointF(r.x(), r.y()));
-
562 append(QPointF(r.x() + r.width(), r.y()));
executed (the execution status of this line is deduced): append(QPointF(r.x() + r.width(), r.y()));
-
563 append(QPointF(r.x() + r.width(), r.y() + r.height()));
executed (the execution status of this line is deduced): append(QPointF(r.x() + r.width(), r.y() + r.height()));
-
564 append(QPointF(r.x(), r.y() + r.height()));
executed (the execution status of this line is deduced): append(QPointF(r.x(), r.y() + r.height()));
-
565 append(QPointF(r.x(), r.y()));
executed (the execution status of this line is deduced): append(QPointF(r.x(), r.y()));
-
566}
executed: }
Execution Count:14
14
567 -
568/*! -
569 \fn QPolygonF::QPolygonF(const QPolygon &polygon) -
570 -
571 Constructs a float based polygon from the specified integer based -
572 \a polygon. -
573 -
574 \sa toPolygon() -
575*/ -
576 -
577QPolygonF::QPolygonF(const QPolygon &a) -
578{ -
579 reserve(a.size());
executed (the execution status of this line is deduced): reserve(a.size());
-
580 for (int i=0; i<a.size(); ++i)
evaluated: i<a.size()
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:13
4-13
581 append(a.at(i));
executed: append(a.at(i));
Execution Count:4
4
582}
executed: }
Execution Count:13
13
583 -
584/*! -
585 \fn QPolygonF::~QPolygonF() -
586 -
587 Destroys the polygon. -
588*/ -
589 -
590 -
591/*! -
592 Translate all points in the polygon by the given \a offset. -
593 -
594 \sa translated() -
595*/ -
596 -
597void QPolygonF::translate(const QPointF &offset) -
598{ -
599 if (offset.isNull())
never evaluated: offset.isNull()
0
600 return;
never executed: return;
0
601 -
602 register QPointF *p = data();
never executed (the execution status of this line is deduced): register QPointF *p = data();
-
603 register int i = size();
never executed (the execution status of this line is deduced): register int i = size();
-
604 while (i--) {
never evaluated: i--
0
605 *p += offset;
never executed (the execution status of this line is deduced): *p += offset;
-
606 ++p;
never executed (the execution status of this line is deduced): ++p;
-
607 }
never executed: }
0
608}
never executed: }
0
609 -
610/*! -
611 \fn void QPolygonF::translate(qreal dx, qreal dy) -
612 \overload -
613 -
614 Translates all points in the polygon by (\a{dx}, \a{dy}). -
615 -
616 \sa translated() -
617*/ -
618 -
619/*! -
620 Returns a copy of the polygon that is translated by the given \a offset. -
621 -
622 \since 4.6 -
623 \sa translate() -
624*/ -
625QPolygonF QPolygonF::translated(const QPointF &offset) const -
626{ -
627 QPolygonF copy(*this);
never executed (the execution status of this line is deduced): QPolygonF copy(*this);
-
628 copy.translate(offset);
never executed (the execution status of this line is deduced): copy.translate(offset);
-
629 return copy;
never executed: return copy;
0
630} -
631 -
632/*! -
633 \fn void QPolygonF::translated(qreal dx, qreal dy) const -
634 \overload -
635 \since 4.6 -
636 -
637 Returns a copy of the polygon that is translated by (\a{dx}, \a{dy}). -
638 -
639 \sa translate() -
640*/ -
641 -
642/*! -
643 \fn bool QPolygonF::isClosed() const -
644 -
645 Returns true if the polygon is closed; otherwise returns false. -
646 -
647 A polygon is said to be closed if its start point and end point are equal. -
648 -
649 \sa QVector::first(), QVector::last() -
650*/ -
651 -
652/*! -
653 Returns the bounding rectangle of the polygon, or QRectF(0,0,0,0) -
654 if the polygon is empty. -
655 -
656 \sa QVector::isEmpty() -
657*/ -
658 -
659QRectF QPolygonF::boundingRect() const -
660{ -
661 if (isEmpty())
evaluated: isEmpty()
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:2065
1-2065
662 return QRectF(0, 0, 0, 0);
executed: return QRectF(0, 0, 0, 0);
Execution Count:1
1
663 register const QPointF *pd = constData();
executed (the execution status of this line is deduced): register const QPointF *pd = constData();
-
664 qreal minx, maxx, miny, maxy;
executed (the execution status of this line is deduced): qreal minx, maxx, miny, maxy;
-
665 minx = maxx = pd->x();
executed (the execution status of this line is deduced): minx = maxx = pd->x();
-
666 miny = maxy = pd->y();
executed (the execution status of this line is deduced): miny = maxy = pd->y();
-
667 ++pd;
executed (the execution status of this line is deduced): ++pd;
-
668 for (int i = 1; i < size(); ++i) {
evaluated: i < size()
TRUEFALSE
yes
Evaluation Count:6182
yes
Evaluation Count:2065
2065-6182
669 if (pd->x() < minx)
evaluated: pd->x() < minx
TRUEFALSE
yes
Evaluation Count:279
yes
Evaluation Count:5903
279-5903
670 minx = pd->x();
executed: minx = pd->x();
Execution Count:279
279
671 else if (pd->x() > maxx)
evaluated: pd->x() > maxx
TRUEFALSE
yes
Evaluation Count:2523
yes
Evaluation Count:3380
2523-3380
672 maxx = pd->x();
executed: maxx = pd->x();
Execution Count:2523
2523
673 if (pd->y() < miny)
evaluated: pd->y() < miny
TRUEFALSE
yes
Evaluation Count:743
yes
Evaluation Count:5439
743-5439
674 miny = pd->y();
executed: miny = pd->y();
Execution Count:743
743
675 else if (pd->y() > maxy)
evaluated: pd->y() > maxy
TRUEFALSE
yes
Evaluation Count:2502
yes
Evaluation Count:2937
2502-2937
676 maxy = pd->y();
executed: maxy = pd->y();
Execution Count:2502
2502
677 ++pd;
executed (the execution status of this line is deduced): ++pd;
-
678 }
executed: }
Execution Count:6182
6182
679 return QRectF(minx,miny, maxx - minx, maxy - miny);
executed: return QRectF(minx,miny, maxx - minx, maxy - miny);
Execution Count:2065
2065
680} -
681 -
682/*! -
683 Creates and returns a QPolygon by converting each QPointF to a -
684 QPoint. -
685 -
686 \sa QPointF::toPoint() -
687*/ -
688 -
689QPolygon QPolygonF::toPolygon() const -
690{ -
691 QPolygon a;
executed (the execution status of this line is deduced): QPolygon a;
-
692 a.reserve(size());
executed (the execution status of this line is deduced): a.reserve(size());
-
693 for (int i=0; i<size(); ++i)
evaluated: i<size()
TRUEFALSE
yes
Evaluation Count:2256
yes
Evaluation Count:103
103-2256
694 a.append(at(i).toPoint());
executed: a.append(at(i).toPoint());
Execution Count:2256
2256
695 return a;
executed: return a;
Execution Count:103
103
696} -
697 -
698/*! -
699 \fn void QPolygon::swap(QPolygon &other) -
700 \since 4.8 -
701 -
702 Swaps polygon \a other with this polygon. This operation is very -
703 fast and never fails. -
704*/ -
705 -
706/*! -
707 \fn void QPolygonF::swap(QPolygonF &other) -
708 \since 4.8 -
709 -
710 Swaps polygon \a other with this polygon. This operation is very -
711 fast and never fails. -
712*/ -
713 -
714/*! -
715 Returns the polygon as a QVariant -
716*/ -
717QPolygon::operator QVariant() const -
718{ -
719 return QVariant(QVariant::Polygon, this);
executed: return QVariant(QVariant::Polygon, this);
Execution Count:1
1
720} -
721 -
722/***************************************************************************** -
723 QPolygon stream functions -
724 *****************************************************************************/ -
725#ifndef QT_NO_DATASTREAM -
726/*! -
727 \fn QDataStream &operator<<(QDataStream &stream, const QPolygon &polygon) -
728 \since 4.4 -
729 \relates QPolygon -
730 -
731 Writes the given \a polygon to the given \a stream, and returns a -
732 reference to the stream. -
733 -
734 \sa {Serializing Qt Data Types} -
735*/ -
736QDataStream &operator<<(QDataStream &s, const QPolygon &a) -
737{ -
738 const QVector<QPoint> &v = a;
executed (the execution status of this line is deduced): const QVector<QPoint> &v = a;
-
739 return s << v;
executed: return s << v;
Execution Count:8
8
740} -
741 -
742/*! -
743 \fn QDataStream &operator>>(QDataStream &stream, QPolygon &polygon) -
744 \since 4.4 -
745 \relates QPolygon -
746 -
747 Reads a polygon from the given \a stream into the given \a -
748 polygon, and returns a reference to the stream. -
749 -
750 \sa {Serializing Qt Data Types} -
751*/ -
752QDataStream &operator>>(QDataStream &s, QPolygon &a) -
753{ -
754 QVector<QPoint> &v = a;
executed (the execution status of this line is deduced): QVector<QPoint> &v = a;
-
755 return s >> v;
executed: return s >> v;
Execution Count:8
8
756} -
757#endif // QT_NO_DATASTREAM -
758 -
759/***************************************************************************** -
760 QPolygonF stream functions -
761 *****************************************************************************/ -
762#ifndef QT_NO_DATASTREAM -
763/*! -
764 \fn QDataStream &operator<<(QDataStream &stream, const QPolygonF &polygon) -
765 \relates QPolygonF -
766 -
767 Writes the given \a polygon to the given \a stream, and returns a -
768 reference to the stream. -
769 -
770 \sa {Serializing Qt Data Types} -
771*/ -
772 -
773QDataStream &operator<<(QDataStream &s, const QPolygonF &a) -
774{ -
775 quint32 len = a.size();
executed (the execution status of this line is deduced): quint32 len = a.size();
-
776 uint i;
executed (the execution status of this line is deduced): uint i;
-
777 -
778 s << len;
executed (the execution status of this line is deduced): s << len;
-
779 for (i = 0; i < len; ++i)
evaluated: i < len
TRUEFALSE
yes
Evaluation Count:12
yes
Evaluation Count:12
12
780 s << a.at(i);
executed: s << a.at(i);
Execution Count:12
12
781 return s;
executed: return s;
Execution Count:12
12
782} -
783 -
784/*! -
785 \fn QDataStream &operator>>(QDataStream &stream, QPolygonF &polygon) -
786 \relates QPolygonF -
787 -
788 Reads a polygon from the given \a stream into the given \a -
789 polygon, and returns a reference to the stream. -
790 -
791 \sa {Serializing Qt Data Types} -
792*/ -
793 -
794QDataStream &operator>>(QDataStream &s, QPolygonF &a) -
795{ -
796 quint32 len;
executed (the execution status of this line is deduced): quint32 len;
-
797 uint i;
executed (the execution status of this line is deduced): uint i;
-
798 -
799 s >> len;
executed (the execution status of this line is deduced): s >> len;
-
800 a.reserve(a.size() + (int)len);
executed (the execution status of this line is deduced): a.reserve(a.size() + (int)len);
-
801 QPointF p;
executed (the execution status of this line is deduced): QPointF p;
-
802 for (i = 0; i < len; ++i) {
evaluated: i < len
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:8
4-8
803 s >> p;
executed (the execution status of this line is deduced): s >> p;
-
804 a.insert(i, p);
executed (the execution status of this line is deduced): a.insert(i, p);
-
805 }
executed: }
Execution Count:4
4
806 return s;
executed: return s;
Execution Count:8
8
807} -
808#endif //QT_NO_DATASTREAM -
809 -
810#ifndef QT_NO_DEBUG_STREAM -
811QDebug operator<<(QDebug dbg, const QPolygonF &a) -
812{ -
813 dbg.nospace() << "QPolygonF(";
executed (the execution status of this line is deduced): dbg.nospace() << "QPolygonF(";
-
814 for (int i = 0; i < a.count(); ++i)
partially evaluated: i < a.count()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1
0-1
815 dbg.nospace() << a.at(i);
never executed: dbg.nospace() << a.at(i);
0
816 dbg.nospace() << ')';
executed (the execution status of this line is deduced): dbg.nospace() << ')';
-
817 return dbg.space();
executed: return dbg.space();
Execution Count:1
1
818} -
819#endif -
820 -
821 -
822/*! -
823 \since 4.3 -
824 -
825 \fn bool QPolygonF::containsPoint(const QPointF &point, Qt::FillRule fillRule) const -
826 -
827 Returns true if the given \a point is inside the polygon according to -
828 the specified \a fillRule; otherwise returns false. -
829*/ -
830bool QPolygonF::containsPoint(const QPointF &pt, Qt::FillRule fillRule) const -
831{ -
832 if (isEmpty())
never evaluated: isEmpty()
0
833 return false;
never executed: return false;
0
834 -
835 int winding_number = 0;
never executed (the execution status of this line is deduced): int winding_number = 0;
-
836 -
837 QPointF last_pt = at(0);
never executed (the execution status of this line is deduced): QPointF last_pt = at(0);
-
838 QPointF last_start = at(0);
never executed (the execution status of this line is deduced): QPointF last_start = at(0);
-
839 for (int i = 1; i < size(); ++i) {
never evaluated: i < size()
0
840 const QPointF &e = at(i);
never executed (the execution status of this line is deduced): const QPointF &e = at(i);
-
841 qt_polygon_isect_line(last_pt, e, pt, &winding_number);
never executed (the execution status of this line is deduced): qt_polygon_isect_line(last_pt, e, pt, &winding_number);
-
842 last_pt = e;
never executed (the execution status of this line is deduced): last_pt = e;
-
843 }
never executed: }
0
844 -
845 // implicitly close last subpath -
846 if (last_pt != last_start)
never evaluated: last_pt != last_start
0
847 qt_polygon_isect_line(last_pt, last_start, pt, &winding_number);
never executed: qt_polygon_isect_line(last_pt, last_start, pt, &winding_number);
0
848 -
849 return (fillRule == Qt::WindingFill
never executed: return (fillRule == Qt::WindingFill ? (winding_number != 0) : ((winding_number % 2) != 0));
0
850 ? (winding_number != 0)
never executed: return (fillRule == Qt::WindingFill ? (winding_number != 0) : ((winding_number % 2) != 0));
0
851 : ((winding_number % 2) != 0));
never executed: return (fillRule == Qt::WindingFill ? (winding_number != 0) : ((winding_number % 2) != 0));
0
852} -
853 -
854/*! -
855 \since 4.3 -
856 -
857 \fn bool QPolygon::containsPoint(const QPoint &point, Qt::FillRule fillRule) const -
858 Returns true if the given \a point is inside the polygon according to -
859 the specified \a fillRule; otherwise returns false. -
860*/ -
861bool QPolygon::containsPoint(const QPoint &pt, Qt::FillRule fillRule) const -
862{ -
863 if (isEmpty())
never evaluated: isEmpty()
0
864 return false;
never executed: return false;
0
865 -
866 int winding_number = 0;
never executed (the execution status of this line is deduced): int winding_number = 0;
-
867 -
868 QPoint last_pt = at(0);
never executed (the execution status of this line is deduced): QPoint last_pt = at(0);
-
869 QPoint last_start = at(0);
never executed (the execution status of this line is deduced): QPoint last_start = at(0);
-
870 for (int i = 1; i < size(); ++i) {
never evaluated: i < size()
0
871 const QPoint &e = at(i);
never executed (the execution status of this line is deduced): const QPoint &e = at(i);
-
872 qt_polygon_isect_line(last_pt, e, pt, &winding_number);
never executed (the execution status of this line is deduced): qt_polygon_isect_line(last_pt, e, pt, &winding_number);
-
873 last_pt = e;
never executed (the execution status of this line is deduced): last_pt = e;
-
874 }
never executed: }
0
875 -
876 // implicitly close last subpath -
877 if (last_pt != last_start)
never evaluated: last_pt != last_start
0
878 qt_polygon_isect_line(last_pt, last_start, pt, &winding_number);
never executed: qt_polygon_isect_line(last_pt, last_start, pt, &winding_number);
0
879 -
880 return (fillRule == Qt::WindingFill
never executed: return (fillRule == Qt::WindingFill ? (winding_number != 0) : ((winding_number % 2) != 0));
0
881 ? (winding_number != 0)
never executed: return (fillRule == Qt::WindingFill ? (winding_number != 0) : ((winding_number % 2) != 0));
0
882 : ((winding_number % 2) != 0));
never executed: return (fillRule == Qt::WindingFill ? (winding_number != 0) : ((winding_number % 2) != 0));
0
883} -
884 -
885/*! -
886 \since 4.3 -
887 -
888 Returns a polygon which is the union of this polygon and \a r. -
889 -
890 Set operations on polygons, will treat the polygons as areas, and -
891 implicitly close the polygon. -
892 -
893 \sa intersected(), subtracted() -
894*/ -
895 -
896QPolygon QPolygon::united(const QPolygon &r) const -
897{ -
898 QPainterPath subject; subject.addPolygon(*this);
never executed (the execution status of this line is deduced): QPainterPath subject; subject.addPolygon(*this);
-
899 QPainterPath clip; clip.addPolygon(r);
never executed (the execution status of this line is deduced): QPainterPath clip; clip.addPolygon(r);
-
900 -
901 return subject.united(clip).toFillPolygon().toPolygon();
never executed: return subject.united(clip).toFillPolygon().toPolygon();
0
902} -
903 -
904/*! -
905 \since 4.3 -
906 -
907 Returns a polygon which is the intersection of this polygon and \a r. -
908 -
909 Set operations on polygons will treat the polygons as -
910 areas. Non-closed polygons will be treated as implicitly closed. -
911*/ -
912 -
913QPolygon QPolygon::intersected(const QPolygon &r) const -
914{ -
915 QPainterPath subject; subject.addPolygon(*this);
never executed (the execution status of this line is deduced): QPainterPath subject; subject.addPolygon(*this);
-
916 QPainterPath clip; clip.addPolygon(r);
never executed (the execution status of this line is deduced): QPainterPath clip; clip.addPolygon(r);
-
917 -
918 return subject.intersected(clip).toFillPolygon().toPolygon();
never executed: return subject.intersected(clip).toFillPolygon().toPolygon();
0
919} -
920 -
921/*! -
922 \since 4.3 -
923 -
924 Returns a polygon which is \a r subtracted from this polygon. -
925 -
926 Set operations on polygons will treat the polygons as -
927 areas. Non-closed polygons will be treated as implicitly closed. -
928 -
929*/ -
930 -
931QPolygon QPolygon::subtracted(const QPolygon &r) const -
932{ -
933 QPainterPath subject; subject.addPolygon(*this);
never executed (the execution status of this line is deduced): QPainterPath subject; subject.addPolygon(*this);
-
934 QPainterPath clip; clip.addPolygon(r);
never executed (the execution status of this line is deduced): QPainterPath clip; clip.addPolygon(r);
-
935 -
936 return subject.subtracted(clip).toFillPolygon().toPolygon();
never executed: return subject.subtracted(clip).toFillPolygon().toPolygon();
0
937} -
938 -
939/*! -
940 \since 4.3 -
941 -
942 Returns a polygon which is the union of this polygon and \a r. -
943 -
944 Set operations on polygons will treat the polygons as -
945 areas. Non-closed polygons will be treated as implicitly closed. -
946 -
947 \sa intersected(), subtracted() -
948*/ -
949 -
950QPolygonF QPolygonF::united(const QPolygonF &r) const -
951{ -
952 QPainterPath subject; subject.addPolygon(*this);
never executed (the execution status of this line is deduced): QPainterPath subject; subject.addPolygon(*this);
-
953 QPainterPath clip; clip.addPolygon(r);
never executed (the execution status of this line is deduced): QPainterPath clip; clip.addPolygon(r);
-
954 -
955 return subject.united(clip).toFillPolygon();
never executed: return subject.united(clip).toFillPolygon();
0
956} -
957 -
958/*! -
959 \since 4.3 -
960 -
961 Returns a polygon which is the intersection of this polygon and \a r. -
962 -
963 Set operations on polygons will treat the polygons as -
964 areas. Non-closed polygons will be treated as implicitly closed. -
965 -
966*/ -
967 -
968QPolygonF QPolygonF::intersected(const QPolygonF &r) const -
969{ -
970 QPainterPath subject; subject.addPolygon(*this);
never executed (the execution status of this line is deduced): QPainterPath subject; subject.addPolygon(*this);
-
971 QPainterPath clip; clip.addPolygon(r);
never executed (the execution status of this line is deduced): QPainterPath clip; clip.addPolygon(r);
-
972 -
973 return subject.intersected(clip).toFillPolygon();
never executed: return subject.intersected(clip).toFillPolygon();
0
974} -
975 -
976/*! -
977 \since 4.3 -
978 -
979 Returns a polygon which is \a r subtracted from this polygon. -
980 -
981 Set operations on polygons will treat the polygons as -
982 areas. Non-closed polygons will be treated as implicitly closed. -
983 -
984*/ -
985 -
986QPolygonF QPolygonF::subtracted(const QPolygonF &r) const -
987{ -
988 QPainterPath subject; subject.addPolygon(*this);
never executed (the execution status of this line is deduced): QPainterPath subject; subject.addPolygon(*this);
-
989 QPainterPath clip; clip.addPolygon(r);
never executed (the execution status of this line is deduced): QPainterPath clip; clip.addPolygon(r);
-
990 return subject.subtracted(clip).toFillPolygon();
never executed: return subject.subtracted(clip).toFillPolygon();
0
991} -
992 -
993/*! -
994 Returns the polygon as a QVariant. -
995*/ -
996 -
997QPolygonF::operator QVariant() const -
998{ -
999 return QVariant(QMetaType::QPolygonF, this);
executed: return QVariant(QMetaType::QPolygonF, this);
Execution Count:1
1
1000} -
1001 -
1002QT_END_NAMESPACE -
1003 -
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial