qbezier.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/gui/painting/qbezier.cpp
Switch to Source codePreprocessed file
LineSourceCount
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
never executed: return b;
b;
never executed: return b;
0
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
never executed: return polygon;
polygon;
never executed: return polygon;
0
34}-
35-
36QBezier QBezier::mapBy(const QTransform &transform) const-
37{-
38 return
never executed: return QBezier::fromPoints(transform.map(pt1()), transform.map(pt2()), transform.map(pt3()), transform.map(pt4()));
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.))
qFuzzyIsNull(t1 - qreal(1.))Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
48 result = *this;-
49 }
never executed: end of block
else {
0
50 temp = *this;-
51 temp.parameterSplitLeft(t1, &result);-
52 }
never executed: end of block
0
53-
54-
55 if (!qFuzzyIsNull(t0)
!qFuzzyIsNull(t0)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
56 result.parameterSplitLeft(t0 / t1, &temp);
never executed: result.parameterSplitLeft(t0 / t1, &temp);
0
57-
58 return
never executed: return result;
result;
never executed: return result;
0
59}-
60-
61void QBezier::addToPolygon(QPolygonF *polygon, qreal bezier_flattening_threshold) const-
62{-
63 QBezier beziers[10];-
64 int levels[10];-
65 beziers[0] = *this;-
66 levels[0] = 9;-
67 QBezier *b = beziers;-
68 int *lvl = levels;-
69-
70 while (b >= beziers
b >= beziersDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
71-
72 qreal y4y1 = b->y4 - b->y1;-
73 qreal x4x1 = b->x4 - b->x1;-
74 qreal l = qAbs(x4x1) + qAbs(y4y1);-
75 qreal d;-
76 if (l > 1.
l > 1.Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
77 d = qAbs( (x4x1)*(b->y1 - b->y2) - (y4y1)*(b->x1 - b->x2) )-
78 + qAbs( (x4x1)*(b->y1 - b->y3) - (y4y1)*(b->x1 - b->x3) );-
79 }
never executed: end of block
else {
0
80 d = qAbs(b->x1 - b->x2) + qAbs(b->y1 - b->y2) +-
81 qAbs(b->x1 - b->x3) + qAbs(b->y1 - b->y3);-
82 l = 1.;-
83 }
never executed: end of block
0
84 if (d < bezier_flattening_threshold*l
d < bezier_fla...ng_threshold*lDescription
TRUEnever evaluated
FALSEnever evaluated
|| *
*lvl == 0Description
TRUEnever evaluated
FALSEnever evaluated
lvl == 0
*lvl == 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
85-
86 polygon->append(QPointF(b->x4, b->y4));-
87 --b;-
88 --lvl;-
89 }
never executed: end of block
else {
0
90-
91 b->split(b+1, b);-
92 lvl[1] = --lvl[0];-
93 ++b;-
94 ++lvl;-
95 }
never executed: end of block
0
96 }-
97}
never executed: end of block
0
98-
99void QBezier::addToPolygon(QDataBuffer<QPointF> &polygon, qreal bezier_flattening_threshold) const-
100{-
101 QBezier beziers[10];-
102 int levels[10];-
103 beziers[0] = *this;-
104 levels[0] = 9;-
105 QBezier *b = beziers;-
106 int *lvl = levels;-
107-
108 while (b >= beziers
b >= beziersDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
109-
110 qreal y4y1 = b->y4 - b->y1;-
111 qreal x4x1 = b->x4 - b->x1;-
112 qreal l = qAbs(x4x1) + qAbs(y4y1);-
113 qreal d;-
114 if (l > 1.
l > 1.Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
115 d = qAbs( (x4x1)*(b->y1 - b->y2) - (y4y1)*(b->x1 - b->x2) )-
116 + qAbs( (x4x1)*(b->y1 - b->y3) - (y4y1)*(b->x1 - b->x3) );-
117 }
never executed: end of block
else {
0
118 d = qAbs(b->x1 - b->x2) + qAbs(b->y1 - b->y2) +-
119 qAbs(b->x1 - b->x3) + qAbs(b->y1 - b->y3);-
120 l = 1.;-
121 }
never executed: end of block
0
122 if (d < bezier_flattening_threshold*l
d < bezier_fla...ng_threshold*lDescription
TRUEnever evaluated
FALSEnever evaluated
|| *
*lvl == 0Description
TRUEnever evaluated
FALSEnever evaluated
lvl == 0
*lvl == 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
123-
124 polygon.add(QPointF(b->x4, b->y4));-
125 --b;-
126 --lvl;-
127 }
never executed: end of block
else {
0
128-
129 b->split(b+1, b);-
130 lvl[1] = --lvl[0];-
131 ++b;-
132 ++lvl;-
133 }
never executed: end of block
0
134 }-
135}
never executed: end of block
0
136-
137QRectF QBezier::bounds() const-
138{-
139 qreal xmin = x1;-
140 qreal xmax = x1;-
141 if (x2 < xmin
x2 < xminDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
142 xmin = x2;
never executed: xmin = x2;
0
143 else if (x2 > xmax
x2 > xmaxDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
144 xmax = x2;
never executed: xmax = x2;
0
145 if (x3 < xmin
x3 < xminDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
146 xmin = x3;
never executed: xmin = x3;
0
147 else if (x3 > xmax
x3 > xmaxDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
148 xmax = x3;
never executed: xmax = x3;
0
149 if (x4 < xmin
x4 < xminDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
150 xmin = x4;
never executed: xmin = x4;
0
151 else if (x4 > xmax
x4 > xmaxDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
152 xmax = x4;
never executed: xmax = x4;
0
153-
154 qreal ymin = y1;-
155 qreal ymax = y1;-
156 if (y2 < ymin
y2 < yminDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
157 ymin = y2;
never executed: ymin = y2;
0
158 else if (y2 > ymax
y2 > ymaxDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
159 ymax = y2;
never executed: ymax = y2;
0
160 if (y3 < ymin
y3 < yminDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
161 ymin = y3;
never executed: ymin = y3;
0
162 else if (y3 > ymax
y3 > ymaxDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
163 ymax = y3;
never executed: ymax = y3;
0
164 if (y4 < ymin
y4 < yminDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
165 ymin = y4;
never executed: ymin = y4;
0
166 else if (y4 > ymax
y4 > ymaxDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
167 ymax = y4;
never executed: ymax = y4;
0
168 return
never executed: return QRectF(xmin, ymin, xmax-xmin, ymax-ymin);
QRectF(xmin, ymin, xmax-xmin, ymax-ymin);
never executed: return QRectF(xmin, ymin, xmax-xmin, ymax-ymin);
0
169}-
170-
171-
172enum ShiftResult {-
173 Ok,-
174 Discard,-
175 Split,-
176 Circle-
177};-
178-
179static ShiftResult good_offset(const QBezier *b1, const QBezier *b2, qreal offset, qreal threshold)-
180{-
181 const qreal o2 = offset*offset;-
182 const qreal max_dist_line = threshold*offset*offset;-
183 const qreal max_dist_normal = threshold*offset;-
184 const qreal spacing = qreal(0.25);-
185 for (qreal i = spacing; i < qreal(0.99)
i < qreal(0.99)Description
TRUEnever evaluated
FALSEnever evaluated
; i += spacing) {
0
186 QPointF p1 = b1->pointAt(i);-
187 QPointF p2 = b2->pointAt(i);-
188 qreal d = (p1.x() - p2.x())*(p1.x() - p2.x()) + (p1.y() - p2.y())*(p1.y() - p2.y());-
189 if (qAbs(d - o2) > max_dist_line
qAbs(d - o2) > max_dist_lineDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
190 return
never executed: return Split;
Split;
never executed: return Split;
0
191-
192 QPointF normalPoint = b1->normalVector(i);-
193 qreal l = qAbs(normalPoint.x()) + qAbs(normalPoint.y());-
194 if (l != qreal(0.0)
l != qreal(0.0)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
195 d = qAbs( normalPoint.x()*(p1.y() - p2.y()) - normalPoint.y()*(p1.x() - p2.x()) ) / l;-
196 if (d > max_dist_normal
d > max_dist_normalDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
197 return
never executed: return Split;
Split;
never executed: return Split;
0
198 }
never executed: end of block
0
199 }
never executed: end of block
0
200 return
never executed: return Ok;
Ok;
never executed: return Ok;
0
201}-
202-
203static ShiftResult shift(const QBezier *orig, QBezier *shifted, qreal offset, qreal threshold)-
204{-
205 int map[4];-
206 bool p1_p2_equal = (orig->x1 == orig->x2
orig->x1 == orig->x2Description
TRUEnever evaluated
FALSEnever evaluated
&& orig->y1 == orig->y2
orig->y1 == orig->y2Description
TRUEnever evaluated
FALSEnever evaluated
);
0
207 bool p2_p3_equal = (orig->x2 == orig->x3
orig->x2 == orig->x3Description
TRUEnever evaluated
FALSEnever evaluated
&& orig->y2 == orig->y3
orig->y2 == orig->y3Description
TRUEnever evaluated
FALSEnever evaluated
);
0
208 bool p3_p4_equal = (orig->x3 == orig->x4
orig->x3 == orig->x4Description
TRUEnever evaluated
FALSEnever evaluated
&& orig->y3 == orig->y4
orig->y3 == orig->y4Description
TRUEnever evaluated
FALSEnever evaluated
);
0
209-
210 QPointF points[4];-
211 int np = 0;-
212 points[np] = QPointF(orig->x1, orig->y1);-
213 map[0] = 0;-
214 ++np;-
215 if (!p1_p2_equal
!p1_p2_equalDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
216 points[np] = QPointF(orig->x2, orig->y2);-
217 ++np;-
218 }
never executed: end of block
0
219 map[1] = np - 1;-
220 if (!p2_p3_equal
!p2_p3_equalDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
221 points[np] = QPointF(orig->x3, orig->y3);-
222 ++np;-
223 }
never executed: end of block
0
224 map[2] = np - 1;-
225 if (!p3_p4_equal
!p3_p4_equalDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
226 points[np] = QPointF(orig->x4, orig->y4);-
227 ++np;-
228 }
never executed: end of block
0
229 map[3] = np - 1;-
230 if (np == 1
np == 1Description
TRUEnever evaluated
FALSEnever evaluated
)
0
231 return
never executed: return Discard;
Discard;
never executed: return Discard;
0
232-
233 QRectF b = orig->bounds();-
234 if (np == 4
np == 4Description
TRUEnever evaluated
FALSEnever evaluated
&& b.width() < .1*offset
b.width() < .1*offsetDescription
TRUEnever evaluated
FALSEnever evaluated
&& b.height() < .1*offset
b.height() < .1*offsetDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
235 qreal l = (orig->x1 - orig->x2)*(orig->x1 - orig->x2) +-
236 (orig->y1 - orig->y2)*(orig->y1 - orig->y2) *-
237 (orig->x3 - orig->x4)*(orig->x3 - orig->x4) +-
238 (orig->y3 - orig->y4)*(orig->y3 - orig->y4);-
239 qreal dot = (orig->x1 - orig->x2)*(orig->x3 - orig->x4) +-
240 (orig->y1 - orig->y2)*(orig->y3 - orig->y4);-
241 if (dot < 0
dot < 0Description
TRUEnever evaluated
FALSEnever evaluated
&& dot*dot < 0.8*l
dot*dot < 0.8*lDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
242-
243-
244 return
never executed: return Circle;
Circle;
never executed: return Circle;
0
245 }
never executed: end of block
0
246-
247 QPointF points_shifted[4];-
248-
249 QLineF prev = QLineF(QPointF(), points[1] - points[0]);-
250 QPointF prev_normal = prev.normalVector().unitVector().p2();-
251-
252 points_shifted[0] = points[0] + offset * prev_normal;-
253-
254 for (int i = 1; i < np - 1
i < np - 1Description
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
255 QLineF next = QLineF(QPointF(), points[i + 1] - points[i]);-
256 QPointF next_normal = next.normalVector().unitVector().p2();-
257-
258 QPointF normal_sum = prev_normal + next_normal;-
259-
260 qreal r = qreal(1.0) + prev_normal.x() * next_normal.x()-
261 + prev_normal.y() * next_normal.y();-
262-
263 if (qFuzzyIsNull(r)
qFuzzyIsNull(r)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
264 points_shifted[i] = points[i] + offset * prev_normal;-
265 }
never executed: end of block
else {
0
266 qreal k = offset / r;-
267 points_shifted[i] = points[i] + k * normal_sum;-
268 }
never executed: end of block
0
269-
270 prev_normal = next_normal;-
271 }
never executed: end of block
0
272-
273 points_shifted[np - 1] = points[np - 1] + offset * prev_normal;-
274-
275 *shifted = QBezier::fromPoints(points_shifted[map[0]], points_shifted[map[1]],-
276 points_shifted[map[2]], points_shifted[map[3]]);-
277-
278 return
never executed: return good_offset(orig, shifted, offset, threshold);
good_offset(orig, shifted, offset, threshold);
never executed: return good_offset(orig, shifted, offset, threshold);
0
279}-
280-
281-
282-
283-
284-
285-
286-
287static bool addCircle(const QBezier *b, qreal offset, QBezier *o)-
288{-
289 QPointF normals[3];-
290-
291 normals[0] = QPointF(b->y2 - b->y1, b->x1 - b->x2);-
292 qreal dist = qSqrt(normals[0].x()*normals[0].x() + normals[0].y()*normals[0].y());-
293 if (qFuzzyIsNull(dist)
qFuzzyIsNull(dist)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
294 return
never executed: return false;
false;
never executed: return false;
0
295 normals[0] /= dist;-
296 normals[2] = QPointF(b->y4 - b->y3, b->x3 - b->x4);-
297 dist = qSqrt(normals[2].x()*normals[2].x() + normals[2].y()*normals[2].y());-
298 if (qFuzzyIsNull(dist)
qFuzzyIsNull(dist)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
299 return
never executed: return false;
false;
never executed: return false;
0
300 normals[2] /= dist;-
301-
302 normals[1] = QPointF(b->x1 - b->x2 - b->x3 + b->x4, b->y1 - b->y2 - b->y3 + b->y4);-
303 normals[1] /= -1*qSqrt(normals[1].x()*normals[1].x() + normals[1].y()*normals[1].y());-
304-
305 qreal angles[2];-
306 qreal sign = 1.;-
307 for (int i = 0; i < 2
i < 2Description
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
308 qreal cos_a = normals[i].x()*normals[i+1].x() + normals[i].y()*normals[i+1].y();-
309 if (cos_a > 1.
cos_a > 1.Description
TRUEnever evaluated
FALSEnever evaluated
)
0
310 cos_a = 1.;
never executed: cos_a = 1.;
0
311 if (cos_a < -1.
cos_a < -1.Description
TRUEnever evaluated
FALSEnever evaluated
)
0
312 cos_a = -1;
never executed: cos_a = -1;
0
313 angles[i] = qAcos(cos_a) * qreal(0.31830988618379067154);-
314 }
never executed: end of block
0
315-
316 if (angles[0] + angles[1] > 1.
angles[0] + angles[1] > 1.Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
317-
318 normals[1] = -normals[1];-
319 angles[0] = 1. - angles[0];-
320 angles[1] = 1. - angles[1];-
321 sign = -1.;-
322-
323 }
never executed: end of block
0
324-
325 QPointF circle[3];-
326 circle[0] = QPointF(b->x1, b->y1) + normals[0]*offset;-
327 circle[1] = QPointF(qreal(0.5)*(b->x1 + b->x4), qreal(0.5)*(b->y1 + b->y4)) + normals[1]*offset;-
328 circle[2] = QPointF(b->x4, b->y4) + normals[2]*offset;-
329-
330 for (int i = 0; i < 2
i < 2Description
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
331 qreal kappa = qreal(2.0) * qreal(0.5522847498) * sign * offset * angles[i];-
332-
333 o->x1 = circle[i].x();-
334 o->y1 = circle[i].y();-
335 o->x2 = circle[i].x() - normals[i].y()*kappa;-
336 o->y2 = circle[i].y() + normals[i].x()*kappa;-
337 o->x3 = circle[i+1].x() + normals[i+1].y()*kappa;-
338 o->y3 = circle[i+1].y() - normals[i+1].x()*kappa;-
339 o->x4 = circle[i+1].x();-
340 o->y4 = circle[i+1].y();-
341-
342 ++o;-
343 }
never executed: end of block
0
344 return
never executed: return true;
true;
never executed: return true;
0
345}-
346-
347int QBezier::shifted(QBezier *curveSegments, int maxSegments, qreal offset, float threshold) const-
348{-
349 ((!(curveSegments)) ? qt_assert("curveSegments",__FILE__,407) : qt_noop());-
350 ((!(maxSegments > 0)) ? qt_assert("maxSegments > 0",__FILE__,408) : qt_noop());-
351-
352 if (qFuzzyCompare(x1, x2)
qFuzzyCompare(x1, x2)Description
TRUEnever evaluated
FALSEnever evaluated
&& qFuzzyCompare(x1, x3)
qFuzzyCompare(x1, x3)Description
TRUEnever evaluated
FALSEnever evaluated
&& qFuzzyCompare(x1, x4)
qFuzzyCompare(x1, x4)Description
TRUEnever evaluated
FALSEnever evaluated
&&
0
353 qFuzzyCompare(y1, y2)
qFuzzyCompare(y1, y2)Description
TRUEnever evaluated
FALSEnever evaluated
&& qFuzzyCompare(y1, y3)
qFuzzyCompare(y1, y3)Description
TRUEnever evaluated
FALSEnever evaluated
&& qFuzzyCompare(y1, y4)
qFuzzyCompare(y1, y4)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
354 return
never executed: return 0;
0;
never executed: return 0;
0
355-
356 --maxSegments;-
357 QBezier beziers[10];-
358redo:
code before this statement never executed: redo:
0
359 beziers[0] = *this;-
360 QBezier *b = beziers;-
361 QBezier *o = curveSegments;-
362-
363 while (b >= beziers
b >= beziersDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
364 int stack_segments = b - beziers + 1;-
365 if ((
(stack_segments == 10)Description
TRUEnever evaluated
FALSEnever evaluated
stack_segments == 10)
(stack_segments == 10)Description
TRUEnever evaluated
FALSEnever evaluated
|| (
(o - curveSegm...tack_segments)Description
TRUEnever evaluated
FALSEnever evaluated
o - curveSegments == maxSegments - stack_segments)
(o - curveSegm...tack_segments)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
366 threshold *= qreal(1.5);-
367 if (threshold > qreal(2.0)
threshold > qreal(2.0)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
368 goto
never executed: goto give_up;
give_up;
never executed: goto give_up;
0
369 goto
never executed: goto redo;
redo;
never executed: goto redo;
0
370 }-
371 ShiftResult res = shift(b, o, offset, threshold);-
372 if (res == Discard
res == DiscardDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
373 --b;-
374 }
never executed: end of block
else if (res == Ok
res == OkDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
375 ++o;-
376 --b;-
377 continue;
never executed: continue;
0
378 } else if (res == Circle
res == CircleDescription
TRUEnever evaluated
FALSEnever evaluated
&& maxSegments - (o - curveSegments) >= 2
maxSegments - ...Segments) >= 2Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
379-
380 if (addCircle(b, offset, o)
addCircle(b, offset, o)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
381 o += 2;
never executed: o += 2;
0
382 --b;-
383 }
never executed: end of block
else {
0
384 b->split(b+1, b);-
385 ++b;-
386 }
never executed: end of block
0
387 }-
388-
389give_up:
code before this statement never executed: give_up:
0
390 while (b >= beziers
b >= beziersDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
391 ShiftResult res = shift(b, o, offset, threshold);-
392-
393-
394 if (res == Ok
res == OkDescription
TRUEnever evaluated
FALSEnever evaluated
|| res == Split
res == SplitDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
395 ++
never executed: ++o;
o;
never executed: ++o;
0
396-
397 --b;-
398 }
never executed: end of block
0
399-
400 ((!(o - curveSegments <= maxSegments)) ? qt_assert("o - curveSegments <= maxSegments",__FILE__,458) : qt_noop());-
401 return
never executed: return o - curveSegments;
o - curveSegments;
never executed: return o - curveSegments;
0
402}-
403qreal QBezier::length(qreal error) const-
404{-
405 qreal length = qreal(0.0);-
406-
407 addIfClose(&length, error);-
408-
409 return
never executed: return length;
length;
never executed: return length;
0
410}-
411-
412void QBezier::addIfClose(qreal *length, qreal error) const-
413{-
414 QBezier left, right;-
415-
416 qreal len = qreal(0.0);-
417 qreal chord;-
418-
419 len = len + QLineF(QPointF(x1, y1),QPointF(x2, y2)).length();-
420 len = len + QLineF(QPointF(x2, y2),QPointF(x3, y3)).length();-
421 len = len + QLineF(QPointF(x3, y3),QPointF(x4, y4)).length();-
422-
423 chord = QLineF(QPointF(x1, y1),QPointF(x4, y4)).length();-
424-
425 if((
(len-chord) > errorDescription
TRUEnever evaluated
FALSEnever evaluated
len-chord) > error
(len-chord) > errorDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
426 split(&left, &right);-
427 left.addIfClose(length, error);-
428 right.addIfClose(length, error);-
429 return;
never executed: return;
0
430 }-
431-
432 *length = *length + len;-
433-
434 return;
never executed: return;
0
435}-
436-
437qreal QBezier::tForY(qreal t0, qreal t1, qreal y) const-
438{-
439 qreal py0 = pointAt(t0).y();-
440 qreal py1 = pointAt(t1).y();-
441-
442 if (py0 > py1
py0 > py1Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
443 qSwap(py0, py1);-
444 qSwap(t0, t1);-
445 }
never executed: end of block
0
446-
447 ((!(py0 <= py1)) ? qt_assert("py0 <= py1",__FILE__,517) : qt_noop());-
448-
449 if (py0 >= y
py0 >= yDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
450 return
never executed: return t0;
t0;
never executed: return t0;
0
451 else if (py1 <= y
py1 <= yDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
452 return
never executed: return t1;
t1;
never executed: return t1;
0
453-
454 ((!(py0 < y && y < py1)) ? qt_assert("py0 < y && y < py1",__FILE__,524) : qt_noop());-
455-
456 qreal lt = t0;-
457 qreal dt;-
458 do {-
459 qreal t = qreal(0.5) * (t0 + t1);-
460-
461 qreal a, b, c, d;-
462 QBezier::coefficients(t, a, b, c, d);-
463 qreal yt = a * y1 + b * y2 + c * y3 + d * y4;-
464-
465 if (yt < y
yt < yDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
466 t0 = t;-
467 py0 = yt;-
468 }
never executed: end of block
else {
0
469 t1 = t;-
470 py1 = yt;-
471 }
never executed: end of block
0
472 dt = lt - t;-
473 lt = t;-
474 }
never executed: end of block
while (qAbs(dt) > qreal(1e-7)
qAbs(dt) > qreal(1e-7)Description
TRUEnever evaluated
FALSEnever evaluated
);
0
475-
476 return
never executed: return t0;
t0;
never executed: return t0;
0
477}-
478-
479int QBezier::stationaryYPoints(qreal &t0, qreal &t1) const-
480{-
481-
482-
483-
484-
485 const qreal a = -y1 + 3 * y2 - 3 * y3 + y4;-
486 const qreal b = 2 * y1 - 4 * y2 + 2 * y3;-
487 const qreal c = -y1 + y2;-
488-
489 if (qFuzzyIsNull(a)
qFuzzyIsNull(a)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
490 if (qFuzzyIsNull(b)
qFuzzyIsNull(b)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
491 return
never executed: return 0;
0;
never executed: return 0;
0
492-
493 t0 = -c / b;-
494 return
never executed: return t0 > 0 && t0 < 1;
t0 > 0 && t0 < 1;
never executed: return t0 > 0 && t0 < 1;
0
495 }-
496-
497 qreal reciprocal = b * b - 4 * a * c;-
498-
499 if (qFuzzyIsNull(reciprocal)
qFuzzyIsNull(reciprocal)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
500 t0 = -b / (2 * a);-
501 return
never executed: return t0 > 0 && t0 < 1;
t0 > 0 && t0 < 1;
never executed: return t0 > 0 && t0 < 1;
0
502 } else if (reciprocal > 0
reciprocal > 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
503 qreal temp = qSqrt(reciprocal);-
504-
505 t0 = (-b - temp)/(2*a);-
506 t1 = (-b + temp)/(2*a);-
507-
508 if (t1 < t0
t1 < t0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
509 qSwap(t0, t1);
never executed: qSwap(t0, t1);
0
510-
511 int count = 0;-
512 qreal t[2] = { 0, 1 };-
513-
514 if (t0 > 0
t0 > 0Description
TRUEnever evaluated
FALSEnever evaluated
&& t0 < 1
t0 < 1Description
TRUEnever evaluated
FALSEnever evaluated
)
0
515 t[count++] = t0;
never executed: t[count++] = t0;
0
516 if (t1 > 0
t1 > 0Description
TRUEnever evaluated
FALSEnever evaluated
&& t1 < 1
t1 < 1Description
TRUEnever evaluated
FALSEnever evaluated
)
0
517 t[count++] = t1;
never executed: t[count++] = t1;
0
518-
519 t0 = t[0];-
520 t1 = t[1];-
521-
522 return
never executed: return count;
count;
never executed: return count;
0
523 }-
524-
525 return
never executed: return 0;
0;
never executed: return 0;
0
526}-
527-
528qreal QBezier::tAtLength(qreal l) const-
529{-
530 qreal len = length();-
531 qreal t = qreal(1.0);-
532 const qreal error = qreal(0.01);-
533 if (l > len
l > lenDescription
TRUEnever evaluated
FALSEnever evaluated
|| qFuzzyCompare(l, len)
qFuzzyCompare(l, len)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
534 return
never executed: return t;
t;
never executed: return t;
0
535-
536 t *= qreal(0.5);-
537-
538-
539 qreal lastBigger = qreal(1.0);-
540 while (1) {-
541-
542 QBezier right = *this;-
543 QBezier left;-
544 right.parameterSplitLeft(t, &left);-
545 qreal lLen = left.length();-
546 if (qAbs(lLen - l) < error
qAbs(lLen - l) < errorDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
547 break;
never executed: break;
0
548-
549 if (lLen < l
lLen < lDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
550 t += (lastBigger - t) * qreal(0.5);-
551 }
never executed: end of block
else {
0
552 lastBigger = t;-
553 t -= t * qreal(0.5);-
554 }
never executed: end of block
0
555-
556 }-
557-
558 return
never executed: return t;
t;
never executed: return t;
0
559}-
560-
561QBezier QBezier::bezierOnInterval(qreal t0, qreal t1) const-
562{-
563 if (t0 == 0
t0 == 0Description
TRUEnever evaluated
FALSEnever evaluated
&& t1 == 1
t1 == 1Description
TRUEnever evaluated
FALSEnever evaluated
)
0
564 return
never executed: return *this;
*this;
never executed: return *this;
0
565-
566 QBezier bezier = *this;-
567-
568 QBezier result;-
569 bezier.parameterSplitLeft(t0, &result);-
570 qreal trueT = (t1-t0)/(1-t0);-
571 bezier.parameterSplitLeft(trueT, &result);-
572-
573 return
never executed: return result;
result;
never executed: return result;
0
574}-
575-
576-
Switch to Source codePreprocessed file

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