OpenCoverage

qpolygon.cpp

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

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9