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

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