Line | Source | Count |
1 | | - |
2 | | - |
3 | | - |
4 | | - |
5 | | - |
6 | | - |
7 | | - |
8 | | - |
9 | | - |
10 | | - |
11 | | - |
12 | | - |
13 | | - |
14 | | - |
15 | | - |
16 | | - |
17 | | - |
18 | | - |
19 | | - |
20 | | - |
21 | | - |
22 | | - |
23 | | - |
24 | | - |
25 | | - |
26 | | - |
27 | | - |
28 | | - |
29 | | - |
30 | | - |
31 | | - |
32 | | - |
33 | | - |
34 | | - |
35 | | - |
36 | | - |
37 | | - |
38 | | - |
39 | | - |
40 | #include "qbezier_p.h" | - |
41 | #include <qdebug.h> | - |
42 | #include <qline.h> | - |
43 | #include <qpolygon.h> | - |
44 | #include <qvector.h> | - |
45 | #include <qlist.h> | - |
46 | #include <qmath.h> | - |
47 | | - |
48 | #include <private/qnumeric_p.h> | - |
49 | | - |
50 | QT_BEGIN_NAMESPACE | - |
51 | | - |
52 | | - |
53 | | - |
54 | | - |
55 | | - |
56 | | - |
57 | QBezier QBezier::fromPoints(const QPointF &p1, const QPointF &p2, | - |
58 | const QPointF &p3, const QPointF &p4) | - |
59 | { | - |
60 | QBezier b; | - |
61 | b.x1 = p1.x(); | - |
62 | b.y1 = p1.y(); | - |
63 | b.x2 = p2.x(); | - |
64 | b.y2 = p2.y(); | - |
65 | b.x3 = p3.x(); | - |
66 | b.y3 = p3.y(); | - |
67 | b.x4 = p4.x(); | - |
68 | b.y4 = p4.y(); | - |
69 | return b; never executed: return b; | 0 |
70 | } | - |
71 | | - |
72 | | - |
73 | | - |
74 | | - |
75 | QPolygonF QBezier::toPolygon(qreal bezier_flattening_threshold) const | - |
76 | { | - |
77 | | - |
78 | | - |
79 | | - |
80 | | - |
81 | | - |
82 | | - |
83 | | - |
84 | | - |
85 | | - |
86 | | - |
87 | | - |
88 | QPolygonF polygon; | - |
89 | polygon.append(QPointF(x1, y1)); | - |
90 | addToPolygon(&polygon, bezier_flattening_threshold); | - |
91 | return polygon; never executed: return polygon; | 0 |
92 | } | - |
93 | | - |
94 | QBezier QBezier::mapBy(const QTransform &transform) const | - |
95 | { | - |
96 | 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 |
97 | } | - |
98 | | - |
99 | QBezier QBezier::getSubRange(qreal t0, qreal t1) const | - |
100 | { | - |
101 | QBezier result; | - |
102 | QBezier temp; | - |
103 | | - |
104 | | - |
105 | if (qFuzzyIsNull(t1 - qreal(1.))) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
106 | result = *this; | - |
107 | } else { never executed: end of block | 0 |
108 | temp = *this; | - |
109 | temp.parameterSplitLeft(t1, &result); | - |
110 | } never executed: end of block | 0 |
111 | | - |
112 | | - |
113 | if (!qFuzzyIsNull(t0))TRUE | never evaluated | FALSE | never evaluated |
| 0 |
114 | result.parameterSplitLeft(t0 / t1, &temp); never executed: result.parameterSplitLeft(t0 / t1, &temp); | 0 |
115 | | - |
116 | return result; never executed: return result; | 0 |
117 | } | - |
118 | | - |
119 | void 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) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
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.) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
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 { never executed: end of block | 0 |
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: end of block | 0 |
142 | if (d < bezier_flattening_threshold*l || *lvl == 0) {TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
143 | | - |
144 | polygon->append(QPointF(b->x4, b->y4)); | - |
145 | --b; | - |
146 | --lvl; | - |
147 | } else { never executed: end of block | 0 |
148 | | - |
149 | b->split(b+1, b); | - |
150 | lvl[1] = --lvl[0]; | - |
151 | ++b; | - |
152 | ++lvl; | - |
153 | } never executed: end of block | 0 |
154 | } | - |
155 | } never executed: end of block | 0 |
156 | | - |
157 | void 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) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
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.) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
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 { never executed: end of block | 0 |
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 | } never executed: end of block | 0 |
180 | if (d < bezier_flattening_threshold*l || *lvl == 0) {TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
181 | | - |
182 | polygon.add(QPointF(b->x4, b->y4)); | - |
183 | --b; | - |
184 | --lvl; | - |
185 | } else { never executed: end of block | 0 |
186 | | - |
187 | b->split(b+1, b); | - |
188 | lvl[1] = --lvl[0]; | - |
189 | ++b; | - |
190 | ++lvl; | - |
191 | } never executed: end of block | 0 |
192 | } | - |
193 | } never executed: end of block | 0 |
194 | | - |
195 | QRectF QBezier::bounds() const | - |
196 | { | - |
197 | qreal xmin = x1; | - |
198 | qreal xmax = x1; | - |
199 | if (x2 < xmin)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
200 | xmin = x2; never executed: xmin = x2; | 0 |
201 | else if (x2 > xmax)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
202 | xmax = x2; never executed: xmax = x2; | 0 |
203 | if (x3 < xmin)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
204 | xmin = x3; never executed: xmin = x3; | 0 |
205 | else if (x3 > xmax)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
206 | xmax = x3; never executed: xmax = x3; | 0 |
207 | if (x4 < xmin)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
208 | xmin = x4; never executed: xmin = x4; | 0 |
209 | else if (x4 > xmax)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
210 | xmax = x4; never executed: xmax = x4; | 0 |
211 | | - |
212 | qreal ymin = y1; | - |
213 | qreal ymax = y1; | - |
214 | if (y2 < ymin)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
215 | ymin = y2; never executed: ymin = y2; | 0 |
216 | else if (y2 > ymax)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
217 | ymax = y2; never executed: ymax = y2; | 0 |
218 | if (y3 < ymin)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
219 | ymin = y3; never executed: ymin = y3; | 0 |
220 | else if (y3 > ymax)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
221 | ymax = y3; never executed: ymax = y3; | 0 |
222 | if (y4 < ymin)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
223 | ymin = y4; never executed: ymin = y4; | 0 |
224 | else if (y4 > ymax)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
225 | ymax = y4; never executed: ymax = y4; | 0 |
226 | return QRectF(xmin, ymin, xmax-xmin, ymax-ymin); never executed: return QRectF(xmin, ymin, xmax-xmin, ymax-ymin); | 0 |
227 | } | - |
228 | | - |
229 | | - |
230 | enum ShiftResult { | - |
231 | Ok, | - |
232 | Discard, | - |
233 | Split, | - |
234 | Circle | - |
235 | }; | - |
236 | | - |
237 | static 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) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
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)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
248 | return Split; never executed: return Split; | 0 |
249 | | - |
250 | QPointF normalPoint = b1->normalVector(i); | - |
251 | qreal l = qAbs(normalPoint.x()) + qAbs(normalPoint.y()); | - |
252 | if (l != qreal(0.0)) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
253 | d = qAbs( normalPoint.x()*(p1.y() - p2.y()) - normalPoint.y()*(p1.x() - p2.x()) ) / l; | - |
254 | if (d > max_dist_normal)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
255 | return Split; never executed: return Split; | 0 |
256 | } never executed: end of block | 0 |
257 | } never executed: end of block | 0 |
258 | return Ok; never executed: return Ok; | 0 |
259 | } | - |
260 | | - |
261 | static 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);TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
265 | bool p2_p3_equal = (orig->x2 == orig->x3 && orig->y2 == orig->y3);TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
266 | bool p3_p4_equal = (orig->x3 == orig->x4 && orig->y3 == orig->y4);TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
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) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
274 | points[np] = QPointF(orig->x2, orig->y2); | - |
275 | ++np; | - |
276 | } never executed: end of block | 0 |
277 | map[1] = np - 1; | - |
278 | if (!p2_p3_equal) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
279 | points[np] = QPointF(orig->x3, orig->y3); | - |
280 | ++np; | - |
281 | } never executed: end of block | 0 |
282 | map[2] = np - 1; | - |
283 | if (!p3_p4_equal) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
284 | points[np] = QPointF(orig->x4, orig->y4); | - |
285 | ++np; | - |
286 | } never executed: end of block | 0 |
287 | map[3] = np - 1; | - |
288 | if (np == 1)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
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) {TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
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)TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
300 | | - |
301 | | - |
302 | return Circle; never executed: return Circle; | 0 |
303 | } never executed: end of block | 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) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
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)) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
322 | points_shifted[i] = points[i] + offset * prev_normal; | - |
323 | } else { never executed: end of block | 0 |
324 | qreal k = offset / r; | - |
325 | points_shifted[i] = points[i] + k * normal_sum; | - |
326 | } never executed: end of block | 0 |
327 | | - |
328 | prev_normal = next_normal; | - |
329 | } never executed: end of block | 0 |
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); never executed: return good_offset(orig, shifted, offset, threshold); | 0 |
337 | } | - |
338 | | - |
339 | | - |
340 | | - |
341 | | - |
342 | #define KAPPA qreal(0.5522847498) | - |
343 | | - |
344 | | - |
345 | static 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))TRUE | never evaluated | FALSE | never evaluated |
| 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))TRUE | never evaluated | FALSE | never evaluated |
| 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) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
366 | qreal cos_a = normals[i].x()*normals[i+1].x() + normals[i].y()*normals[i+1].y(); | - |
367 | if (cos_a > 1.)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
368 | cos_a = 1.; never executed: cos_a = 1.; | 0 |
369 | if (cos_a < -1.)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
370 | cos_a = -1; never executed: cos_a = -1; | 0 |
371 | angles[i] = qAcos(cos_a) * qreal(M_1_PI); | - |
372 | } never executed: end of block | 0 |
373 | | - |
374 | if (angles[0] + angles[1] > 1.) {TRUE | never evaluated | FALSE | never evaluated |
| 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: end of block | 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) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
389 | qreal kappa = qreal(2.0) * KAPPA * 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: end of block | 0 |
402 | return true; never executed: return true; | 0 |
403 | } | - |
404 | | - |
405 | int QBezier::shifted(QBezier *curveSegments, int maxSegments, qreal offset, float threshold) const | - |
406 | { | - |
407 | Q_ASSERT(curveSegments); | - |
408 | Q_ASSERT(maxSegments > 0); | - |
409 | | - |
410 | if (qFuzzyCompare(x1, x2) && qFuzzyCompare(x1, x3) && qFuzzyCompare(x1, x4) &&TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
411 | qFuzzyCompare(y1, y2) && qFuzzyCompare(y1, y3) && qFuzzyCompare(y1, y4))TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
412 | return 0; never executed: return 0; | 0 |
413 | | - |
414 | --maxSegments; | - |
415 | QBezier beziers[10]; | - |
416 | redo: code before this statement never executed: redo: | 0 |
417 | beziers[0] = *this; | - |
418 | QBezier *b = beziers; | - |
419 | QBezier *o = curveSegments; | - |
420 | | - |
421 | while (b >= beziers) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
422 | int stack_segments = b - beziers + 1; | - |
423 | if ((stack_segments == 10) || (o - curveSegments == maxSegments - stack_segments)) {TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
424 | threshold *= qreal(1.5); | - |
425 | if (threshold > qreal(2.0))TRUE | never evaluated | FALSE | never evaluated |
| 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) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
431 | --b; | - |
432 | } else if (res == Ok) { never executed: end of block TRUE | never evaluated | FALSE | never evaluated |
| 0 |
433 | ++o; | - |
434 | --b; | - |
435 | continue; never executed: continue; | 0 |
436 | } else if (res == Circle && maxSegments - (o - curveSegments) >= 2) {TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
437 | | - |
438 | if (addCircle(b, offset, o))TRUE | never evaluated | FALSE | never evaluated |
| 0 |
439 | o += 2; never executed: o += 2; | 0 |
440 | --b; | - |
441 | } else { never executed: end of block | 0 |
442 | b->split(b+1, b); | - |
443 | ++b; | - |
444 | } never executed: end of block | 0 |
445 | } | - |
446 | | - |
447 | give_up: code before this statement never executed: give_up: | 0 |
448 | while (b >= beziers) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
449 | ShiftResult res = shift(b, o, offset, threshold); | - |
450 | | - |
451 | | - |
452 | if (res == Ok || res == Split)TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
453 | ++o; never executed: ++o; | 0 |
454 | | - |
455 | --b; | - |
456 | } never executed: end of block | 0 |
457 | | - |
458 | Q_ASSERT(o - curveSegments <= maxSegments); | - |
459 | return o - curveSegments; never executed: return o - curveSegments; | 0 |
460 | } | - |
461 | | - |
462 | #ifdef QDEBUG_BEZIER | - |
463 | static QDebug operator<<(QDebug dbg, const QBezier &bz) | - |
464 | { | - |
465 | dbg << '[' << bz.x1<< ", " << bz.y1 << "], " | - |
466 | << '[' << bz.x2 <<", " << bz.y2 << "], " | - |
467 | << '[' << bz.x3 <<", " << bz.y3 << "], " | - |
468 | << '[' << bz.x4 <<", " << bz.y4 << ']'; | - |
469 | return dbg; | - |
470 | } | - |
471 | #endif | - |
472 | | - |
473 | qreal QBezier::length(qreal error) const | - |
474 | { | - |
475 | qreal length = qreal(0.0); | - |
476 | | - |
477 | addIfClose(&length, error); | - |
478 | | - |
479 | return length; never executed: return length; | 0 |
480 | } | - |
481 | | - |
482 | void QBezier::addIfClose(qreal *length, qreal error) const | - |
483 | { | - |
484 | QBezier left, right; | - |
485 | | - |
486 | qreal len = qreal(0.0); | - |
487 | qreal chord; | - |
488 | | - |
489 | len = len + QLineF(QPointF(x1, y1),QPointF(x2, y2)).length(); | - |
490 | len = len + QLineF(QPointF(x2, y2),QPointF(x3, y3)).length(); | - |
491 | len = len + QLineF(QPointF(x3, y3),QPointF(x4, y4)).length(); | - |
492 | | - |
493 | chord = QLineF(QPointF(x1, y1),QPointF(x4, y4)).length(); | - |
494 | | - |
495 | if((len-chord) > error) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
496 | split(&left, &right); | - |
497 | left.addIfClose(length, error); | - |
498 | right.addIfClose(length, error); | - |
499 | return; never executed: return; | 0 |
500 | } | - |
501 | | - |
502 | *length = *length + len; | - |
503 | | - |
504 | return; never executed: return; | 0 |
505 | } | - |
506 | | - |
507 | qreal QBezier::tForY(qreal t0, qreal t1, qreal y) const | - |
508 | { | - |
509 | qreal py0 = pointAt(t0).y(); | - |
510 | qreal py1 = pointAt(t1).y(); | - |
511 | | - |
512 | if (py0 > py1) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
513 | qSwap(py0, py1); | - |
514 | qSwap(t0, t1); | - |
515 | } never executed: end of block | 0 |
516 | | - |
517 | Q_ASSERT(py0 <= py1); | - |
518 | | - |
519 | if (py0 >= y)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
520 | return t0; never executed: return t0; | 0 |
521 | else if (py1 <= y)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
522 | return t1; never executed: return t1; | 0 |
523 | | - |
524 | Q_ASSERT(py0 < y && y < py1); | - |
525 | | - |
526 | qreal lt = t0; | - |
527 | qreal dt; | - |
528 | do { | - |
529 | qreal t = qreal(0.5) * (t0 + t1); | - |
530 | | - |
531 | qreal a, b, c, d; | - |
532 | QBezier::coefficients(t, a, b, c, d); | - |
533 | qreal yt = a * y1 + b * y2 + c * y3 + d * y4; | - |
534 | | - |
535 | if (yt < y) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
536 | t0 = t; | - |
537 | py0 = yt; | - |
538 | } else { never executed: end of block | 0 |
539 | t1 = t; | - |
540 | py1 = yt; | - |
541 | } never executed: end of block | 0 |
542 | dt = lt - t; | - |
543 | lt = t; | - |
544 | } while (qAbs(dt) > qreal(1e-7)); never executed: end of block TRUE | never evaluated | FALSE | never evaluated |
| 0 |
545 | | - |
546 | return t0; never executed: return t0; | 0 |
547 | } | - |
548 | | - |
549 | int QBezier::stationaryYPoints(qreal &t0, qreal &t1) const | - |
550 | { | - |
551 | | - |
552 | | - |
553 | | - |
554 | | - |
555 | const qreal a = -y1 + 3 * y2 - 3 * y3 + y4; | - |
556 | const qreal b = 2 * y1 - 4 * y2 + 2 * y3; | - |
557 | const qreal c = -y1 + y2; | - |
558 | | - |
559 | if (qFuzzyIsNull(a)) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
560 | if (qFuzzyIsNull(b))TRUE | never evaluated | FALSE | never evaluated |
| 0 |
561 | return 0; never executed: return 0; | 0 |
562 | | - |
563 | t0 = -c / b; | - |
564 | return t0 > 0 && t0 < 1; never executed: return t0 > 0 && t0 < 1; | 0 |
565 | } | - |
566 | | - |
567 | qreal reciprocal = b * b - 4 * a * c; | - |
568 | | - |
569 | if (qFuzzyIsNull(reciprocal)) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
570 | t0 = -b / (2 * a); | - |
571 | return t0 > 0 && t0 < 1; never executed: return t0 > 0 && t0 < 1; | 0 |
572 | } else if (reciprocal > 0) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
573 | qreal temp = qSqrt(reciprocal); | - |
574 | | - |
575 | t0 = (-b - temp)/(2*a); | - |
576 | t1 = (-b + temp)/(2*a); | - |
577 | | - |
578 | if (t1 < t0)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
579 | qSwap(t0, t1); never executed: qSwap(t0, t1); | 0 |
580 | | - |
581 | int count = 0; | - |
582 | qreal t[2] = { 0, 1 }; | - |
583 | | - |
584 | if (t0 > 0 && t0 < 1)TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
585 | t[count++] = t0; never executed: t[count++] = t0; | 0 |
586 | if (t1 > 0 && t1 < 1)TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
587 | t[count++] = t1; never executed: t[count++] = t1; | 0 |
588 | | - |
589 | t0 = t[0]; | - |
590 | t1 = t[1]; | - |
591 | | - |
592 | return count; never executed: return count; | 0 |
593 | } | - |
594 | | - |
595 | return 0; never executed: return 0; | 0 |
596 | } | - |
597 | | - |
598 | qreal QBezier::tAtLength(qreal l) const | - |
599 | { | - |
600 | qreal len = length(); | - |
601 | qreal t = qreal(1.0); | - |
602 | const qreal error = qreal(0.01); | - |
603 | if (l > len || qFuzzyCompare(l, len))TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
604 | return t; never executed: return t; | 0 |
605 | | - |
606 | t *= qreal(0.5); | - |
607 | | - |
608 | | - |
609 | qreal lastBigger = qreal(1.0); | - |
610 | while (1) { | - |
611 | | - |
612 | QBezier right = *this; | - |
613 | QBezier left; | - |
614 | right.parameterSplitLeft(t, &left); | - |
615 | qreal lLen = left.length(); | - |
616 | if (qAbs(lLen - l) < error)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
617 | break; never executed: break; | 0 |
618 | | - |
619 | if (lLen < l) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
620 | t += (lastBigger - t) * qreal(0.5); | - |
621 | } else { never executed: end of block | 0 |
622 | lastBigger = t; | - |
623 | t -= t * qreal(0.5); | - |
624 | } never executed: end of block | 0 |
625 | | - |
626 | } | - |
627 | | - |
628 | return t; never executed: return t; | 0 |
629 | } | - |
630 | | - |
631 | QBezier QBezier::bezierOnInterval(qreal t0, qreal t1) const | - |
632 | { | - |
633 | if (t0 == 0 && t1 == 1)TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
634 | return *this; never executed: return *this; | 0 |
635 | | - |
636 | QBezier bezier = *this; | - |
637 | | - |
638 | QBezier result; | - |
639 | bezier.parameterSplitLeft(t0, &result); | - |
640 | qreal trueT = (t1-t0)/(1-t0); | - |
641 | bezier.parameterSplitLeft(trueT, &result); | - |
642 | | - |
643 | return result; never executed: return result; | 0 |
644 | } | - |
645 | | - |
646 | QT_END_NAMESPACE | - |
| | |