painting/qbezier.cpp

Switch to Source codePreprocessed file
LineSource CodeCoverage
1 -
2 -
3 -
4 -
5 -
6 -
7 -
8 -
9 -
10QBezier QBezier::fromPoints(const QPointF &p1, const QPointF &p2, -
11 const QPointF &p3, const QPointF &p4) -
12{ -
13 QBezier b; -
14 b.x1 = p1.x(); -
15 b.y1 = p1.y(); -
16 b.x2 = p2.x(); -
17 b.y2 = p2.y(); -
18 b.x3 = p3.x(); -
19 b.y3 = p3.y(); -
20 b.x4 = p4.x(); -
21 b.y4 = p4.y(); -
22 return b;
executed: return b;
Execution Count:36081
36081
23} -
24 -
25 -
26 -
27 -
28QPolygonF QBezier::toPolygon(qreal bezier_flattening_threshold) const -
29{ -
30 QPolygonF polygon; -
31 polygon.append(QPointF(x1, y1)); -
32 addToPolygon(&polygon, bezier_flattening_threshold); -
33 return polygon;
never executed: return polygon;
0
34} -
35 -
36QBezier QBezier::mapBy(const QTransform &transform) const -
37{ -
38 return QBezier::fromPoints(transform.map(pt1()), transform.map(pt2()), transform.map(pt3()), transform.map(pt4()));
never executed: return QBezier::fromPoints(transform.map(pt1()), transform.map(pt2()), transform.map(pt3()), transform.map(pt4()));
0
39} -
40 -
41QBezier QBezier::getSubRange(qreal t0, qreal t1) const -
42{ -
43 QBezier result; -
44 QBezier temp; -
45 -
46 -
47 if (qFuzzyIsNull(t1 - qreal(1.))) {
never evaluated: qFuzzyIsNull(t1 - qreal(1.))
0
48 result = *this; -
49 } else {
never executed: }
0
50 temp = *this; -
51 temp.parameterSplitLeft(t1, &result); -
52 }
never executed: }
0
53 -
54 -
55 if (!qFuzzyIsNull(t0))
never evaluated: !qFuzzyIsNull(t0)
0
56 result.parameterSplitLeft(t0 / t1, &temp);
never executed: result.parameterSplitLeft(t0 / t1, &temp);
0
57 -
58 return result;
never executed: return result;
0
59} -
60 -
61static inline int quadraticRoots(qreal a, qreal b, qreal c, -
62 qreal *x1, qreal *x2) -
63{ -
64 if (qFuzzyIsNull(a)) {
never evaluated: qFuzzyIsNull(a)
0
65 if (qFuzzyIsNull(b))
never evaluated: qFuzzyIsNull(b)
0
66 return 0;
never executed: return 0;
0
67 *x1 = *x2 = (-c / b); -
68 return 1;
never executed: return 1;
0
69 } else { -
70 const qreal det = b * b - 4 * a * c; -
71 if (qFuzzyIsNull(det)) {
never evaluated: qFuzzyIsNull(det)
0
72 *x1 = *x2 = -b / (2 * a); -
73 return 1;
never executed: return 1;
0
74 } -
75 if (det > 0) {
never evaluated: det > 0
0
76 if (qFuzzyIsNull(b)) {
never evaluated: qFuzzyIsNull(b)
0
77 *x2 = qSqrt(-c / a); -
78 *x1 = -(*x2); -
79 return 2;
never executed: return 2;
0
80 } -
81 const qreal stableA = b / (2 * a); -
82 const qreal stableB = c / (a * stableA * stableA); -
83 const qreal stableC = -1 - qSqrt(1 - stableB); -
84 *x2 = stableA * stableC; -
85 *x1 = (stableA * stableB) / stableC; -
86 return 2;
never executed: return 2;
0
87 } else -
88 return 0;
never executed: return 0;
0
89 } -
90} -
91 -
92static inline bool findInflections(qreal a, qreal b, qreal c, -
93 qreal *t1 , qreal *t2, qreal *tCups) -
94{ -
95 qreal r1 = 0, r2 = 0; -
96 -
97 short rootsCount = quadraticRoots(a, b, c, &r1, &r2); -
98 -
99 if (rootsCount >= 1) {
never evaluated: rootsCount >= 1
0
100 if (r1 < r2) {
never evaluated: r1 < r2
0
101 *t1 = r1; -
102 *t2 = r2; -
103 } else {
never executed: }
0
104 *t1 = r2; -
105 *t2 = r1; -
106 }
never executed: }
0
107 if (!qFuzzyIsNull(a))
never evaluated: !qFuzzyIsNull(a)
0
108 *tCups = qreal(0.5) * (-b / a);
never executed: *tCups = qreal(0.5) * (-b / a);
0
109 else -
110 *tCups = 2;
never executed: *tCups = 2;
0
111 -
112 return true;
never executed: return true;
0
113 } -
114 -
115 return false;
never executed: return false;
0
116} -
117 -
118 -
119void QBezier::addToPolygon(QPolygonF *polygon, qreal bezier_flattening_threshold) const -
120{ -
121 QBezier beziers[10]; -
122 int levels[10]; -
123 beziers[0] = *this; -
124 levels[0] = 9; -
125 QBezier *b = beziers; -
126 int *lvl = levels; -
127 -
128 while (b >= beziers) {
evaluated: b >= beziers
TRUEFALSE
yes
Evaluation Count:2031
yes
Evaluation Count:105
105-2031
129 -
130 qreal y4y1 = b->y4 - b->y1; -
131 qreal x4x1 = b->x4 - b->x1; -
132 qreal l = qAbs(x4x1) + qAbs(y4y1); -
133 qreal d; -
134 if (l > 1.) {
partially evaluated: l > 1.
TRUEFALSE
yes
Evaluation Count:2031
no
Evaluation Count:0
0-2031
135 d = qAbs( (x4x1)*(b->y1 - b->y2) - (y4y1)*(b->x1 - b->x2) ) -
136 + qAbs( (x4x1)*(b->y1 - b->y3) - (y4y1)*(b->x1 - b->x3) ); -
137 } else {
executed: }
Execution Count:2031
2031
138 d = qAbs(b->x1 - b->x2) + qAbs(b->y1 - b->y2) + -
139 qAbs(b->x1 - b->x3) + qAbs(b->y1 - b->y3); -
140 l = 1.; -
141 }
never executed: }
0
142 if (d < bezier_flattening_threshold*l || *lvl == 0) {
evaluated: d < bezier_flattening_threshold*l
TRUEFALSE
yes
Evaluation Count:1068
yes
Evaluation Count:963
partially evaluated: *lvl == 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:963
0-1068
143 -
144 polygon->append(QPointF(b->x4, b->y4)); -
145 --b; -
146 --lvl; -
147 } else {
executed: }
Execution Count:1068
1068
148 -
149 b->split(b+1, b); -
150 lvl[1] = --lvl[0]; -
151 ++b; -
152 ++lvl; -
153 }
executed: }
Execution Count:963
963
154 } -
155}
executed: }
Execution Count:105
105
156 -
157void QBezier::addToPolygon(QDataBuffer<QPointF> &polygon, qreal bezier_flattening_threshold) const -
158{ -
159 QBezier beziers[10]; -
160 int levels[10]; -
161 beziers[0] = *this; -
162 levels[0] = 9; -
163 QBezier *b = beziers; -
164 int *lvl = levels; -
165 -
166 while (b >= beziers) {
evaluated: b >= beziers
TRUEFALSE
yes
Evaluation Count:453128
yes
Evaluation Count:11216
11216-453128
167 -
168 qreal y4y1 = b->y4 - b->y1; -
169 qreal x4x1 = b->x4 - b->x1; -
170 qreal l = qAbs(x4x1) + qAbs(y4y1); -
171 qreal d; -
172 if (l > 1.) {
evaluated: l > 1.
TRUEFALSE
yes
Evaluation Count:276642
yes
Evaluation Count:176486
176486-276642
173 d = qAbs( (x4x1)*(b->y1 - b->y2) - (y4y1)*(b->x1 - b->x2) ) -
174 + qAbs( (x4x1)*(b->y1 - b->y3) - (y4y1)*(b->x1 - b->x3) ); -
175 } else {
executed: }
Execution Count:276642
276642
176 d = qAbs(b->x1 - b->x2) + qAbs(b->y1 - b->y2) + -
177 qAbs(b->x1 - b->x3) + qAbs(b->y1 - b->y3); -
178 l = 1.; -
179 }
executed: }
Execution Count:176486
176486
180 if (d < bezier_flattening_threshold*l || *lvl == 0) {
evaluated: d < bezier_flattening_threshold*l
TRUEFALSE
yes
Evaluation Count:229590
yes
Evaluation Count:223538
evaluated: *lvl == 0
TRUEFALSE
yes
Evaluation Count:2582
yes
Evaluation Count:220956
2582-229590
181 -
182 polygon.add(QPointF(b->x4, b->y4)); -
183 --b; -
184 --lvl; -
185 } else {
executed: }
Execution Count:232172
232172
186 -
187 b->split(b+1, b); -
188 lvl[1] = --lvl[0]; -
189 ++b; -
190 ++lvl; -
191 }
executed: }
Execution Count:220956
220956
192 } -
193}
executed: }
Execution Count:11216
11216
194 -
195QRectF QBezier::bounds() const -
196{ -
197 qreal xmin = x1; -
198 qreal xmax = x1; -
199 if (x2 < xmin)
evaluated: x2 < xmin
TRUEFALSE
yes
Evaluation Count:6268
yes
Evaluation Count:10802
6268-10802
200 xmin = x2;
executed: xmin = x2;
Execution Count:6268
6268
201 else if (x2 > xmax)
evaluated: x2 > xmax
TRUEFALSE
yes
Evaluation Count:5850
yes
Evaluation Count:4952
4952-5850
202 xmax = x2;
executed: xmax = x2;
Execution Count:5850
5850
203 if (x3 < xmin)
evaluated: x3 < xmin
TRUEFALSE
yes
Evaluation Count:8906
yes
Evaluation Count:8164
8164-8906
204 xmin = x3;
executed: xmin = x3;
Execution Count:8906
8906
205 else if (x3 > xmax)
evaluated: x3 > xmax
TRUEFALSE
yes
Evaluation Count:8146
yes
Evaluation Count:18
18-8146
206 xmax = x3;
executed: xmax = x3;
Execution Count:8146
8146
207 if (x4 < xmin)
evaluated: x4 < xmin
TRUEFALSE
yes
Evaluation Count:6283
yes
Evaluation Count:10787
6283-10787
208 xmin = x4;
executed: xmin = x4;
Execution Count:6283
6283
209 else if (x4 > xmax)
evaluated: x4 > xmax
TRUEFALSE
yes
Evaluation Count:5787
yes
Evaluation Count:5000
5000-5787
210 xmax = x4;
executed: xmax = x4;
Execution Count:5787
5787
211 -
212 qreal ymin = y1; -
213 qreal ymax = y1; -
214 if (y2 < ymin)
evaluated: y2 < ymin
TRUEFALSE
yes
Evaluation Count:6199
yes
Evaluation Count:10871
6199-10871
215 ymin = y2;
executed: ymin = y2;
Execution Count:6199
6199
216 else if (y2 > ymax)
evaluated: y2 > ymax
TRUEFALSE
yes
Evaluation Count:6304
yes
Evaluation Count:4567
4567-6304
217 ymax = y2;
executed: ymax = y2;
Execution Count:6304
6304
218 if (y3 < ymin)
evaluated: y3 < ymin
TRUEFALSE
yes
Evaluation Count:8457
yes
Evaluation Count:8613
8457-8613
219 ymin = y3;
executed: ymin = y3;
Execution Count:8457
8457
220 else if (y3 > ymax)
evaluated: y3 > ymax
TRUEFALSE
yes
Evaluation Count:8600
yes
Evaluation Count:13
13-8600
221 ymax = y3;
executed: ymax = y3;
Execution Count:8600
8600
222 if (y4 < ymin)
evaluated: y4 < ymin
TRUEFALSE
yes
Evaluation Count:6152
yes
Evaluation Count:10918
6152-10918
223 ymin = y4;
executed: ymin = y4;
Execution Count:6152
6152
224 else if (y4 > ymax)
evaluated: y4 > ymax
TRUEFALSE
yes
Evaluation Count:6331
yes
Evaluation Count:4587
4587-6331
225 ymax = y4;
executed: ymax = y4;
Execution Count:6331
6331
226 return QRectF(xmin, ymin, xmax-xmin, ymax-ymin);
executed: return QRectF(xmin, ymin, xmax-xmin, ymax-ymin);
Execution Count:17070
17070
227} -
228 -
229 -
230enum ShiftResult { -
231 Ok, -
232 Discard, -
233 Split, -
234 Circle -
235}; -
236 -
237static ShiftResult good_offset(const QBezier *b1, const QBezier *b2, qreal offset, qreal threshold) -
238{ -
239 const qreal o2 = offset*offset; -
240 const qreal max_dist_line = threshold*offset*offset; -
241 const qreal max_dist_normal = threshold*offset; -
242 const qreal spacing = qreal(0.25); -
243 for (qreal i = spacing; i < qreal(0.99); i += spacing) {
evaluated: i < qreal(0.99)
TRUEFALSE
yes
Evaluation Count:22820
yes
Evaluation Count:7504
7504-22820
244 QPointF p1 = b1->pointAt(i); -
245 QPointF p2 = b2->pointAt(i); -
246 qreal d = (p1.x() - p2.x())*(p1.x() - p2.x()) + (p1.y() - p2.y())*(p1.y() - p2.y()); -
247 if (qAbs(d - o2) > max_dist_line)
evaluated: qAbs(d - o2) > max_dist_line
TRUEFALSE
yes
Evaluation Count:8
yes
Evaluation Count:22812
8-22812
248 return Split;
executed: return Split;
Execution Count:8
8
249 -
250 QPointF normalPoint = b1->normalVector(i); -
251 qreal l = qAbs(normalPoint.x()) + qAbs(normalPoint.y()); -
252 if (l != qreal(0.0)) {
partially evaluated: l != qreal(0.0)
TRUEFALSE
yes
Evaluation Count:22812
no
Evaluation Count:0
0-22812
253 d = qAbs( normalPoint.x()*(p1.y() - p2.y()) - normalPoint.y()*(p1.x() - p2.x()) ) / l; -
254 if (d > max_dist_normal)
evaluated: d > max_dist_normal
TRUEFALSE
yes
Evaluation Count:200
yes
Evaluation Count:22612
200-22612
255 return Split;
executed: return Split;
Execution Count:200
200
256 }
executed: }
Execution Count:22612
22612
257 }
executed: }
Execution Count:22612
22612
258 return Ok;
executed: return Ok;
Execution Count:7504
7504
259} -
260 -
261static ShiftResult shift(const QBezier *orig, QBezier *shifted, qreal offset, qreal threshold) -
262{ -
263 int map[4]; -
264 bool p1_p2_equal = (orig->x1 == orig->x2 && orig->y1 == orig->y2);
evaluated: orig->x1 == orig->x2
TRUEFALSE
yes
Evaluation Count:3744
yes
Evaluation Count:3968
partially evaluated: orig->y1 == orig->y2
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:3744
0-3968
265 bool p2_p3_equal = (orig->x2 == orig->x3 && orig->y2 == orig->y3);
evaluated: orig->x2 == orig->x3
TRUEFALSE
yes
Evaluation Count:8
yes
Evaluation Count:7704
partially evaluated: orig->y2 == orig->y3
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:8
0-7704
266 bool p3_p4_equal = (orig->x3 == orig->x4 && orig->y3 == orig->y4);
evaluated: orig->x3 == orig->x4
TRUEFALSE
yes
Evaluation Count:3744
yes
Evaluation Count:3968
partially evaluated: orig->y3 == orig->y4
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:3744
0-3968
267 -
268 QPointF points[4]; -
269 int np = 0; -
270 points[np] = QPointF(orig->x1, orig->y1); -
271 map[0] = 0; -
272 ++np; -
273 if (!p1_p2_equal) {
partially evaluated: !p1_p2_equal
TRUEFALSE
yes
Evaluation Count:7712
no
Evaluation Count:0
0-7712
274 points[np] = QPointF(orig->x2, orig->y2); -
275 ++np; -
276 }
executed: }
Execution Count:7712
7712
277 map[1] = np - 1; -
278 if (!p2_p3_equal) {
partially evaluated: !p2_p3_equal
TRUEFALSE
yes
Evaluation Count:7712
no
Evaluation Count:0
0-7712
279 points[np] = QPointF(orig->x3, orig->y3); -
280 ++np; -
281 }
executed: }
Execution Count:7712
7712
282 map[2] = np - 1; -
283 if (!p3_p4_equal) {
partially evaluated: !p3_p4_equal
TRUEFALSE
yes
Evaluation Count:7712
no
Evaluation Count:0
0-7712
284 points[np] = QPointF(orig->x4, orig->y4); -
285 ++np; -
286 }
executed: }
Execution Count:7712
7712
287 map[3] = np - 1; -
288 if (np == 1)
partially evaluated: np == 1
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:7712
0-7712
289 return Discard;
never executed: return Discard;
0
290 -
291 QRectF b = orig->bounds(); -
292 if (np == 4 && b.width() < .1*offset && b.height() < .1*offset) {
partially evaluated: np == 4
TRUEFALSE
yes
Evaluation Count:7712
no
Evaluation Count:0
partially evaluated: b.width() < .1*offset
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:7712
never evaluated: b.height() < .1*offset
0-7712
293 qreal l = (orig->x1 - orig->x2)*(orig->x1 - orig->x2) + -
294 (orig->y1 - orig->y2)*(orig->y1 - orig->y2) * -
295 (orig->x3 - orig->x4)*(orig->x3 - orig->x4) + -
296 (orig->y3 - orig->y4)*(orig->y3 - orig->y4); -
297 qreal dot = (orig->x1 - orig->x2)*(orig->x3 - orig->x4) + -
298 (orig->y1 - orig->y2)*(orig->y3 - orig->y4); -
299 if (dot < 0 && dot*dot < 0.8*l)
never evaluated: dot < 0
never evaluated: dot*dot < 0.8*l
0
300 -
301 -
302 return Circle;
never executed: return Circle;
0
303 }
never executed: }
0
304 -
305 QPointF points_shifted[4]; -
306 -
307 QLineF prev = QLineF(QPointF(), points[1] - points[0]); -
308 QPointF prev_normal = prev.normalVector().unitVector().p2(); -
309 -
310 points_shifted[0] = points[0] + offset * prev_normal; -
311 -
312 for (int i = 1; i < np - 1; ++i) {
evaluated: i < np - 1
TRUEFALSE
yes
Evaluation Count:15424
yes
Evaluation Count:7712
7712-15424
313 QLineF next = QLineF(QPointF(), points[i + 1] - points[i]); -
314 QPointF next_normal = next.normalVector().unitVector().p2(); -
315 -
316 QPointF normal_sum = prev_normal + next_normal; -
317 -
318 qreal r = qreal(1.0) + prev_normal.x() * next_normal.x() -
319 + prev_normal.y() * next_normal.y(); -
320 -
321 if (qFuzzyIsNull(r)) {
partially evaluated: qFuzzyIsNull(r)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:15424
0-15424
322 points_shifted[i] = points[i] + offset * prev_normal; -
323 } else {
never executed: }
0
324 qreal k = offset / r; -
325 points_shifted[i] = points[i] + k * normal_sum; -
326 }
executed: }
Execution Count:15424
15424
327 -
328 prev_normal = next_normal; -
329 }
executed: }
Execution Count:15424
15424
330 -
331 points_shifted[np - 1] = points[np - 1] + offset * prev_normal; -
332 -
333 *shifted = QBezier::fromPoints(points_shifted[map[0]], points_shifted[map[1]], -
334 points_shifted[map[2]], points_shifted[map[3]]); -
335 -
336 return good_offset(orig, shifted, offset, threshold);
executed: return good_offset(orig, shifted, offset, threshold);
Execution Count:7712
7712
337} -
338 -
339 -
340 -
341 -
342 -
343 -
344 -
345static bool addCircle(const QBezier *b, qreal offset, QBezier *o) -
346{ -
347 QPointF normals[3]; -
348 -
349 normals[0] = QPointF(b->y2 - b->y1, b->x1 - b->x2); -
350 qreal dist = qSqrt(normals[0].x()*normals[0].x() + normals[0].y()*normals[0].y()); -
351 if (qFuzzyIsNull(dist))
never evaluated: qFuzzyIsNull(dist)
0
352 return false;
never executed: return false;
0
353 normals[0] /= dist; -
354 normals[2] = QPointF(b->y4 - b->y3, b->x3 - b->x4); -
355 dist = qSqrt(normals[2].x()*normals[2].x() + normals[2].y()*normals[2].y()); -
356 if (qFuzzyIsNull(dist))
never evaluated: qFuzzyIsNull(dist)
0
357 return false;
never executed: return false;
0
358 normals[2] /= dist; -
359 -
360 normals[1] = QPointF(b->x1 - b->x2 - b->x3 + b->x4, b->y1 - b->y2 - b->y3 + b->y4); -
361 normals[1] /= -1*qSqrt(normals[1].x()*normals[1].x() + normals[1].y()*normals[1].y()); -
362 -
363 qreal angles[2]; -
364 qreal sign = 1.; -
365 for (int i = 0; i < 2; ++i) {
never evaluated: i < 2
0
366 qreal cos_a = normals[i].x()*normals[i+1].x() + normals[i].y()*normals[i+1].y(); -
367 if (cos_a > 1.)
never evaluated: cos_a > 1.
0
368 cos_a = 1.;
never executed: cos_a = 1.;
0
369 if (cos_a < -1.)
never evaluated: cos_a < -1.
0
370 cos_a = -1;
never executed: cos_a = -1;
0
371 angles[i] = qAcos(cos_a)/Q_PI; -
372 }
never executed: }
0
373 -
374 if (angles[0] + angles[1] > 1.) {
never evaluated: angles[0] + angles[1] > 1.
0
375 -
376 normals[1] = -normals[1]; -
377 angles[0] = 1. - angles[0]; -
378 angles[1] = 1. - angles[1]; -
379 sign = -1.; -
380 -
381 }
never executed: }
0
382 -
383 QPointF circle[3]; -
384 circle[0] = QPointF(b->x1, b->y1) + normals[0]*offset; -
385 circle[1] = QPointF(qreal(0.5)*(b->x1 + b->x4), qreal(0.5)*(b->y1 + b->y4)) + normals[1]*offset; -
386 circle[2] = QPointF(b->x4, b->y4) + normals[2]*offset; -
387 -
388 for (int i = 0; i < 2; ++i) {
never evaluated: i < 2
0
389 qreal kappa = qreal(2.0) * qreal(0.5522847498) * sign * offset * angles[i]; -
390 -
391 o->x1 = circle[i].x(); -
392 o->y1 = circle[i].y(); -
393 o->x2 = circle[i].x() - normals[i].y()*kappa; -
394 o->y2 = circle[i].y() + normals[i].x()*kappa; -
395 o->x3 = circle[i+1].x() + normals[i+1].y()*kappa; -
396 o->y3 = circle[i+1].y() - normals[i+1].x()*kappa; -
397 o->x4 = circle[i+1].x(); -
398 o->y4 = circle[i+1].y(); -
399 -
400 ++o; -
401 }
never executed: }
0
402 return true;
never executed: return true;
0
403} -
404 -
405int QBezier::shifted(QBezier *curveSegments, int maxSegments, qreal offset, float threshold) const -
406{ -
407 qt_noop(); -
408 qt_noop(); -
409 -
410 if (x1 == x2 && x1 == x3 && x1 == x4 &&
evaluated: x1 == x2
TRUEFALSE
yes
Evaluation Count:3644
yes
Evaluation Count:3652
partially evaluated: x1 == x3
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:3644
never evaluated: x1 == x4
0-3652
411 y1 == y2 && y1 == y3 && y1 == y4)
never evaluated: y1 == y2
never evaluated: y1 == y3
never evaluated: y1 == y4
0
412 return 0;
never executed: return 0;
0
413 -
414 --maxSegments; -
415 QBezier beziers[10]; -
416redo:
code before this statement executed: redo:
Execution Count:7296
7296
417 beziers[0] = *this; -
418 QBezier *b = beziers; -
419 QBezier *o = curveSegments; -
420 -
421 while (b >= beziers) {
evaluated: b >= beziers
TRUEFALSE
yes
Evaluation Count:7712
yes
Evaluation Count:7296
7296-7712
422 int stack_segments = b - beziers + 1; -
423 if ((stack_segments == 10) || (o - curveSegments == maxSegments - stack_segments)) {
partially evaluated: (stack_segments == 10)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:7712
partially evaluated: (o - curveSegments == maxSegments - stack_segments)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:7712
0-7712
424 threshold *= qreal(1.5); -
425 if (threshold > qreal(2.0))
never evaluated: threshold > qreal(2.0)
0
426 goto give_up;
never executed: goto give_up;
0
427 goto redo;
never executed: goto redo;
0
428 } -
429 ShiftResult res = shift(b, o, offset, threshold); -
430 if (res == Discard) {
partially evaluated: res == Discard
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:7712
0-7712
431 --b; -
432 } else if (res == Ok) {
evaluated: res == Ok
TRUEFALSE
yes
Evaluation Count:7504
yes
Evaluation Count:208
never executed: }
0-7504
433 ++o; -
434 --b; -
435 continue;
executed: continue;
Execution Count:7504
7504
436 } else if (res == Circle && maxSegments - (o - curveSegments) >= 2) {
partially evaluated: res == Circle
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:208
never evaluated: maxSegments - (o - curveSegments) >= 2
0-208
437 -
438 if (addCircle(b, offset, o))
never evaluated: addCircle(b, offset, o)
0
439 o += 2;
never executed: o += 2;
0
440 --b; -
441 } else {
never executed: }
0
442 b->split(b+1, b); -
443 ++b; -
444 }
executed: }
Execution Count:208
208
445 } -
446 -
447give_up:
code before this statement executed: give_up:
Execution Count:7296
7296
448 while (b >= beziers) {
partially evaluated: b >= beziers
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:7296
0-7296
449 ShiftResult res = shift(b, o, offset, threshold); -
450 -
451 -
452 if (res == Ok || res == Split)
never evaluated: res == Ok
never evaluated: res == Split
0
453 ++o;
never executed: ++o;
0
454 -
455 --b; -
456 }
never executed: }
0
457 -
458 qt_noop(); -
459 return o - curveSegments;
executed: return o - curveSegments;
Execution Count:7296
7296
460} -
461static inline void splitBezierAt(const QBezier &bez, qreal t, -
462 QBezier *left, QBezier *right) -
463{ -
464 left->x1 = bez.x1; -
465 left->y1 = bez.y1; -
466 -
467 left->x2 = bez.x1 + t * ( bez.x2 - bez.x1 ); -
468 left->y2 = bez.y1 + t * ( bez.y2 - bez.y1 ); -
469 -
470 left->x3 = bez.x2 + t * ( bez.x3 - bez.x2 ); -
471 left->y3 = bez.y2 + t * ( bez.y3 - bez.y2 ); -
472 -
473 right->x3 = bez.x3 + t * ( bez.x4 - bez.x3 ); -
474 right->y3 = bez.y3 + t * ( bez.y4 - bez.y3 ); -
475 -
476 right->x2 = left->x3 + t * ( right->x3 - left->x3); -
477 right->y2 = left->y3 + t * ( right->y3 - left->y3); -
478 -
479 left->x3 = left->x2 + t * ( left->x3 - left->x2 ); -
480 left->y3 = left->y2 + t * ( left->y3 - left->y2 ); -
481 -
482 left->x4 = right->x1 = left->x3 + t * (right->x2 - left->x3); -
483 left->y4 = right->y1 = left->y3 + t * (right->y2 - left->y3); -
484 -
485 right->x4 = bez.x4; -
486 right->y4 = bez.y4; -
487}
never executed: }
0
488 -
489qreal QBezier::length(qreal error) const -
490{ -
491 qreal length = qreal(0.0); -
492 -
493 addIfClose(&length, error); -
494 -
495 return length;
executed: return length;
Execution Count:111
111
496} -
497 -
498void QBezier::addIfClose(qreal *length, qreal error) const -
499{ -
500 QBezier left, right; -
501 -
502 qreal len = qreal(0.0); -
503 qreal chord; -
504 -
505 len = len + QLineF(QPointF(x1, y1),QPointF(x2, y2)).length(); -
506 len = len + QLineF(QPointF(x2, y2),QPointF(x3, y3)).length(); -
507 len = len + QLineF(QPointF(x3, y3),QPointF(x4, y4)).length(); -
508 -
509 chord = QLineF(QPointF(x1, y1),QPointF(x4, y4)).length(); -
510 -
511 if((len-chord) > error) {
evaluated: (len-chord) > error
TRUEFALSE
yes
Evaluation Count:2748
yes
Evaluation Count:2859
2748-2859
512 split(&left, &right); -
513 left.addIfClose(length, error); -
514 right.addIfClose(length, error); -
515 return;
executed: return;
Execution Count:2748
2748
516 } -
517 -
518 *length = *length + len; -
519 -
520 return;
executed: return;
Execution Count:2859
2859
521} -
522 -
523qreal QBezier::tForY(qreal t0, qreal t1, qreal y) const -
524{ -
525 qreal py0 = pointAt(t0).y(); -
526 qreal py1 = pointAt(t1).y(); -
527 -
528 if (py0 > py1) {
never evaluated: py0 > py1
0
529 qSwap(py0, py1); -
530 qSwap(t0, t1); -
531 }
never executed: }
0
532 -
533 qt_noop(); -
534 -
535 if (py0 >= y)
never evaluated: py0 >= y
0
536 return t0;
never executed: return t0;
0
537 else if (py1 <= y)
never evaluated: py1 <= y
0
538 return t1;
never executed: return t1;
0
539 -
540 qt_noop(); -
541 -
542 qreal lt = t0; -
543 qreal dt; -
544 do { -
545 qreal t = qreal(0.5) * (t0 + t1); -
546 -
547 qreal a, b, c, d; -
548 QBezier::coefficients(t, a, b, c, d); -
549 qreal yt = a * y1 + b * y2 + c * y3 + d * y4; -
550 -
551 if (yt < y) {
never evaluated: yt < y
0
552 t0 = t; -
553 py0 = yt; -
554 } else {
never executed: }
0
555 t1 = t; -
556 py1 = yt; -
557 }
never executed: }
0
558 dt = lt - t; -
559 lt = t; -
560 } while (qAbs(dt) > qreal(1e-7));
never evaluated: qAbs(dt) > qreal(1e-7)
never executed: }
0
561 -
562 return t0;
never executed: return t0;
0
563} -
564 -
565int QBezier::stationaryYPoints(qreal &t0, qreal &t1) const -
566{ -
567 -
568 -
569 -
570 -
571 const qreal a = -y1 + 3 * y2 - 3 * y3 + y4; -
572 const qreal b = 2 * y1 - 4 * y2 + 2 * y3; -
573 const qreal c = -y1 + y2; -
574 -
575 if (qFuzzyIsNull(a)) {
never evaluated: qFuzzyIsNull(a)
0
576 if (qFuzzyIsNull(b))
never evaluated: qFuzzyIsNull(b)
0
577 return 0;
never executed: return 0;
0
578 -
579 t0 = -c / b; -
580 return t0 > 0 && t0 < 1;
never executed: return t0 > 0 && t0 < 1;
0
581 } -
582 -
583 qreal reciprocal = b * b - 4 * a * c; -
584 -
585 if (qFuzzyIsNull(reciprocal)) {
never evaluated: qFuzzyIsNull(reciprocal)
0
586 t0 = -b / (2 * a); -
587 return t0 > 0 && t0 < 1;
never executed: return t0 > 0 && t0 < 1;
0
588 } else if (reciprocal > 0) {
never evaluated: reciprocal > 0
0
589 qreal temp = qSqrt(reciprocal); -
590 -
591 t0 = (-b - temp)/(2*a); -
592 t1 = (-b + temp)/(2*a); -
593 -
594 if (t1 < t0)
never evaluated: t1 < t0
0
595 qSwap(t0, t1);
never executed: qSwap(t0, t1);
0
596 -
597 int count = 0; -
598 qreal t[2] = { 0, 1 }; -
599 -
600 if (t0 > 0 && t0 < 1)
never evaluated: t0 > 0
never evaluated: t0 < 1
0
601 t[count++] = t0;
never executed: t[count++] = t0;
0
602 if (t1 > 0 && t1 < 1)
never evaluated: t1 > 0
never evaluated: t1 < 1
0
603 t[count++] = t1;
never executed: t[count++] = t1;
0
604 -
605 t0 = t[0]; -
606 t1 = t[1]; -
607 -
608 return count;
never executed: return count;
0
609 } -
610 -
611 return 0;
never executed: return 0;
0
612} -
613 -
614qreal QBezier::tAtLength(qreal l) const -
615{ -
616 qreal len = length(); -
617 qreal t = qreal(1.0); -
618 const qreal error = qreal(0.01); -
619 if (l > len || qFuzzyCompare(l, len))
never evaluated: l > len
never evaluated: qFuzzyCompare(l, len)
0
620 return t;
never executed: return t;
0
621 -
622 t *= qreal(0.5); -
623 -
624 -
625 qreal lastBigger = qreal(1.0); -
626 while (1) {
never evaluated: 1
0
627 -
628 QBezier right = *this; -
629 QBezier left; -
630 right.parameterSplitLeft(t, &left); -
631 qreal lLen = left.length(); -
632 if (qAbs(lLen - l) < error)
never evaluated: qAbs(lLen - l) < error
0
633 break;
never executed: break;
0
634 -
635 if (lLen < l) {
never evaluated: lLen < l
0
636 t += (lastBigger - t) * qreal(0.5); -
637 } else {
never executed: }
0
638 lastBigger = t; -
639 t -= t * qreal(0.5); -
640 }
never executed: }
0
641 -
642 } -
643 -
644 return t;
never executed: return t;
0
645} -
646 -
647QBezier QBezier::bezierOnInterval(qreal t0, qreal t1) const -
648{ -
649 if (t0 == 0 && t1 == 1)
evaluated: t0 == 0
TRUEFALSE
yes
Evaluation Count:1942
yes
Evaluation Count:5731
partially evaluated: t1 == 1
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1942
0-5731
650 return *this;
never executed: return *this;
0
651 -
652 QBezier bezier = *this; -
653 -
654 QBezier result; -
655 bezier.parameterSplitLeft(t0, &result); -
656 qreal trueT = (t1-t0)/(1-t0); -
657 bezier.parameterSplitLeft(trueT, &result); -
658 -
659 return result;
executed: return result;
Execution Count:7673
7673
660} -
661 -
662 -
663 -
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial