painting/qpolygon.cpp

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

Generated by Squish Coco Non-Commercial