Fixed outline / fill inconsistencies in raster paint engine.
[profile/ivi/qtbase.git] / src / gui / painting / qpolygon.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
20 **
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
28 **
29 ** Other Usage
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
32 **
33 **
34 **
35 **
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
54 QT_BEGIN_NAMESPACE
55
56 //same as qt_painterpath_isect_line in qpainterpath.cpp
57 static void qt_polygon_isect_line(const QPointF &p1, const QPointF &p2, const QPointF &pos,
58                                   int *winding)
59 {
60     qreal x1 = p1.x();
61     qreal y1 = p1.y();
62     qreal x2 = p2.x();
63     qreal y2 = p2.y();
64     qreal y = pos.y();
65
66     int dir = 1;
67
68     if (qFuzzyCompare(y1, y2)) {
69         // ignore horizontal lines according to scan conversion rule
70         return;
71     } else if (y2 < y1) {
72         qreal x_tmp = x2; x2 = x1; x1 = x_tmp;
73         qreal y_tmp = y2; y2 = y1; y1 = y_tmp;
74         dir = -1;
75     }
76
77     if (y >= y1 && y < y2) {
78         qreal x = x1 + ((x2 - x1) / (y2 - y1)) * (y - y1);
79
80         // count up the winding number if we're
81         if (x<=pos.x()) {
82             (*winding) += dir;
83         }
84     }
85 }
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
178 QPolygon::QPolygon(const QRect &r, bool closed)
179 {
180     reserve(closed ? 5 : 4);
181     *this << QPoint(r.x(), r.y())
182           << QPoint(r.x() + r.width(), r.y())
183           << QPoint(r.x() + r.width(), r.y() + r.height())
184           << QPoint(r.x(), r.y() + r.height());
185     if (closed)
186         *this << QPoint(r.left(), r.top());
187 }
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
197 QPolygon::QPolygon(int nPoints, const int *points)
198 {
199     setPoints(nPoints, points);
200 }
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
216 void QPolygon::translate(int dx, int dy)
217 {
218     if (dx == 0 && dy == 0)
219         return;
220
221     register QPoint *p = data();
222     register int i = size();
223     QPoint pt(dx, dy);
224     while (i--) {
225         *p += pt;
226         ++p;
227     }
228 }
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 */
245 QPolygon QPolygon::translated(int dx, int dy) const
246 {
247     QPolygon copy(*this);
248     copy.translate(dx, dy);
249     return copy;
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
269 void QPolygon::point(int index, int *x, int *y) const
270 {
271     QPoint p = at(index);
272     if (x)
273         *x = (int)p.x();
274     if (y)
275         *y = (int)p.y();
276 }
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
313 void QPolygon::setPoints(int nPoints, const int *points)
314 {
315     resize(nPoints);
316     int i = 0;
317     while (nPoints--) {
318         setPoint(i++, *points, *(points+1));
319         points += 2;
320     }
321 }
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
337 void QPolygon::setPoints(int nPoints, int firstx, int firsty, ...)
338 {
339     va_list ap;
340     resize(nPoints);
341     setPoint(0, firstx, firsty);
342     int i = 0, x, y;
343     va_start(ap, firsty);
344     while (--nPoints) {
345         x = va_arg(ap, int);
346         y = va_arg(ap, int);
347         setPoint(++i, x, y);
348     }
349     va_end(ap);
350 }
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
363 void QPolygon::putPoints(int index, int nPoints, const int *points)
364 {
365     if (index + nPoints > size())
366         resize(index + nPoints);
367     int i = index;
368     while (nPoints--) {
369         setPoint(i++, *points, *(points+1));
370         points += 2;
371     }
372 }
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
395 void QPolygon::putPoints(int index, int nPoints, int firstx, int firsty, ...)
396 {
397     va_list ap;
398     if (index + nPoints > size())
399         resize(index + nPoints);
400     if (nPoints <= 0)
401         return;
402     setPoint(index, firstx, firsty);
403     int i = index, x, y;
404     va_start(ap, firsty);
405     while (--nPoints) {
406         x = va_arg(ap, int);
407         y = va_arg(ap, int);
408         setPoint(++i, x, y);
409     }
410     va_end(ap);
411 }
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
425 void QPolygon::putPoints(int index, int nPoints, const QPolygon & from, int fromIndex)
426 {
427     if (index + nPoints > size())
428         resize(index + nPoints);
429     if (nPoints <= 0)
430         return;
431     int n = 0;
432     while(n < nPoints) {
433         setPoint(index + n, from[fromIndex+n]);
434         ++n;
435     }
436 }
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
446 QRect QPolygon::boundingRect() const
447 {
448     if (isEmpty())
449         return QRect(0, 0, 0, 0);
450     register const QPoint *pd = constData();
451     int minx, maxx, miny, maxy;
452     minx = maxx = pd->x();
453     miny = maxy = pd->y();
454     ++pd;
455     for (int i = 1; i < size(); ++i) {
456         if (pd->x() < minx)
457             minx = pd->x();
458         else if (pd->x() > maxx)
459             maxx = pd->x();
460         if (pd->y() < miny)
461             miny = pd->y();
462         else if (pd->y() > maxy)
463             maxy = pd->y();
464         ++pd;
465     }
466     return QRect(QPoint(minx,miny), QPoint(maxx,maxy));
467 }
468
469 #ifndef QT_NO_DEBUG_STREAM
470 QDebug operator<<(QDebug dbg, const QPolygon &a)
471 {
472     dbg.nospace() << "QPolygon(";
473     for (int i = 0; i < a.count(); ++i)
474         dbg.nospace() << a.at(i);
475     dbg.nospace() << ')';
476     return dbg.space();
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
558 QPolygonF::QPolygonF(const QRectF &r)
559 {
560     reserve(5);
561     append(QPointF(r.x(), r.y()));
562     append(QPointF(r.x() + r.width(), r.y()));
563     append(QPointF(r.x() + r.width(), r.y() + r.height()));
564     append(QPointF(r.x(), r.y() + r.height()));
565     append(QPointF(r.x(), r.y()));
566 }
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
577 QPolygonF::QPolygonF(const QPolygon &a)
578 {
579     reserve(a.size());
580     for (int i=0; i<a.size(); ++i)
581         append(a.at(i));
582 }
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
597 void QPolygonF::translate(const QPointF &offset)
598 {
599     if (offset.isNull())
600         return;
601
602     register QPointF *p = data();
603     register int i = size();
604     while (i--) {
605         *p += offset;
606         ++p;
607     }
608 }
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 */
625 QPolygonF QPolygonF::translated(const QPointF &offset) const
626 {
627     QPolygonF copy(*this);
628     copy.translate(offset);
629     return copy;
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
659 QRectF QPolygonF::boundingRect() const
660 {
661     if (isEmpty())
662         return QRectF(0, 0, 0, 0);
663     register const QPointF *pd = constData();
664     qreal minx, maxx, miny, maxy;
665     minx = maxx = pd->x();
666     miny = maxy = pd->y();
667     ++pd;
668     for (int i = 1; i < size(); ++i) {
669         if (pd->x() < minx)
670             minx = pd->x();
671         else if (pd->x() > maxx)
672             maxx = pd->x();
673         if (pd->y() < miny)
674             miny = pd->y();
675         else if (pd->y() > maxy)
676             maxy = pd->y();
677         ++pd;
678     }
679     return QRectF(minx,miny, maxx - minx, maxy - miny);
680 }
681
682 /*!
683     Creates and returns a QPolygon by converting each QPointF to a
684     QPoint.
685
686     \sa QPointF::toPoint()
687 */
688
689 QPolygon QPolygonF::toPolygon() const
690 {
691     QPolygon a;
692     a.reserve(size());
693     for (int i=0; i<size(); ++i)
694         a.append(at(i).toPoint());
695     return a;
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 */
717 QPolygon::operator QVariant() const
718 {
719     return QVariant(QVariant::Polygon, this);
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 */
736 QDataStream &operator<<(QDataStream &s, const QPolygon &a)
737 {
738     const QVector<QPoint> &v = a;
739     return s << v;
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 */
752 QDataStream &operator>>(QDataStream &s, QPolygon &a)
753 {
754     QVector<QPoint> &v = a;
755     return s >> v;
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
773 QDataStream &operator<<(QDataStream &s, const QPolygonF &a)
774 {
775     quint32 len = a.size();
776     uint i;
777
778     s << len;
779     for (i = 0; i < len; ++i)
780         s << a.at(i);
781     return s;
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
794 QDataStream &operator>>(QDataStream &s, QPolygonF &a)
795 {
796     quint32 len;
797     uint i;
798
799     s >> len;
800     a.reserve(a.size() + (int)len);
801     QPointF p;
802     for (i = 0; i < len; ++i) {
803         s >> p;
804         a.insert(i, p);
805     }
806     return s;
807 }
808 #endif //QT_NO_DATASTREAM
809
810 #ifndef QT_NO_DEBUG_STREAM
811 QDebug operator<<(QDebug dbg, const QPolygonF &a)
812 {
813     dbg.nospace() << "QPolygonF(";
814     for (int i = 0; i < a.count(); ++i)
815         dbg.nospace() << a.at(i);
816     dbg.nospace() << ')';
817     return dbg.space();
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 */
830 bool QPolygonF::containsPoint(const QPointF &pt, Qt::FillRule fillRule) const
831 {
832     if (isEmpty())
833         return false;
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) {
840         const QPointF &e = at(i);
841         qt_polygon_isect_line(last_pt, e, pt, &winding_number);
842         last_pt = e;
843     }
844
845     // implicitly close last subpath
846     if (last_pt != last_start)
847         qt_polygon_isect_line(last_pt, last_start, pt, &winding_number);
848
849     return (fillRule == Qt::WindingFill
850             ? (winding_number != 0)
851             : ((winding_number % 2) != 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 */
861 bool QPolygon::containsPoint(const QPoint &pt, Qt::FillRule fillRule) const
862 {
863     if (isEmpty())
864         return false;
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) {
871         const QPoint &e = at(i);
872         qt_polygon_isect_line(last_pt, e, pt, &winding_number);
873         last_pt = e;
874     }
875
876     // implicitly close last subpath
877     if (last_pt != last_start)
878         qt_polygon_isect_line(last_pt, last_start, pt, &winding_number);
879
880     return (fillRule == Qt::WindingFill
881             ? (winding_number != 0)
882             : ((winding_number % 2) != 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
896 QPolygon 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();
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
913 QPolygon 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();
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
931 QPolygon 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();
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
950 QPolygonF 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();
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
968 QPolygonF 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();
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
986 QPolygonF 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();
991 }
992
993 /*!
994    Returns the polygon as a QVariant.
995 */
996
997 QPolygonF::operator QVariant() const
998 {
999     return QVariant(QMetaType::QPolygonF, this);
1000 }
1001
1002 QT_END_NAMESPACE