qpolygon.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/gui/painting/qpolygon.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6-
7static void qt_polygon_isect_line(const QPointF &p1, const QPointF &p2, const QPointF &pos,-
8 int *winding)-
9{-
10 qreal x1 = p1.x();-
11 qreal y1 = p1.y();-
12 qreal x2 = p2.x();-
13 qreal y2 = p2.y();-
14 qreal y = pos.y();-
15-
16 int dir = 1;-
17-
18 if (qFuzzyCompare(y1, y2)
qFuzzyCompare(y1, y2)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
19-
20 return;
never executed: return;
0
21 } else if (y2 < y1
y2 < y1Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
22 qreal x_tmp = x2; x2 = x1; x1 = x_tmp;-
23 qreal y_tmp = y2; y2 = y1; y1 = y_tmp;-
24 dir = -1;-
25 }
never executed: end of block
0
26-
27 if (y >= y1
y >= y1Description
TRUEnever evaluated
FALSEnever evaluated
&& y < y2
y < y2Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
28 qreal x = x1 + ((x2 - x1) / (y2 - y1)) * (y - y1);-
29-
30-
31 if (x<=pos.x()
x<=pos.x()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
32 (*winding) += dir;-
33 }
never executed: end of block
0
34 }
never executed: end of block
0
35}
never executed: end of block
0
36QPolygon::QPolygon(const QRect &r, bool closed)-
37{-
38 reserve(closed ? 5 : 4);-
39 *this << QPoint(r.x(), r.y())-
40 << QPoint(r.x() + r.width(), r.y())-
41 << QPoint(r.x() + r.width(), r.y() + r.height())-
42 << QPoint(r.x(), r.y() + r.height());-
43 if (closed
closedDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
44 *
never executed: *this << QPoint(r.left(), r.top());
this << QPoint(r.left(), r.top());
never executed: *this << QPoint(r.left(), r.top());
0
45}
never executed: end of block
0
46QPolygon::QPolygon(int nPoints, const int *points)-
47{-
48 setPoints(nPoints, points);-
49}
never executed: end of block
0
50void QPolygon::translate(int dx, int dy)-
51{-
52 if (dx == 0
dx == 0Description
TRUEnever evaluated
FALSEnever evaluated
&& dy == 0
dy == 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
53 return;
never executed: return;
0
54-
55 QPoint *p = data();-
56 int i = size();-
57 QPoint pt(dx, dy);-
58 while (i--
i--Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
59 *p += pt;-
60 ++p;-
61 }
never executed: end of block
0
62}
never executed: end of block
0
63QPolygon QPolygon::translated(int dx, int dy) const-
64{-
65 QPolygon copy(*this);-
66 copy.translate(dx, dy);-
67 return
never executed: return copy;
copy;
never executed: return copy;
0
68}-
69void QPolygon::point(int index, int *x, int *y) const-
70{-
71 QPoint p = at(index);-
72 if (x
xDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
73 *
never executed: *x = (int)p.x();
x = (int)p.x();
never executed: *x = (int)p.x();
0
74 if (y
yDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
75 *
never executed: *y = (int)p.y();
y = (int)p.y();
never executed: *y = (int)p.y();
0
76}
never executed: end of block
0
77void QPolygon::setPoints(int nPoints, const int *points)-
78{-
79 resize(nPoints);-
80 int i = 0;-
81 while (nPoints--
nPoints--Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
82 setPoint(i++, *points, *(points+1));-
83 points += 2;-
84 }
never executed: end of block
0
85}
never executed: end of block
0
86void QPolygon::setPoints(int nPoints, int firstx, int firsty, ...)-
87{-
88 va_list ap;-
89 resize(nPoints);-
90 setPoint(0, firstx, firsty);-
91 int i = 0, x, y;-
92 __builtin_va_start(ap,firsty);-
93 while (--
--nPointsDescription
TRUEnever evaluated
FALSEnever evaluated
nPoints
--nPointsDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
94 x = __builtin_va_arg(ap,int);-
95 y = __builtin_va_arg(ap,int);-
96 setPoint(++i, x, y);-
97 }
never executed: end of block
0
98 __builtin_va_end(ap);-
99}
never executed: end of block
0
100void QPolygon::putPoints(int index, int nPoints, const int *points)-
101{-
102 if (index + nPoints > size()
index + nPoints > size()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
103 resize(index + nPoints);
never executed: resize(index + nPoints);
0
104 int i = index;-
105 while (nPoints--
nPoints--Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
106 setPoint(i++, *points, *(points+1));-
107 points += 2;-
108 }
never executed: end of block
0
109}
never executed: end of block
0
110void QPolygon::putPoints(int index, int nPoints, int firstx, int firsty, ...)-
111{-
112 va_list ap;-
113 if (index + nPoints > size()
index + nPoints > size()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
114 resize(index + nPoints);
never executed: resize(index + nPoints);
0
115 if (nPoints <= 0
nPoints <= 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
116 return;
never executed: return;
0
117 setPoint(index, firstx, firsty);-
118 int i = index, x, y;-
119 __builtin_va_start(ap,firsty);-
120 while (--
--nPointsDescription
TRUEnever evaluated
FALSEnever evaluated
nPoints
--nPointsDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
121 x = __builtin_va_arg(ap,int);-
122 y = __builtin_va_arg(ap,int);-
123 setPoint(++i, x, y);-
124 }
never executed: end of block
0
125 __builtin_va_end(ap);-
126}
never executed: end of block
0
127void QPolygon::putPoints(int index, int nPoints, const QPolygon & from, int fromIndex)-
128{-
129 if (index + nPoints > size()
index + nPoints > size()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
130 resize(index + nPoints);
never executed: resize(index + nPoints);
0
131 if (nPoints <= 0
nPoints <= 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
132 return;
never executed: return;
0
133 int n = 0;-
134 while(n < nPoints
n < nPointsDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
135 setPoint(index + n, from[fromIndex+n]);-
136 ++n;-
137 }
never executed: end of block
0
138}
never executed: end of block
0
139QRect QPolygon::boundingRect() const-
140{-
141 if (isEmpty()
isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
142 return
never executed: return QRect(0, 0, 0, 0);
QRect(0, 0, 0, 0);
never executed: return QRect(0, 0, 0, 0);
0
143 const QPoint *pd = constData();-
144 int minx, maxx, miny, maxy;-
145 minx = maxx = pd->x();-
146 miny = maxy = pd->y();-
147 ++pd;-
148 for (int i = 1; i < size()
i < size()Description
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
149 if (pd->x() < minx
pd->x() < minxDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
150 minx = pd->x();
never executed: minx = pd->x();
0
151 else if (pd->x() > maxx
pd->x() > maxxDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
152 maxx = pd->x();
never executed: maxx = pd->x();
0
153 if (pd->y() < miny
pd->y() < minyDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
154 miny = pd->y();
never executed: miny = pd->y();
0
155 else if (pd->y() > maxy
pd->y() > maxyDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
156 maxy = pd->y();
never executed: maxy = pd->y();
0
157 ++pd;-
158 }
never executed: end of block
0
159 return
never executed: return QRect(QPoint(minx,miny), QPoint(maxx,maxy));
QRect(QPoint(minx,miny), QPoint(maxx,maxy));
never executed: return QRect(QPoint(minx,miny), QPoint(maxx,maxy));
0
160}-
161-
162-
163QDebug operator<<(QDebug dbg, const QPolygon &a)-
164{-
165 QDebugStateSaver saver(dbg);-
166 dbg.nospace() << "QPolygon(";-
167 for (int i = 0; i < a.count()
i < a.count()Description
TRUEnever evaluated
FALSEnever evaluated
; ++i)
0
168 dbg.nospace() << a.at(i);
never executed: dbg.nospace() << a.at(i);
0
169 dbg.nospace() << ')';-
170 return
never executed: return dbg;
dbg;
never executed: return dbg;
0
171}-
172QPolygonF::QPolygonF(const QRectF &r)-
173{-
174 reserve(5);-
175 append(QPointF(r.x(), r.y()));-
176 append(QPointF(r.x() + r.width(), r.y()));-
177 append(QPointF(r.x() + r.width(), r.y() + r.height()));-
178 append(QPointF(r.x(), r.y() + r.height()));-
179 append(QPointF(r.x(), r.y()));-
180}
never executed: end of block
0
181QPolygonF::QPolygonF(const QPolygon &a)-
182{-
183 reserve(a.size());-
184 for (int i=0; i<a.size()
i<a.size()Description
TRUEnever evaluated
FALSEnever evaluated
; ++i)
0
185 append(a.at(i));
never executed: append(a.at(i));
0
186}
never executed: end of block
0
187void QPolygonF::translate(const QPointF &offset)-
188{-
189 if (offset.isNull()
offset.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
190 return;
never executed: return;
0
191-
192 QPointF *p = data();-
193 int i = size();-
194 while (i--
i--Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
195 *p += offset;-
196 ++p;-
197 }
never executed: end of block
0
198}
never executed: end of block
0
199QPolygonF QPolygonF::translated(const QPointF &offset) const-
200{-
201 QPolygonF copy(*this);-
202 copy.translate(offset);-
203 return
never executed: return copy;
copy;
never executed: return copy;
0
204}-
205QRectF QPolygonF::boundingRect() const-
206{-
207 if (isEmpty()
isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
208 return
never executed: return QRectF(0, 0, 0, 0);
QRectF(0, 0, 0, 0);
never executed: return QRectF(0, 0, 0, 0);
0
209 const QPointF *pd = constData();-
210 qreal minx, maxx, miny, maxy;-
211 minx = maxx = pd->x();-
212 miny = maxy = pd->y();-
213 ++pd;-
214 for (int i = 1; i < size()
i < size()Description
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
215 if (pd->x() < minx
pd->x() < minxDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
216 minx = pd->x();
never executed: minx = pd->x();
0
217 else if (pd->x() > maxx
pd->x() > maxxDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
218 maxx = pd->x();
never executed: maxx = pd->x();
0
219 if (pd->y() < miny
pd->y() < minyDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
220 miny = pd->y();
never executed: miny = pd->y();
0
221 else if (pd->y() > maxy
pd->y() > maxyDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
222 maxy = pd->y();
never executed: maxy = pd->y();
0
223 ++pd;-
224 }
never executed: end of block
0
225 return
never executed: return QRectF(minx,miny, maxx - minx, maxy - miny);
QRectF(minx,miny, maxx - minx, maxy - miny);
never executed: return QRectF(minx,miny, maxx - minx, maxy - miny);
0
226}-
227QPolygon QPolygonF::toPolygon() const-
228{-
229 QPolygon a;-
230 a.reserve(size());-
231 for (int i=0; i<size()
i<size()Description
TRUEnever evaluated
FALSEnever evaluated
; ++i)
0
232 a.append(at(i).toPoint());
never executed: a.append(at(i).toPoint());
0
233 return
never executed: return a;
a;
never executed: return a;
0
234}-
235QPolygon::operator QVariant() const-
236{-
237 return
never executed: return QVariant(QVariant::Polygon, this);
QVariant(QVariant::Polygon, this);
never executed: return QVariant(QVariant::Polygon, this);
0
238}-
239QDataStream &operator<<(QDataStream &s, const QPolygon &a)-
240{-
241 const QVector<QPoint> &v = a;-
242 return
never executed: return s << v;
s << v;
never executed: return s << v;
0
243}-
244QDataStream &operator>>(QDataStream &s, QPolygon &a)-
245{-
246 QVector<QPoint> &v = a;-
247 return
never executed: return s >> v;
s >> v;
never executed: return s >> v;
0
248}-
249QDataStream &operator<<(QDataStream &s, const QPolygonF &a)-
250{-
251 quint32 len = a.size();-
252 uint i;-
253-
254 s << len;-
255 for (i = 0; i < len
i < lenDescription
TRUEnever evaluated
FALSEnever evaluated
; ++i)
0
256 s << a.at(i);
never executed: s << a.at(i);
0
257 return
never executed: return s;
s;
never executed: return s;
0
258}-
259QDataStream &operator>>(QDataStream &s, QPolygonF &a)-
260{-
261 quint32 len;-
262 uint i;-
263-
264 s >> len;-
265 a.reserve(a.size() + (int)len);-
266 QPointF p;-
267 for (i = 0; i < len
i < lenDescription
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
268 s >> p;-
269 a.insert(i, p);-
270 }
never executed: end of block
0
271 return
never executed: return s;
s;
never executed: return s;
0
272}-
273-
274-
275-
276QDebug operator<<(QDebug dbg, const QPolygonF &a)-
277{-
278 QDebugStateSaver saver(dbg);-
279 dbg.nospace() << "QPolygonF(";-
280 for (int i = 0; i < a.count()
i < a.count()Description
TRUEnever evaluated
FALSEnever evaluated
; ++i)
0
281 dbg.nospace() << a.at(i);
never executed: dbg.nospace() << a.at(i);
0
282 dbg.nospace() << ')';-
283 return
never executed: return dbg;
dbg;
never executed: return dbg;
0
284}-
285bool QPolygonF::containsPoint(const QPointF &pt, Qt::FillRule fillRule) const-
286{-
287 if (isEmpty()
isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
288 return
never executed: return false;
false;
never executed: return false;
0
289-
290 int winding_number = 0;-
291-
292 QPointF last_pt = at(0);-
293 QPointF last_start = at(0);-
294 for (int i = 1; i < size()
i < size()Description
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
295 const QPointF &e = at(i);-
296 qt_polygon_isect_line(last_pt, e, pt, &winding_number);-
297 last_pt = e;-
298 }
never executed: end of block
0
299-
300-
301 if (last_pt != last_start
last_pt != last_startDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
302 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
303-
304 return
never executed: return (fillRule == Qt::WindingFill ? (winding_number != 0) : ((winding_number % 2) != 0));
(fillRule == Qt::WindingFill
never executed: return (fillRule == Qt::WindingFill ? (winding_number != 0) : ((winding_number % 2) != 0));
0
305 ? (winding_number != 0)
never executed: return (fillRule == Qt::WindingFill ? (winding_number != 0) : ((winding_number % 2) != 0));
0
306 : ((winding_number % 2) != 0));
never executed: return (fillRule == Qt::WindingFill ? (winding_number != 0) : ((winding_number % 2) != 0));
0
307}-
308bool QPolygon::containsPoint(const QPoint &pt, Qt::FillRule fillRule) const-
309{-
310 if (isEmpty()
isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
311 return
never executed: return false;
false;
never executed: return false;
0
312-
313 int winding_number = 0;-
314-
315 QPoint last_pt = at(0);-
316 QPoint last_start = at(0);-
317 for (int i = 1; i < size()
i < size()Description
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
318 const QPoint &e = at(i);-
319 qt_polygon_isect_line(last_pt, e, pt, &winding_number);-
320 last_pt = e;-
321 }
never executed: end of block
0
322-
323-
324 if (last_pt != last_start
last_pt != last_startDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
325 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
326-
327 return
never executed: return (fillRule == Qt::WindingFill ? (winding_number != 0) : ((winding_number % 2) != 0));
(fillRule == Qt::WindingFill
never executed: return (fillRule == Qt::WindingFill ? (winding_number != 0) : ((winding_number % 2) != 0));
0
328 ? (winding_number != 0)
never executed: return (fillRule == Qt::WindingFill ? (winding_number != 0) : ((winding_number % 2) != 0));
0
329 : ((winding_number % 2) != 0));
never executed: return (fillRule == Qt::WindingFill ? (winding_number != 0) : ((winding_number % 2) != 0));
0
330}-
331QPolygon QPolygon::united(const QPolygon &r) const-
332{-
333 QPainterPath subject; subject.addPolygon(*this);-
334 QPainterPath clip; clip.addPolygon(r);-
335-
336 return
never executed: return subject.united(clip).toFillPolygon().toPolygon();
subject.united(clip).toFillPolygon().toPolygon();
never executed: return subject.united(clip).toFillPolygon().toPolygon();
0
337}-
338QPolygon QPolygon::intersected(const QPolygon &r) const-
339{-
340 QPainterPath subject; subject.addPolygon(*this);-
341 QPainterPath clip; clip.addPolygon(r);-
342-
343 return
never executed: return subject.intersected(clip).toFillPolygon().toPolygon();
subject.intersected(clip).toFillPolygon().toPolygon();
never executed: return subject.intersected(clip).toFillPolygon().toPolygon();
0
344}-
345QPolygon QPolygon::subtracted(const QPolygon &r) const-
346{-
347 QPainterPath subject; subject.addPolygon(*this);-
348 QPainterPath clip; clip.addPolygon(r);-
349-
350 return
never executed: return subject.subtracted(clip).toFillPolygon().toPolygon();
subject.subtracted(clip).toFillPolygon().toPolygon();
never executed: return subject.subtracted(clip).toFillPolygon().toPolygon();
0
351}-
352QPolygonF QPolygonF::united(const QPolygonF &r) const-
353{-
354 QPainterPath subject; subject.addPolygon(*this);-
355 QPainterPath clip; clip.addPolygon(r);-
356-
357 return
never executed: return subject.united(clip).toFillPolygon();
subject.united(clip).toFillPolygon();
never executed: return subject.united(clip).toFillPolygon();
0
358}-
359QPolygonF QPolygonF::intersected(const QPolygonF &r) const-
360{-
361 QPainterPath subject; subject.addPolygon(*this);-
362 QPainterPath clip; clip.addPolygon(r);-
363-
364 return
never executed: return subject.intersected(clip).toFillPolygon();
subject.intersected(clip).toFillPolygon();
never executed: return subject.intersected(clip).toFillPolygon();
0
365}-
366QPolygonF QPolygonF::subtracted(const QPolygonF &r) const-
367{-
368 QPainterPath subject; subject.addPolygon(*this);-
369 QPainterPath clip; clip.addPolygon(r);-
370 return
never executed: return subject.subtracted(clip).toFillPolygon();
subject.subtracted(clip).toFillPolygon();
never executed: return subject.subtracted(clip).toFillPolygon();
0
371}-
372-
373-
374-
375-
376-
377QPolygonF::operator QVariant() const-
378{-
379 return
never executed: return QVariant(QMetaType::QPolygonF, this);
QVariant(QMetaType::QPolygonF, this);
never executed: return QVariant(QMetaType::QPolygonF, this);
0
380}-
381-
382-
Switch to Source codePreprocessed file

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