Line | Source Code | Coverage |
---|
1 | /**************************************************************************** | - |
2 | ** | - |
3 | ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). | - |
4 | ** Contact: http://www.qt-project.org/legal | - |
5 | ** | - |
6 | ** This file is part of the QtGui module of the Qt Toolkit. | - |
7 | ** | - |
8 | ** $QT_BEGIN_LICENSE:LGPL$ | - |
9 | ** Commercial License Usage | - |
10 | ** Licensees holding valid commercial Qt licenses may use this file in | - |
11 | ** accordance with the commercial license agreement provided with the | - |
12 | ** Software or, alternatively, in accordance with the terms contained in | - |
13 | ** a written agreement between you and Digia. For licensing terms and | - |
14 | ** conditions see http://qt.digia.com/licensing. For further information | - |
15 | ** use the contact form at http://qt.digia.com/contact-us. | - |
16 | ** | - |
17 | ** GNU Lesser General Public License Usage | - |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - |
19 | ** General Public License version 2.1 as published by the Free Software | - |
20 | ** Foundation and appearing in the file LICENSE.LGPL included in the | - |
21 | ** packaging of this file. Please review the following information to | - |
22 | ** ensure the GNU Lesser General Public License version 2.1 requirements | - |
23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - |
24 | ** | - |
25 | ** In addition, as a special exception, Digia gives you certain additional | - |
26 | ** rights. These rights are described in the Digia Qt LGPL Exception | - |
27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - |
28 | ** | - |
29 | ** GNU General Public License Usage | - |
30 | ** Alternatively, this file may be used under the terms of the GNU | - |
31 | ** General Public License version 3.0 as published by the Free Software | - |
32 | ** Foundation and appearing in the file LICENSE.GPL included in the | - |
33 | ** packaging of this file. Please review the following information to | - |
34 | ** ensure the GNU General Public License version 3.0 requirements will be | - |
35 | ** met: http://www.gnu.org/copyleft/gpl.html. | - |
36 | ** | - |
37 | ** | - |
38 | ** $QT_END_LICENSE$ | - |
39 | ** | - |
40 | ****************************************************************************/ | - |
41 | | - |
42 | #include "qbezier_p.h" | - |
43 | #include <qdebug.h> | - |
44 | #include <qline.h> | - |
45 | #include <qpolygon.h> | - |
46 | #include <qvector.h> | - |
47 | #include <qlist.h> | - |
48 | #include <qmath.h> | - |
49 | | - |
50 | #include <private/qnumeric_p.h> | - |
51 | #include <private/qmath_p.h> | - |
52 | | - |
53 | QT_BEGIN_NAMESPACE | - |
54 | | - |
55 | //#define QDEBUG_BEZIER | - |
56 | | - |
57 | /*! | - |
58 | \internal | - |
59 | */ | - |
60 | QBezier QBezier::fromPoints(const QPointF &p1, const QPointF &p2, | - |
61 | const QPointF &p3, const QPointF &p4) | - |
62 | { | - |
63 | QBezier b; executed (the execution status of this line is deduced): QBezier b; | - |
64 | b.x1 = p1.x(); executed (the execution status of this line is deduced): b.x1 = p1.x(); | - |
65 | b.y1 = p1.y(); executed (the execution status of this line is deduced): b.y1 = p1.y(); | - |
66 | b.x2 = p2.x(); executed (the execution status of this line is deduced): b.x2 = p2.x(); | - |
67 | b.y2 = p2.y(); executed (the execution status of this line is deduced): b.y2 = p2.y(); | - |
68 | b.x3 = p3.x(); executed (the execution status of this line is deduced): b.x3 = p3.x(); | - |
69 | b.y3 = p3.y(); executed (the execution status of this line is deduced): b.y3 = p3.y(); | - |
70 | b.x4 = p4.x(); executed (the execution status of this line is deduced): b.x4 = p4.x(); | - |
71 | b.y4 = p4.y(); executed (the execution status of this line is deduced): b.y4 = p4.y(); | - |
72 | return b; executed: return b; Execution Count:36081 | 36081 |
73 | } | - |
74 | | - |
75 | /*! | - |
76 | \internal | - |
77 | */ | - |
78 | QPolygonF QBezier::toPolygon(qreal bezier_flattening_threshold) const | - |
79 | { | - |
80 | // flattening is done by splitting the bezier until we can replace the segment by a straight | - |
81 | // line. We split further until the control points are close enough to the line connecting the | - |
82 | // boundary points. | - |
83 | // | - |
84 | // the Distance of a point p from a line given by the points (a,b) is given by: | - |
85 | // | - |
86 | // d = abs( (bx - ax)(ay - py) - (by - ay)(ax - px) ) / line_length | - |
87 | // | - |
88 | // We can stop splitting if both control points are close enough to the line. | - |
89 | // To make the algorithm faster we use the manhattan length of the line. | - |
90 | | - |
91 | QPolygonF polygon; never executed (the execution status of this line is deduced): QPolygonF polygon; | - |
92 | polygon.append(QPointF(x1, y1)); never executed (the execution status of this line is deduced): polygon.append(QPointF(x1, y1)); | - |
93 | addToPolygon(&polygon, bezier_flattening_threshold); never executed (the execution status of this line is deduced): addToPolygon(&polygon, bezier_flattening_threshold); | - |
94 | return polygon; never executed: return polygon; | 0 |
95 | } | - |
96 | | - |
97 | QBezier QBezier::mapBy(const QTransform &transform) const | - |
98 | { | - |
99 | 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 |
100 | } | - |
101 | | - |
102 | QBezier QBezier::getSubRange(qreal t0, qreal t1) const | - |
103 | { | - |
104 | QBezier result; never executed (the execution status of this line is deduced): QBezier result; | - |
105 | QBezier temp; never executed (the execution status of this line is deduced): QBezier temp; | - |
106 | | - |
107 | // cut at t1 | - |
108 | if (qFuzzyIsNull(t1 - qreal(1.))) { never evaluated: qFuzzyIsNull(t1 - qreal(1.)) | 0 |
109 | result = *this; never executed (the execution status of this line is deduced): result = *this; | - |
110 | } else { | 0 |
111 | temp = *this; never executed (the execution status of this line is deduced): temp = *this; | - |
112 | temp.parameterSplitLeft(t1, &result); never executed (the execution status of this line is deduced): temp.parameterSplitLeft(t1, &result); | - |
113 | } | 0 |
114 | | - |
115 | // cut at t0 | - |
116 | if (!qFuzzyIsNull(t0)) never evaluated: !qFuzzyIsNull(t0) | 0 |
117 | result.parameterSplitLeft(t0 / t1, &temp); never executed: result.parameterSplitLeft(t0 / t1, &temp); | 0 |
118 | | - |
119 | return result; never executed: return result; | 0 |
120 | } | - |
121 | | - |
122 | static inline int quadraticRoots(qreal a, qreal b, qreal c, | - |
123 | qreal *x1, qreal *x2) | - |
124 | { | - |
125 | if (qFuzzyIsNull(a)) { never evaluated: qFuzzyIsNull(a) | 0 |
126 | if (qFuzzyIsNull(b)) never evaluated: qFuzzyIsNull(b) | 0 |
127 | return 0; never executed: return 0; | 0 |
128 | *x1 = *x2 = (-c / b); never executed (the execution status of this line is deduced): *x1 = *x2 = (-c / b); | - |
129 | return 1; never executed: return 1; | 0 |
130 | } else { | - |
131 | const qreal det = b * b - 4 * a * c; never executed (the execution status of this line is deduced): const qreal det = b * b - 4 * a * c; | - |
132 | if (qFuzzyIsNull(det)) { never evaluated: qFuzzyIsNull(det) | 0 |
133 | *x1 = *x2 = -b / (2 * a); never executed (the execution status of this line is deduced): *x1 = *x2 = -b / (2 * a); | - |
134 | return 1; never executed: return 1; | 0 |
135 | } | - |
136 | if (det > 0) { | 0 |
137 | if (qFuzzyIsNull(b)) { never evaluated: qFuzzyIsNull(b) | 0 |
138 | *x2 = qSqrt(-c / a); never executed (the execution status of this line is deduced): *x2 = qSqrt(-c / a); | - |
139 | *x1 = -(*x2); never executed (the execution status of this line is deduced): *x1 = -(*x2); | - |
140 | return 2; never executed: return 2; | 0 |
141 | } | - |
142 | const qreal stableA = b / (2 * a); never executed (the execution status of this line is deduced): const qreal stableA = b / (2 * a); | - |
143 | const qreal stableB = c / (a * stableA * stableA); never executed (the execution status of this line is deduced): const qreal stableB = c / (a * stableA * stableA); | - |
144 | const qreal stableC = -1 - qSqrt(1 - stableB); never executed (the execution status of this line is deduced): const qreal stableC = -1 - qSqrt(1 - stableB); | - |
145 | *x2 = stableA * stableC; never executed (the execution status of this line is deduced): *x2 = stableA * stableC; | - |
146 | *x1 = (stableA * stableB) / stableC; never executed (the execution status of this line is deduced): *x1 = (stableA * stableB) / stableC; | - |
147 | return 2; never executed: return 2; | 0 |
148 | } else | - |
149 | return 0; never executed: return 0; | 0 |
150 | } | - |
151 | } | - |
152 | | - |
153 | static inline bool findInflections(qreal a, qreal b, qreal c, | - |
154 | qreal *t1 , qreal *t2, qreal *tCups) | - |
155 | { | - |
156 | qreal r1 = 0, r2 = 0; never executed (the execution status of this line is deduced): qreal r1 = 0, r2 = 0; | - |
157 | | - |
158 | short rootsCount = quadraticRoots(a, b, c, &r1, &r2); never executed (the execution status of this line is deduced): short rootsCount = quadraticRoots(a, b, c, &r1, &r2); | - |
159 | | - |
160 | if (rootsCount >= 1) { never evaluated: rootsCount >= 1 | 0 |
161 | if (r1 < r2) { | 0 |
162 | *t1 = r1; never executed (the execution status of this line is deduced): *t1 = r1; | - |
163 | *t2 = r2; never executed (the execution status of this line is deduced): *t2 = r2; | - |
164 | } else { | 0 |
165 | *t1 = r2; never executed (the execution status of this line is deduced): *t1 = r2; | - |
166 | *t2 = r1; never executed (the execution status of this line is deduced): *t2 = r1; | - |
167 | } | 0 |
168 | if (!qFuzzyIsNull(a)) never evaluated: !qFuzzyIsNull(a) | 0 |
169 | *tCups = qreal(0.5) * (-b / a); never executed: *tCups = qreal(0.5) * (-b / a); | 0 |
170 | else | - |
171 | *tCups = 2; never executed: *tCups = 2; | 0 |
172 | | - |
173 | return true; never executed: return true; | 0 |
174 | } | - |
175 | | - |
176 | return false; never executed: return false; | 0 |
177 | } | - |
178 | | - |
179 | | - |
180 | void QBezier::addToPolygon(QPolygonF *polygon, qreal bezier_flattening_threshold) const | - |
181 | { | - |
182 | QBezier beziers[10]; executed (the execution status of this line is deduced): QBezier beziers[10]; | - |
183 | int levels[10]; executed (the execution status of this line is deduced): int levels[10]; | - |
184 | beziers[0] = *this; executed (the execution status of this line is deduced): beziers[0] = *this; | - |
185 | levels[0] = 9; executed (the execution status of this line is deduced): levels[0] = 9; | - |
186 | QBezier *b = beziers; executed (the execution status of this line is deduced): QBezier *b = beziers; | - |
187 | int *lvl = levels; executed (the execution status of this line is deduced): int *lvl = levels; | - |
188 | | - |
189 | while (b >= beziers) { evaluated: b >= beziers yes Evaluation Count:2031 | yes Evaluation Count:105 |
| 105-2031 |
190 | // check if we can pop the top bezier curve from the stack | - |
191 | qreal y4y1 = b->y4 - b->y1; executed (the execution status of this line is deduced): qreal y4y1 = b->y4 - b->y1; | - |
192 | qreal x4x1 = b->x4 - b->x1; executed (the execution status of this line is deduced): qreal x4x1 = b->x4 - b->x1; | - |
193 | qreal l = qAbs(x4x1) + qAbs(y4y1); executed (the execution status of this line is deduced): qreal l = qAbs(x4x1) + qAbs(y4y1); | - |
194 | qreal d; executed (the execution status of this line is deduced): qreal d; | - |
195 | if (l > 1.) { partially evaluated: l > 1. yes Evaluation Count:2031 | no Evaluation Count:0 |
| 0-2031 |
196 | d = qAbs( (x4x1)*(b->y1 - b->y2) - (y4y1)*(b->x1 - b->x2) ) executed (the execution status of this line is deduced): d = qAbs( (x4x1)*(b->y1 - b->y2) - (y4y1)*(b->x1 - b->x2) ) | - |
197 | + qAbs( (x4x1)*(b->y1 - b->y3) - (y4y1)*(b->x1 - b->x3) ); executed (the execution status of this line is deduced): + qAbs( (x4x1)*(b->y1 - b->y3) - (y4y1)*(b->x1 - b->x3) ); | - |
198 | } else { executed: } Execution Count:2031 | 2031 |
199 | d = qAbs(b->x1 - b->x2) + qAbs(b->y1 - b->y2) + never executed (the execution status of this line is deduced): d = qAbs(b->x1 - b->x2) + qAbs(b->y1 - b->y2) + | - |
200 | qAbs(b->x1 - b->x3) + qAbs(b->y1 - b->y3); never executed (the execution status of this line is deduced): qAbs(b->x1 - b->x3) + qAbs(b->y1 - b->y3); | - |
201 | l = 1.; never executed (the execution status of this line is deduced): l = 1.; | - |
202 | } | 0 |
203 | if (d < bezier_flattening_threshold*l || *lvl == 0) { evaluated: d < bezier_flattening_threshold*l yes Evaluation Count:1068 | yes Evaluation Count:963 |
partially evaluated: *lvl == 0 no Evaluation Count:0 | yes Evaluation Count:963 |
| 0-1068 |
204 | // good enough, we pop it off and add the endpoint | - |
205 | polygon->append(QPointF(b->x4, b->y4)); executed (the execution status of this line is deduced): polygon->append(QPointF(b->x4, b->y4)); | - |
206 | --b; executed (the execution status of this line is deduced): --b; | - |
207 | --lvl; executed (the execution status of this line is deduced): --lvl; | - |
208 | } else { executed: } Execution Count:1068 | 1068 |
209 | // split, second half of the polygon goes lower into the stack | - |
210 | b->split(b+1, b); executed (the execution status of this line is deduced): b->split(b+1, b); | - |
211 | lvl[1] = --lvl[0]; executed (the execution status of this line is deduced): lvl[1] = --lvl[0]; | - |
212 | ++b; executed (the execution status of this line is deduced): ++b; | - |
213 | ++lvl; executed (the execution status of this line is deduced): ++lvl; | - |
214 | } executed: } Execution Count:963 | 963 |
215 | } | - |
216 | } executed: } Execution Count:105 | 105 |
217 | | - |
218 | void QBezier::addToPolygon(QDataBuffer<QPointF> &polygon, qreal bezier_flattening_threshold) const | - |
219 | { | - |
220 | QBezier beziers[10]; executed (the execution status of this line is deduced): QBezier beziers[10]; | - |
221 | int levels[10]; executed (the execution status of this line is deduced): int levels[10]; | - |
222 | beziers[0] = *this; executed (the execution status of this line is deduced): beziers[0] = *this; | - |
223 | levels[0] = 9; executed (the execution status of this line is deduced): levels[0] = 9; | - |
224 | QBezier *b = beziers; executed (the execution status of this line is deduced): QBezier *b = beziers; | - |
225 | int *lvl = levels; executed (the execution status of this line is deduced): int *lvl = levels; | - |
226 | | - |
227 | while (b >= beziers) { evaluated: b >= beziers yes Evaluation Count:453128 | yes Evaluation Count:11216 |
| 11216-453128 |
228 | // check if we can pop the top bezier curve from the stack | - |
229 | qreal y4y1 = b->y4 - b->y1; executed (the execution status of this line is deduced): qreal y4y1 = b->y4 - b->y1; | - |
230 | qreal x4x1 = b->x4 - b->x1; executed (the execution status of this line is deduced): qreal x4x1 = b->x4 - b->x1; | - |
231 | qreal l = qAbs(x4x1) + qAbs(y4y1); executed (the execution status of this line is deduced): qreal l = qAbs(x4x1) + qAbs(y4y1); | - |
232 | qreal d; executed (the execution status of this line is deduced): qreal d; | - |
233 | if (l > 1.) { evaluated: l > 1. yes Evaluation Count:276642 | yes Evaluation Count:176486 |
| 176486-276642 |
234 | d = qAbs( (x4x1)*(b->y1 - b->y2) - (y4y1)*(b->x1 - b->x2) ) executed (the execution status of this line is deduced): d = qAbs( (x4x1)*(b->y1 - b->y2) - (y4y1)*(b->x1 - b->x2) ) | - |
235 | + qAbs( (x4x1)*(b->y1 - b->y3) - (y4y1)*(b->x1 - b->x3) ); executed (the execution status of this line is deduced): + qAbs( (x4x1)*(b->y1 - b->y3) - (y4y1)*(b->x1 - b->x3) ); | - |
236 | } else { executed: } Execution Count:276642 | 276642 |
237 | d = qAbs(b->x1 - b->x2) + qAbs(b->y1 - b->y2) + executed (the execution status of this line is deduced): d = qAbs(b->x1 - b->x2) + qAbs(b->y1 - b->y2) + | - |
238 | qAbs(b->x1 - b->x3) + qAbs(b->y1 - b->y3); executed (the execution status of this line is deduced): qAbs(b->x1 - b->x3) + qAbs(b->y1 - b->y3); | - |
239 | l = 1.; executed (the execution status of this line is deduced): l = 1.; | - |
240 | } executed: } Execution Count:176486 | 176486 |
241 | if (d < bezier_flattening_threshold*l || *lvl == 0) { evaluated: d < bezier_flattening_threshold*l yes Evaluation Count:229590 | yes Evaluation Count:223538 |
evaluated: *lvl == 0 yes Evaluation Count:2582 | yes Evaluation Count:220956 |
| 2582-229590 |
242 | // good enough, we pop it off and add the endpoint | - |
243 | polygon.add(QPointF(b->x4, b->y4)); executed (the execution status of this line is deduced): polygon.add(QPointF(b->x4, b->y4)); | - |
244 | --b; executed (the execution status of this line is deduced): --b; | - |
245 | --lvl; executed (the execution status of this line is deduced): --lvl; | - |
246 | } else { executed: } Execution Count:232172 | 232172 |
247 | // split, second half of the polygon goes lower into the stack | - |
248 | b->split(b+1, b); executed (the execution status of this line is deduced): b->split(b+1, b); | - |
249 | lvl[1] = --lvl[0]; executed (the execution status of this line is deduced): lvl[1] = --lvl[0]; | - |
250 | ++b; executed (the execution status of this line is deduced): ++b; | - |
251 | ++lvl; executed (the execution status of this line is deduced): ++lvl; | - |
252 | } executed: } Execution Count:220956 | 220956 |
253 | } | - |
254 | } executed: } Execution Count:11216 | 11216 |
255 | | - |
256 | QRectF QBezier::bounds() const | - |
257 | { | - |
258 | qreal xmin = x1; executed (the execution status of this line is deduced): qreal xmin = x1; | - |
259 | qreal xmax = x1; executed (the execution status of this line is deduced): qreal xmax = x1; | - |
260 | if (x2 < xmin) evaluated: x2 < xmin yes Evaluation Count:6268 | yes Evaluation Count:10802 |
| 6268-10802 |
261 | xmin = x2; executed: xmin = x2; Execution Count:6268 | 6268 |
262 | else if (x2 > xmax) evaluated: x2 > xmax yes Evaluation Count:5850 | yes Evaluation Count:4952 |
| 4952-5850 |
263 | xmax = x2; executed: xmax = x2; Execution Count:5850 | 5850 |
264 | if (x3 < xmin) evaluated: x3 < xmin yes Evaluation Count:8906 | yes Evaluation Count:8164 |
| 8164-8906 |
265 | xmin = x3; executed: xmin = x3; Execution Count:8906 | 8906 |
266 | else if (x3 > xmax) evaluated: x3 > xmax yes Evaluation Count:8146 | yes Evaluation Count:18 |
| 18-8146 |
267 | xmax = x3; executed: xmax = x3; Execution Count:8146 | 8146 |
268 | if (x4 < xmin) evaluated: x4 < xmin yes Evaluation Count:6283 | yes Evaluation Count:10787 |
| 6283-10787 |
269 | xmin = x4; executed: xmin = x4; Execution Count:6283 | 6283 |
270 | else if (x4 > xmax) evaluated: x4 > xmax yes Evaluation Count:5787 | yes Evaluation Count:5000 |
| 5000-5787 |
271 | xmax = x4; executed: xmax = x4; Execution Count:5787 | 5787 |
272 | | - |
273 | qreal ymin = y1; executed (the execution status of this line is deduced): qreal ymin = y1; | - |
274 | qreal ymax = y1; executed (the execution status of this line is deduced): qreal ymax = y1; | - |
275 | if (y2 < ymin) evaluated: y2 < ymin yes Evaluation Count:6199 | yes Evaluation Count:10871 |
| 6199-10871 |
276 | ymin = y2; executed: ymin = y2; Execution Count:6199 | 6199 |
277 | else if (y2 > ymax) evaluated: y2 > ymax yes Evaluation Count:6304 | yes Evaluation Count:4567 |
| 4567-6304 |
278 | ymax = y2; executed: ymax = y2; Execution Count:6304 | 6304 |
279 | if (y3 < ymin) evaluated: y3 < ymin yes Evaluation Count:8457 | yes Evaluation Count:8613 |
| 8457-8613 |
280 | ymin = y3; executed: ymin = y3; Execution Count:8457 | 8457 |
281 | else if (y3 > ymax) evaluated: y3 > ymax yes Evaluation Count:8600 | yes Evaluation Count:13 |
| 13-8600 |
282 | ymax = y3; executed: ymax = y3; Execution Count:8600 | 8600 |
283 | if (y4 < ymin) evaluated: y4 < ymin yes Evaluation Count:6152 | yes Evaluation Count:10918 |
| 6152-10918 |
284 | ymin = y4; executed: ymin = y4; Execution Count:6152 | 6152 |
285 | else if (y4 > ymax) evaluated: y4 > ymax yes Evaluation Count:6331 | yes Evaluation Count:4587 |
| 4587-6331 |
286 | ymax = y4; executed: ymax = y4; Execution Count:6331 | 6331 |
287 | return QRectF(xmin, ymin, xmax-xmin, ymax-ymin); executed: return QRectF(xmin, ymin, xmax-xmin, ymax-ymin); Execution Count:17070 | 17070 |
288 | } | - |
289 | | - |
290 | | - |
291 | enum ShiftResult { | - |
292 | Ok, | - |
293 | Discard, | - |
294 | Split, | - |
295 | Circle | - |
296 | }; | - |
297 | | - |
298 | static ShiftResult good_offset(const QBezier *b1, const QBezier *b2, qreal offset, qreal threshold) | - |
299 | { | - |
300 | const qreal o2 = offset*offset; executed (the execution status of this line is deduced): const qreal o2 = offset*offset; | - |
301 | const qreal max_dist_line = threshold*offset*offset; executed (the execution status of this line is deduced): const qreal max_dist_line = threshold*offset*offset; | - |
302 | const qreal max_dist_normal = threshold*offset; executed (the execution status of this line is deduced): const qreal max_dist_normal = threshold*offset; | - |
303 | const qreal spacing = qreal(0.25); executed (the execution status of this line is deduced): const qreal spacing = qreal(0.25); | - |
304 | for (qreal i = spacing; i < qreal(0.99); i += spacing) { evaluated: i < qreal(0.99) yes Evaluation Count:22820 | yes Evaluation Count:7504 |
| 7504-22820 |
305 | QPointF p1 = b1->pointAt(i); executed (the execution status of this line is deduced): QPointF p1 = b1->pointAt(i); | - |
306 | QPointF p2 = b2->pointAt(i); executed (the execution status of this line is deduced): QPointF p2 = b2->pointAt(i); | - |
307 | qreal d = (p1.x() - p2.x())*(p1.x() - p2.x()) + (p1.y() - p2.y())*(p1.y() - p2.y()); executed (the execution status of this line is deduced): qreal d = (p1.x() - p2.x())*(p1.x() - p2.x()) + (p1.y() - p2.y())*(p1.y() - p2.y()); | - |
308 | if (qAbs(d - o2) > max_dist_line) evaluated: qAbs(d - o2) > max_dist_line yes Evaluation Count:8 | yes Evaluation Count:22812 |
| 8-22812 |
309 | return Split; executed: return Split; Execution Count:8 | 8 |
310 | | - |
311 | QPointF normalPoint = b1->normalVector(i); executed (the execution status of this line is deduced): QPointF normalPoint = b1->normalVector(i); | - |
312 | qreal l = qAbs(normalPoint.x()) + qAbs(normalPoint.y()); executed (the execution status of this line is deduced): qreal l = qAbs(normalPoint.x()) + qAbs(normalPoint.y()); | - |
313 | if (l != qreal(0.0)) { partially evaluated: l != qreal(0.0) yes Evaluation Count:22812 | no Evaluation Count:0 |
| 0-22812 |
314 | d = qAbs( normalPoint.x()*(p1.y() - p2.y()) - normalPoint.y()*(p1.x() - p2.x()) ) / l; executed (the execution status of this line is deduced): d = qAbs( normalPoint.x()*(p1.y() - p2.y()) - normalPoint.y()*(p1.x() - p2.x()) ) / l; | - |
315 | if (d > max_dist_normal) evaluated: d > max_dist_normal yes Evaluation Count:200 | yes Evaluation Count:22612 |
| 200-22612 |
316 | return Split; executed: return Split; Execution Count:200 | 200 |
317 | } executed: } Execution Count:22612 | 22612 |
318 | } executed: } Execution Count:22612 | 22612 |
319 | return Ok; executed: return Ok; Execution Count:7504 | 7504 |
320 | } | - |
321 | | - |
322 | static ShiftResult shift(const QBezier *orig, QBezier *shifted, qreal offset, qreal threshold) | - |
323 | { | - |
324 | int map[4]; executed (the execution status of this line is deduced): int map[4]; | - |
325 | bool p1_p2_equal = (orig->x1 == orig->x2 && orig->y1 == orig->y2); evaluated: orig->x1 == orig->x2 yes Evaluation Count:3744 | yes Evaluation Count:3968 |
partially evaluated: orig->y1 == orig->y2 no Evaluation Count:0 | yes Evaluation Count:3744 |
| 0-3968 |
326 | bool p2_p3_equal = (orig->x2 == orig->x3 && orig->y2 == orig->y3); evaluated: orig->x2 == orig->x3 yes Evaluation Count:8 | yes Evaluation Count:7704 |
partially evaluated: orig->y2 == orig->y3 no Evaluation Count:0 | yes Evaluation Count:8 |
| 0-7704 |
327 | bool p3_p4_equal = (orig->x3 == orig->x4 && orig->y3 == orig->y4); evaluated: orig->x3 == orig->x4 yes Evaluation Count:3744 | yes Evaluation Count:3968 |
partially evaluated: orig->y3 == orig->y4 no Evaluation Count:0 | yes Evaluation Count:3744 |
| 0-3968 |
328 | | - |
329 | QPointF points[4]; executed (the execution status of this line is deduced): QPointF points[4]; | - |
330 | int np = 0; executed (the execution status of this line is deduced): int np = 0; | - |
331 | points[np] = QPointF(orig->x1, orig->y1); executed (the execution status of this line is deduced): points[np] = QPointF(orig->x1, orig->y1); | - |
332 | map[0] = 0; executed (the execution status of this line is deduced): map[0] = 0; | - |
333 | ++np; executed (the execution status of this line is deduced): ++np; | - |
334 | if (!p1_p2_equal) { partially evaluated: !p1_p2_equal yes Evaluation Count:7712 | no Evaluation Count:0 |
| 0-7712 |
335 | points[np] = QPointF(orig->x2, orig->y2); executed (the execution status of this line is deduced): points[np] = QPointF(orig->x2, orig->y2); | - |
336 | ++np; executed (the execution status of this line is deduced): ++np; | - |
337 | } executed: } Execution Count:7712 | 7712 |
338 | map[1] = np - 1; executed (the execution status of this line is deduced): map[1] = np - 1; | - |
339 | if (!p2_p3_equal) { partially evaluated: !p2_p3_equal yes Evaluation Count:7712 | no Evaluation Count:0 |
| 0-7712 |
340 | points[np] = QPointF(orig->x3, orig->y3); executed (the execution status of this line is deduced): points[np] = QPointF(orig->x3, orig->y3); | - |
341 | ++np; executed (the execution status of this line is deduced): ++np; | - |
342 | } executed: } Execution Count:7712 | 7712 |
343 | map[2] = np - 1; executed (the execution status of this line is deduced): map[2] = np - 1; | - |
344 | if (!p3_p4_equal) { partially evaluated: !p3_p4_equal yes Evaluation Count:7712 | no Evaluation Count:0 |
| 0-7712 |
345 | points[np] = QPointF(orig->x4, orig->y4); executed (the execution status of this line is deduced): points[np] = QPointF(orig->x4, orig->y4); | - |
346 | ++np; executed (the execution status of this line is deduced): ++np; | - |
347 | } executed: } Execution Count:7712 | 7712 |
348 | map[3] = np - 1; executed (the execution status of this line is deduced): map[3] = np - 1; | - |
349 | if (np == 1) partially evaluated: np == 1 no Evaluation Count:0 | yes Evaluation Count:7712 |
| 0-7712 |
350 | return Discard; never executed: return Discard; | 0 |
351 | | - |
352 | QRectF b = orig->bounds(); executed (the execution status of this line is deduced): QRectF b = orig->bounds(); | - |
353 | if (np == 4 && b.width() < .1*offset && b.height() < .1*offset) { partially evaluated: np == 4 yes Evaluation Count:7712 | no Evaluation Count:0 |
partially evaluated: b.width() < .1*offset no Evaluation Count:0 | yes Evaluation Count:7712 |
never evaluated: b.height() < .1*offset | 0-7712 |
354 | qreal l = (orig->x1 - orig->x2)*(orig->x1 - orig->x2) + never executed (the execution status of this line is deduced): qreal l = (orig->x1 - orig->x2)*(orig->x1 - orig->x2) + | - |
355 | (orig->y1 - orig->y2)*(orig->y1 - orig->y2) * never executed (the execution status of this line is deduced): (orig->y1 - orig->y2)*(orig->y1 - orig->y2) * | - |
356 | (orig->x3 - orig->x4)*(orig->x3 - orig->x4) + never executed (the execution status of this line is deduced): (orig->x3 - orig->x4)*(orig->x3 - orig->x4) + | - |
357 | (orig->y3 - orig->y4)*(orig->y3 - orig->y4); never executed (the execution status of this line is deduced): (orig->y3 - orig->y4)*(orig->y3 - orig->y4); | - |
358 | qreal dot = (orig->x1 - orig->x2)*(orig->x3 - orig->x4) + never executed (the execution status of this line is deduced): qreal dot = (orig->x1 - orig->x2)*(orig->x3 - orig->x4) + | - |
359 | (orig->y1 - orig->y2)*(orig->y3 - orig->y4); never executed (the execution status of this line is deduced): (orig->y1 - orig->y2)*(orig->y3 - orig->y4); | - |
360 | if (dot < 0 && dot*dot < 0.8*l) never evaluated: dot < 0 never evaluated: dot*dot < 0.8*l | 0 |
361 | // the points are close and reverse dirction. Approximate the whole | - |
362 | // thing by a semi circle | - |
363 | return Circle; never executed: return Circle; | 0 |
364 | } | 0 |
365 | | - |
366 | QPointF points_shifted[4]; executed (the execution status of this line is deduced): QPointF points_shifted[4]; | - |
367 | | - |
368 | QLineF prev = QLineF(QPointF(), points[1] - points[0]); executed (the execution status of this line is deduced): QLineF prev = QLineF(QPointF(), points[1] - points[0]); | - |
369 | QPointF prev_normal = prev.normalVector().unitVector().p2(); executed (the execution status of this line is deduced): QPointF prev_normal = prev.normalVector().unitVector().p2(); | - |
370 | | - |
371 | points_shifted[0] = points[0] + offset * prev_normal; executed (the execution status of this line is deduced): points_shifted[0] = points[0] + offset * prev_normal; | - |
372 | | - |
373 | for (int i = 1; i < np - 1; ++i) { evaluated: i < np - 1 yes Evaluation Count:15424 | yes Evaluation Count:7712 |
| 7712-15424 |
374 | QLineF next = QLineF(QPointF(), points[i + 1] - points[i]); executed (the execution status of this line is deduced): QLineF next = QLineF(QPointF(), points[i + 1] - points[i]); | - |
375 | QPointF next_normal = next.normalVector().unitVector().p2(); executed (the execution status of this line is deduced): QPointF next_normal = next.normalVector().unitVector().p2(); | - |
376 | | - |
377 | QPointF normal_sum = prev_normal + next_normal; executed (the execution status of this line is deduced): QPointF normal_sum = prev_normal + next_normal; | - |
378 | | - |
379 | qreal r = qreal(1.0) + prev_normal.x() * next_normal.x() executed (the execution status of this line is deduced): qreal r = qreal(1.0) + prev_normal.x() * next_normal.x() | - |
380 | + prev_normal.y() * next_normal.y(); executed (the execution status of this line is deduced): + prev_normal.y() * next_normal.y(); | - |
381 | | - |
382 | if (qFuzzyIsNull(r)) { partially evaluated: qFuzzyIsNull(r) no Evaluation Count:0 | yes Evaluation Count:15424 |
| 0-15424 |
383 | points_shifted[i] = points[i] + offset * prev_normal; never executed (the execution status of this line is deduced): points_shifted[i] = points[i] + offset * prev_normal; | - |
384 | } else { | 0 |
385 | qreal k = offset / r; executed (the execution status of this line is deduced): qreal k = offset / r; | - |
386 | points_shifted[i] = points[i] + k * normal_sum; executed (the execution status of this line is deduced): points_shifted[i] = points[i] + k * normal_sum; | - |
387 | } executed: } Execution Count:15424 | 15424 |
388 | | - |
389 | prev_normal = next_normal; executed (the execution status of this line is deduced): prev_normal = next_normal; | - |
390 | } executed: } Execution Count:15424 | 15424 |
391 | | - |
392 | points_shifted[np - 1] = points[np - 1] + offset * prev_normal; executed (the execution status of this line is deduced): points_shifted[np - 1] = points[np - 1] + offset * prev_normal; | - |
393 | | - |
394 | *shifted = QBezier::fromPoints(points_shifted[map[0]], points_shifted[map[1]], executed (the execution status of this line is deduced): *shifted = QBezier::fromPoints(points_shifted[map[0]], points_shifted[map[1]], | - |
395 | points_shifted[map[2]], points_shifted[map[3]]); executed (the execution status of this line is deduced): points_shifted[map[2]], points_shifted[map[3]]); | - |
396 | | - |
397 | return good_offset(orig, shifted, offset, threshold); executed: return good_offset(orig, shifted, offset, threshold); Execution Count:7712 | 7712 |
398 | } | - |
399 | | - |
400 | // This value is used to determine the length of control point vectors | - |
401 | // when approximating arc segments as curves. The factor is multiplied | - |
402 | // with the radius of the circle. | - |
403 | #define KAPPA qreal(0.5522847498) | - |
404 | | - |
405 | | - |
406 | static bool addCircle(const QBezier *b, qreal offset, QBezier *o) | - |
407 | { | - |
408 | QPointF normals[3]; never executed (the execution status of this line is deduced): QPointF normals[3]; | - |
409 | | - |
410 | normals[0] = QPointF(b->y2 - b->y1, b->x1 - b->x2); never executed (the execution status of this line is deduced): normals[0] = QPointF(b->y2 - b->y1, b->x1 - b->x2); | - |
411 | qreal dist = qSqrt(normals[0].x()*normals[0].x() + normals[0].y()*normals[0].y()); never executed (the execution status of this line is deduced): qreal dist = qSqrt(normals[0].x()*normals[0].x() + normals[0].y()*normals[0].y()); | - |
412 | if (qFuzzyIsNull(dist)) never evaluated: qFuzzyIsNull(dist) | 0 |
413 | return false; never executed: return false; | 0 |
414 | normals[0] /= dist; never executed (the execution status of this line is deduced): normals[0] /= dist; | - |
415 | normals[2] = QPointF(b->y4 - b->y3, b->x3 - b->x4); never executed (the execution status of this line is deduced): normals[2] = QPointF(b->y4 - b->y3, b->x3 - b->x4); | - |
416 | dist = qSqrt(normals[2].x()*normals[2].x() + normals[2].y()*normals[2].y()); never executed (the execution status of this line is deduced): dist = qSqrt(normals[2].x()*normals[2].x() + normals[2].y()*normals[2].y()); | - |
417 | if (qFuzzyIsNull(dist)) never evaluated: qFuzzyIsNull(dist) | 0 |
418 | return false; never executed: return false; | 0 |
419 | normals[2] /= dist; never executed (the execution status of this line is deduced): normals[2] /= dist; | - |
420 | | - |
421 | normals[1] = QPointF(b->x1 - b->x2 - b->x3 + b->x4, b->y1 - b->y2 - b->y3 + b->y4); never executed (the execution status of this line is deduced): normals[1] = QPointF(b->x1 - b->x2 - b->x3 + b->x4, b->y1 - b->y2 - b->y3 + b->y4); | - |
422 | normals[1] /= -1*qSqrt(normals[1].x()*normals[1].x() + normals[1].y()*normals[1].y()); never executed (the execution status of this line is deduced): normals[1] /= -1*qSqrt(normals[1].x()*normals[1].x() + normals[1].y()*normals[1].y()); | - |
423 | | - |
424 | qreal angles[2]; never executed (the execution status of this line is deduced): qreal angles[2]; | - |
425 | qreal sign = 1.; never executed (the execution status of this line is deduced): qreal sign = 1.; | - |
426 | for (int i = 0; i < 2; ++i) { | 0 |
427 | qreal cos_a = normals[i].x()*normals[i+1].x() + normals[i].y()*normals[i+1].y(); never executed (the execution status of this line is deduced): qreal cos_a = normals[i].x()*normals[i+1].x() + normals[i].y()*normals[i+1].y(); | - |
428 | if (cos_a > 1.) never evaluated: cos_a > 1. | 0 |
429 | cos_a = 1.; never executed: cos_a = 1.; | 0 |
430 | if (cos_a < -1.) never evaluated: cos_a < -1. | 0 |
431 | cos_a = -1; never executed: cos_a = -1; | 0 |
432 | angles[i] = qAcos(cos_a)/Q_PI; never executed (the execution status of this line is deduced): angles[i] = qAcos(cos_a)/Q_PI; | - |
433 | } | 0 |
434 | | - |
435 | if (angles[0] + angles[1] > 1.) { never evaluated: angles[0] + angles[1] > 1. | 0 |
436 | // more than 180 degrees | - |
437 | normals[1] = -normals[1]; never executed (the execution status of this line is deduced): normals[1] = -normals[1]; | - |
438 | angles[0] = 1. - angles[0]; never executed (the execution status of this line is deduced): angles[0] = 1. - angles[0]; | - |
439 | angles[1] = 1. - angles[1]; never executed (the execution status of this line is deduced): angles[1] = 1. - angles[1]; | - |
440 | sign = -1.; never executed (the execution status of this line is deduced): sign = -1.; | - |
441 | | - |
442 | } | 0 |
443 | | - |
444 | QPointF circle[3]; never executed (the execution status of this line is deduced): QPointF circle[3]; | - |
445 | circle[0] = QPointF(b->x1, b->y1) + normals[0]*offset; never executed (the execution status of this line is deduced): circle[0] = QPointF(b->x1, b->y1) + normals[0]*offset; | - |
446 | circle[1] = QPointF(qreal(0.5)*(b->x1 + b->x4), qreal(0.5)*(b->y1 + b->y4)) + normals[1]*offset; never executed (the execution status of this line is deduced): circle[1] = QPointF(qreal(0.5)*(b->x1 + b->x4), qreal(0.5)*(b->y1 + b->y4)) + normals[1]*offset; | - |
447 | circle[2] = QPointF(b->x4, b->y4) + normals[2]*offset; never executed (the execution status of this line is deduced): circle[2] = QPointF(b->x4, b->y4) + normals[2]*offset; | - |
448 | | - |
449 | for (int i = 0; i < 2; ++i) { | 0 |
450 | qreal kappa = qreal(2.0) * KAPPA * sign * offset * angles[i]; never executed (the execution status of this line is deduced): qreal kappa = qreal(2.0) * qreal(0.5522847498) * sign * offset * angles[i]; | - |
451 | | - |
452 | o->x1 = circle[i].x(); never executed (the execution status of this line is deduced): o->x1 = circle[i].x(); | - |
453 | o->y1 = circle[i].y(); never executed (the execution status of this line is deduced): o->y1 = circle[i].y(); | - |
454 | o->x2 = circle[i].x() - normals[i].y()*kappa; never executed (the execution status of this line is deduced): o->x2 = circle[i].x() - normals[i].y()*kappa; | - |
455 | o->y2 = circle[i].y() + normals[i].x()*kappa; never executed (the execution status of this line is deduced): o->y2 = circle[i].y() + normals[i].x()*kappa; | - |
456 | o->x3 = circle[i+1].x() + normals[i+1].y()*kappa; never executed (the execution status of this line is deduced): o->x3 = circle[i+1].x() + normals[i+1].y()*kappa; | - |
457 | o->y3 = circle[i+1].y() - normals[i+1].x()*kappa; never executed (the execution status of this line is deduced): o->y3 = circle[i+1].y() - normals[i+1].x()*kappa; | - |
458 | o->x4 = circle[i+1].x(); never executed (the execution status of this line is deduced): o->x4 = circle[i+1].x(); | - |
459 | o->y4 = circle[i+1].y(); never executed (the execution status of this line is deduced): o->y4 = circle[i+1].y(); | - |
460 | | - |
461 | ++o; never executed (the execution status of this line is deduced): ++o; | - |
462 | } | 0 |
463 | return true; never executed: return true; | 0 |
464 | } | - |
465 | | - |
466 | int QBezier::shifted(QBezier *curveSegments, int maxSegments, qreal offset, float threshold) const | - |
467 | { | - |
468 | Q_ASSERT(curveSegments); executed (the execution status of this line is deduced): qt_noop(); | - |
469 | Q_ASSERT(maxSegments > 0); executed (the execution status of this line is deduced): qt_noop(); | - |
470 | | - |
471 | if (x1 == x2 && x1 == x3 && x1 == x4 && evaluated: x1 == x2 yes Evaluation Count:3644 | yes Evaluation Count:3652 |
partially evaluated: x1 == x3 no Evaluation Count:0 | yes Evaluation Count:3644 |
never evaluated: x1 == x4 | 0-3652 |
472 | y1 == y2 && y1 == y3 && y1 == y4) never evaluated: y1 == y2 never evaluated: y1 == y3 never evaluated: y1 == y4 | 0 |
473 | return 0; never executed: return 0; | 0 |
474 | | - |
475 | --maxSegments; executed (the execution status of this line is deduced): --maxSegments; | - |
476 | QBezier beziers[10]; executed (the execution status of this line is deduced): QBezier beziers[10]; | - |
477 | redo: code before this statement executed: redo: Execution Count:7296 | 7296 |
478 | beziers[0] = *this; executed (the execution status of this line is deduced): beziers[0] = *this; | - |
479 | QBezier *b = beziers; executed (the execution status of this line is deduced): QBezier *b = beziers; | - |
480 | QBezier *o = curveSegments; executed (the execution status of this line is deduced): QBezier *o = curveSegments; | - |
481 | | - |
482 | while (b >= beziers) { evaluated: b >= beziers yes Evaluation Count:7712 | yes Evaluation Count:7296 |
| 7296-7712 |
483 | int stack_segments = b - beziers + 1; executed (the execution status of this line is deduced): int stack_segments = b - beziers + 1; | - |
484 | if ((stack_segments == 10) || (o - curveSegments == maxSegments - stack_segments)) { partially evaluated: (stack_segments == 10) no Evaluation Count:0 | yes Evaluation Count:7712 |
partially evaluated: (o - curveSegments == maxSegments - stack_segments) no Evaluation Count:0 | yes Evaluation Count:7712 |
| 0-7712 |
485 | threshold *= qreal(1.5); never executed (the execution status of this line is deduced): threshold *= qreal(1.5); | - |
486 | if (threshold > qreal(2.0)) never evaluated: threshold > qreal(2.0) | 0 |
487 | goto give_up; never executed: goto give_up; | 0 |
488 | goto redo; never executed: goto redo; | 0 |
489 | } | - |
490 | ShiftResult res = shift(b, o, offset, threshold); executed (the execution status of this line is deduced): ShiftResult res = shift(b, o, offset, threshold); | - |
491 | if (res == Discard) { partially evaluated: res == Discard no Evaluation Count:0 | yes Evaluation Count:7712 |
| 0-7712 |
492 | --b; never executed (the execution status of this line is deduced): --b; | - |
493 | } else if (res == Ok) { never executed: } evaluated: res == Ok yes Evaluation Count:7504 | yes Evaluation Count:208 |
| 0-7504 |
494 | ++o; executed (the execution status of this line is deduced): ++o; | - |
495 | --b; executed (the execution status of this line is deduced): --b; | - |
496 | continue; executed: continue; Execution Count:7504 | 7504 |
497 | } else if (res == Circle && maxSegments - (o - curveSegments) >= 2) { partially evaluated: res == Circle no Evaluation Count:0 | yes Evaluation Count:208 |
never evaluated: maxSegments - (o - curveSegments) >= 2 | 0-208 |
498 | // add semi circle | - |
499 | if (addCircle(b, offset, o)) never evaluated: addCircle(b, offset, o) | 0 |
500 | o += 2; | 0 |
501 | --b; never executed (the execution status of this line is deduced): --b; | - |
502 | } else { | 0 |
503 | b->split(b+1, b); executed (the execution status of this line is deduced): b->split(b+1, b); | - |
504 | ++b; executed (the execution status of this line is deduced): ++b; | - |
505 | } executed: } Execution Count:208 | 208 |
506 | } | - |
507 | | - |
508 | give_up: code before this statement executed: give_up: Execution Count:7296 | 7296 |
509 | while (b >= beziers) { partially evaluated: b >= beziers no Evaluation Count:0 | yes Evaluation Count:7296 |
| 0-7296 |
510 | ShiftResult res = shift(b, o, offset, threshold); never executed (the execution status of this line is deduced): ShiftResult res = shift(b, o, offset, threshold); | - |
511 | | - |
512 | // if res isn't Ok or Split then *o is undefined | - |
513 | if (res == Ok || res == Split) never evaluated: res == Ok never evaluated: res == Split | 0 |
514 | ++o; | 0 |
515 | | - |
516 | --b; never executed (the execution status of this line is deduced): --b; | - |
517 | } | 0 |
518 | | - |
519 | Q_ASSERT(o - curveSegments <= maxSegments); executed (the execution status of this line is deduced): qt_noop(); | - |
520 | return o - curveSegments; executed: return o - curveSegments; Execution Count:7296 | 7296 |
521 | } | - |
522 | | - |
523 | #ifdef QDEBUG_BEZIER | - |
524 | static QDebug operator<<(QDebug dbg, const QBezier &bz) | - |
525 | { | - |
526 | dbg << '[' << bz.x1<< ", " << bz.y1 << "], " | - |
527 | << '[' << bz.x2 <<", " << bz.y2 << "], " | - |
528 | << '[' << bz.x3 <<", " << bz.y3 << "], " | - |
529 | << '[' << bz.x4 <<", " << bz.y4 << ']'; | - |
530 | return dbg; | - |
531 | } | - |
532 | #endif | - |
533 | | - |
534 | static inline void splitBezierAt(const QBezier &bez, qreal t, | - |
535 | QBezier *left, QBezier *right) | - |
536 | { | - |
537 | left->x1 = bez.x1; never executed (the execution status of this line is deduced): left->x1 = bez.x1; | - |
538 | left->y1 = bez.y1; never executed (the execution status of this line is deduced): left->y1 = bez.y1; | - |
539 | | - |
540 | left->x2 = bez.x1 + t * ( bez.x2 - bez.x1 ); never executed (the execution status of this line is deduced): left->x2 = bez.x1 + t * ( bez.x2 - bez.x1 ); | - |
541 | left->y2 = bez.y1 + t * ( bez.y2 - bez.y1 ); never executed (the execution status of this line is deduced): left->y2 = bez.y1 + t * ( bez.y2 - bez.y1 ); | - |
542 | | - |
543 | left->x3 = bez.x2 + t * ( bez.x3 - bez.x2 ); // temporary holding spot never executed (the execution status of this line is deduced): left->x3 = bez.x2 + t * ( bez.x3 - bez.x2 ); | - |
544 | left->y3 = bez.y2 + t * ( bez.y3 - bez.y2 ); // temporary holding spot never executed (the execution status of this line is deduced): left->y3 = bez.y2 + t * ( bez.y3 - bez.y2 ); | - |
545 | | - |
546 | right->x3 = bez.x3 + t * ( bez.x4 - bez.x3 ); never executed (the execution status of this line is deduced): right->x3 = bez.x3 + t * ( bez.x4 - bez.x3 ); | - |
547 | right->y3 = bez.y3 + t * ( bez.y4 - bez.y3 ); never executed (the execution status of this line is deduced): right->y3 = bez.y3 + t * ( bez.y4 - bez.y3 ); | - |
548 | | - |
549 | right->x2 = left->x3 + t * ( right->x3 - left->x3); never executed (the execution status of this line is deduced): right->x2 = left->x3 + t * ( right->x3 - left->x3); | - |
550 | right->y2 = left->y3 + t * ( right->y3 - left->y3); never executed (the execution status of this line is deduced): right->y2 = left->y3 + t * ( right->y3 - left->y3); | - |
551 | | - |
552 | left->x3 = left->x2 + t * ( left->x3 - left->x2 ); never executed (the execution status of this line is deduced): left->x3 = left->x2 + t * ( left->x3 - left->x2 ); | - |
553 | left->y3 = left->y2 + t * ( left->y3 - left->y2 ); never executed (the execution status of this line is deduced): left->y3 = left->y2 + t * ( left->y3 - left->y2 ); | - |
554 | | - |
555 | left->x4 = right->x1 = left->x3 + t * (right->x2 - left->x3); never executed (the execution status of this line is deduced): left->x4 = right->x1 = left->x3 + t * (right->x2 - left->x3); | - |
556 | left->y4 = right->y1 = left->y3 + t * (right->y2 - left->y3); never executed (the execution status of this line is deduced): left->y4 = right->y1 = left->y3 + t * (right->y2 - left->y3); | - |
557 | | - |
558 | right->x4 = bez.x4; never executed (the execution status of this line is deduced): right->x4 = bez.x4; | - |
559 | right->y4 = bez.y4; never executed (the execution status of this line is deduced): right->y4 = bez.y4; | - |
560 | } | 0 |
561 | | - |
562 | qreal QBezier::length(qreal error) const | - |
563 | { | - |
564 | qreal length = qreal(0.0); executed (the execution status of this line is deduced): qreal length = qreal(0.0); | - |
565 | | - |
566 | addIfClose(&length, error); executed (the execution status of this line is deduced): addIfClose(&length, error); | - |
567 | | - |
568 | return length; executed: return length; Execution Count:111 | 111 |
569 | } | - |
570 | | - |
571 | void QBezier::addIfClose(qreal *length, qreal error) const | - |
572 | { | - |
573 | QBezier left, right; /* bez poly splits */ executed (the execution status of this line is deduced): QBezier left, right; | - |
574 | | - |
575 | qreal len = qreal(0.0); /* arc length */ executed (the execution status of this line is deduced): qreal len = qreal(0.0); | - |
576 | qreal chord; /* chord length */ executed (the execution status of this line is deduced): qreal chord; | - |
577 | | - |
578 | len = len + QLineF(QPointF(x1, y1),QPointF(x2, y2)).length(); executed (the execution status of this line is deduced): len = len + QLineF(QPointF(x1, y1),QPointF(x2, y2)).length(); | - |
579 | len = len + QLineF(QPointF(x2, y2),QPointF(x3, y3)).length(); executed (the execution status of this line is deduced): len = len + QLineF(QPointF(x2, y2),QPointF(x3, y3)).length(); | - |
580 | len = len + QLineF(QPointF(x3, y3),QPointF(x4, y4)).length(); executed (the execution status of this line is deduced): len = len + QLineF(QPointF(x3, y3),QPointF(x4, y4)).length(); | - |
581 | | - |
582 | chord = QLineF(QPointF(x1, y1),QPointF(x4, y4)).length(); executed (the execution status of this line is deduced): chord = QLineF(QPointF(x1, y1),QPointF(x4, y4)).length(); | - |
583 | | - |
584 | if((len-chord) > error) { evaluated: (len-chord) > error yes Evaluation Count:2748 | yes Evaluation Count:2859 |
| 2748-2859 |
585 | split(&left, &right); /* split in two */ executed (the execution status of this line is deduced): split(&left, &right); | - |
586 | left.addIfClose(length, error); /* try left side */ executed (the execution status of this line is deduced): left.addIfClose(length, error); | - |
587 | right.addIfClose(length, error); /* try right side */ executed (the execution status of this line is deduced): right.addIfClose(length, error); | - |
588 | return; executed: return; Execution Count:2748 | 2748 |
589 | } | - |
590 | | - |
591 | *length = *length + len; executed (the execution status of this line is deduced): *length = *length + len; | - |
592 | | - |
593 | return; executed: return; Execution Count:2859 | 2859 |
594 | } | - |
595 | | - |
596 | qreal QBezier::tForY(qreal t0, qreal t1, qreal y) const | - |
597 | { | - |
598 | qreal py0 = pointAt(t0).y(); never executed (the execution status of this line is deduced): qreal py0 = pointAt(t0).y(); | - |
599 | qreal py1 = pointAt(t1).y(); never executed (the execution status of this line is deduced): qreal py1 = pointAt(t1).y(); | - |
600 | | - |
601 | if (py0 > py1) { never evaluated: py0 > py1 | 0 |
602 | qSwap(py0, py1); never executed (the execution status of this line is deduced): qSwap(py0, py1); | - |
603 | qSwap(t0, t1); never executed (the execution status of this line is deduced): qSwap(t0, t1); | - |
604 | } | 0 |
605 | | - |
606 | Q_ASSERT(py0 <= py1); never executed (the execution status of this line is deduced): qt_noop(); | - |
607 | | - |
608 | if (py0 >= y) never evaluated: py0 >= y | 0 |
609 | return t0; never executed: return t0; | 0 |
610 | else if (py1 <= y) never evaluated: py1 <= y | 0 |
611 | return t1; never executed: return t1; | 0 |
612 | | - |
613 | Q_ASSERT(py0 < y && y < py1); never executed (the execution status of this line is deduced): qt_noop(); | - |
614 | | - |
615 | qreal lt = t0; never executed (the execution status of this line is deduced): qreal lt = t0; | - |
616 | qreal dt; never executed (the execution status of this line is deduced): qreal dt; | - |
617 | do { | - |
618 | qreal t = qreal(0.5) * (t0 + t1); never executed (the execution status of this line is deduced): qreal t = qreal(0.5) * (t0 + t1); | - |
619 | | - |
620 | qreal a, b, c, d; never executed (the execution status of this line is deduced): qreal a, b, c, d; | - |
621 | QBezier::coefficients(t, a, b, c, d); never executed (the execution status of this line is deduced): QBezier::coefficients(t, a, b, c, d); | - |
622 | qreal yt = a * y1 + b * y2 + c * y3 + d * y4; never executed (the execution status of this line is deduced): qreal yt = a * y1 + b * y2 + c * y3 + d * y4; | - |
623 | | - |
624 | if (yt < y) { | 0 |
625 | t0 = t; never executed (the execution status of this line is deduced): t0 = t; | - |
626 | py0 = yt; never executed (the execution status of this line is deduced): py0 = yt; | - |
627 | } else { | 0 |
628 | t1 = t; never executed (the execution status of this line is deduced): t1 = t; | - |
629 | py1 = yt; never executed (the execution status of this line is deduced): py1 = yt; | - |
630 | } | 0 |
631 | dt = lt - t; never executed (the execution status of this line is deduced): dt = lt - t; | - |
632 | lt = t; never executed (the execution status of this line is deduced): lt = t; | - |
633 | } while (qAbs(dt) > qreal(1e-7)); never executed: } never evaluated: qAbs(dt) > qreal(1e-7) | 0 |
634 | | - |
635 | return t0; never executed: return t0; | 0 |
636 | } | - |
637 | | - |
638 | int QBezier::stationaryYPoints(qreal &t0, qreal &t1) const | - |
639 | { | - |
640 | // y(t) = (1 - t)^3 * y1 + 3 * (1 - t)^2 * t * y2 + 3 * (1 - t) * t^2 * y3 + t^3 * y4 | - |
641 | // y'(t) = 3 * (-(1-2t+t^2) * y1 + (1 - 4 * t + 3 * t^2) * y2 + (2 * t - 3 * t^2) * y3 + t^2 * y4) | - |
642 | // y'(t) = 3 * ((-y1 + 3 * y2 - 3 * y3 + y4)t^2 + (2 * y1 - 4 * y2 + 2 * y3)t + (-y1 + y2)) | - |
643 | | - |
644 | const qreal a = -y1 + 3 * y2 - 3 * y3 + y4; never executed (the execution status of this line is deduced): const qreal a = -y1 + 3 * y2 - 3 * y3 + y4; | - |
645 | const qreal b = 2 * y1 - 4 * y2 + 2 * y3; never executed (the execution status of this line is deduced): const qreal b = 2 * y1 - 4 * y2 + 2 * y3; | - |
646 | const qreal c = -y1 + y2; never executed (the execution status of this line is deduced): const qreal c = -y1 + y2; | - |
647 | | - |
648 | if (qFuzzyIsNull(a)) { never evaluated: qFuzzyIsNull(a) | 0 |
649 | if (qFuzzyIsNull(b)) never evaluated: qFuzzyIsNull(b) | 0 |
650 | return 0; never executed: return 0; | 0 |
651 | | - |
652 | t0 = -c / b; never executed (the execution status of this line is deduced): t0 = -c / b; | - |
653 | return t0 > 0 && t0 < 1; never executed: return t0 > 0 && t0 < 1; | 0 |
654 | } | - |
655 | | - |
656 | qreal reciprocal = b * b - 4 * a * c; never executed (the execution status of this line is deduced): qreal reciprocal = b * b - 4 * a * c; | - |
657 | | - |
658 | if (qFuzzyIsNull(reciprocal)) { never evaluated: qFuzzyIsNull(reciprocal) | 0 |
659 | t0 = -b / (2 * a); never executed (the execution status of this line is deduced): t0 = -b / (2 * a); | - |
660 | return t0 > 0 && t0 < 1; never executed: return t0 > 0 && t0 < 1; | 0 |
661 | } else if (reciprocal > 0) { never evaluated: reciprocal > 0 | 0 |
662 | qreal temp = qSqrt(reciprocal); never executed (the execution status of this line is deduced): qreal temp = qSqrt(reciprocal); | - |
663 | | - |
664 | t0 = (-b - temp)/(2*a); never executed (the execution status of this line is deduced): t0 = (-b - temp)/(2*a); | - |
665 | t1 = (-b + temp)/(2*a); never executed (the execution status of this line is deduced): t1 = (-b + temp)/(2*a); | - |
666 | | - |
667 | if (t1 < t0) | 0 |
668 | qSwap(t0, t1); never executed: qSwap(t0, t1); | 0 |
669 | | - |
670 | int count = 0; never executed (the execution status of this line is deduced): int count = 0; | - |
671 | qreal t[2] = { 0, 1 }; never executed (the execution status of this line is deduced): qreal t[2] = { 0, 1 }; | - |
672 | | - |
673 | if (t0 > 0 && t0 < 1) never evaluated: t0 > 0 never evaluated: t0 < 1 | 0 |
674 | t[count++] = t0; never executed: t[count++] = t0; | 0 |
675 | if (t1 > 0 && t1 < 1) never evaluated: t1 > 0 never evaluated: t1 < 1 | 0 |
676 | t[count++] = t1; never executed: t[count++] = t1; | 0 |
677 | | - |
678 | t0 = t[0]; never executed (the execution status of this line is deduced): t0 = t[0]; | - |
679 | t1 = t[1]; never executed (the execution status of this line is deduced): t1 = t[1]; | - |
680 | | - |
681 | return count; never executed: return count; | 0 |
682 | } | - |
683 | | - |
684 | return 0; never executed: return 0; | 0 |
685 | } | - |
686 | | - |
687 | qreal QBezier::tAtLength(qreal l) const | - |
688 | { | - |
689 | qreal len = length(); never executed (the execution status of this line is deduced): qreal len = length(); | - |
690 | qreal t = qreal(1.0); never executed (the execution status of this line is deduced): qreal t = qreal(1.0); | - |
691 | const qreal error = qreal(0.01); never executed (the execution status of this line is deduced): const qreal error = qreal(0.01); | - |
692 | if (l > len || qFuzzyCompare(l, len)) never evaluated: l > len never evaluated: qFuzzyCompare(l, len) | 0 |
693 | return t; never executed: return t; | 0 |
694 | | - |
695 | t *= qreal(0.5); never executed (the execution status of this line is deduced): t *= qreal(0.5); | - |
696 | //int iters = 0; | - |
697 | //qDebug()<<"LEN is "<<l<<len; | - |
698 | qreal lastBigger = qreal(1.0); never executed (the execution status of this line is deduced): qreal lastBigger = qreal(1.0); | - |
699 | while (1) { | 0 |
700 | //qDebug()<<"\tt is "<<t; | - |
701 | QBezier right = *this; never executed (the execution status of this line is deduced): QBezier right = *this; | - |
702 | QBezier left; never executed (the execution status of this line is deduced): QBezier left; | - |
703 | right.parameterSplitLeft(t, &left); never executed (the execution status of this line is deduced): right.parameterSplitLeft(t, &left); | - |
704 | qreal lLen = left.length(); never executed (the execution status of this line is deduced): qreal lLen = left.length(); | - |
705 | if (qAbs(lLen - l) < error) never evaluated: qAbs(lLen - l) < error | 0 |
706 | break; | 0 |
707 | | - |
708 | if (lLen < l) { never evaluated: lLen < l | 0 |
709 | t += (lastBigger - t) * qreal(0.5); never executed (the execution status of this line is deduced): t += (lastBigger - t) * qreal(0.5); | - |
710 | } else { | 0 |
711 | lastBigger = t; never executed (the execution status of this line is deduced): lastBigger = t; | - |
712 | t -= t * qreal(0.5); never executed (the execution status of this line is deduced): t -= t * qreal(0.5); | - |
713 | } | 0 |
714 | //++iters; | - |
715 | } | - |
716 | //qDebug()<<"number of iters is "<<iters; | - |
717 | return t; never executed: return t; | 0 |
718 | } | - |
719 | | - |
720 | QBezier QBezier::bezierOnInterval(qreal t0, qreal t1) const | - |
721 | { | - |
722 | if (t0 == 0 && t1 == 1) evaluated: t0 == 0 yes Evaluation Count:1942 | yes Evaluation Count:5731 |
partially evaluated: t1 == 1 no Evaluation Count:0 | yes Evaluation Count:1942 |
| 0-5731 |
723 | return *this; never executed: return *this; | 0 |
724 | | - |
725 | QBezier bezier = *this; executed (the execution status of this line is deduced): QBezier bezier = *this; | - |
726 | | - |
727 | QBezier result; executed (the execution status of this line is deduced): QBezier result; | - |
728 | bezier.parameterSplitLeft(t0, &result); executed (the execution status of this line is deduced): bezier.parameterSplitLeft(t0, &result); | - |
729 | qreal trueT = (t1-t0)/(1-t0); executed (the execution status of this line is deduced): qreal trueT = (t1-t0)/(1-t0); | - |
730 | bezier.parameterSplitLeft(trueT, &result); executed (the execution status of this line is deduced): bezier.parameterSplitLeft(trueT, &result); | - |
731 | | - |
732 | return result; executed: return result; Execution Count:7673 | 7673 |
733 | } | - |
734 | | - |
735 | QT_END_NAMESPACE | - |
736 | | - |
| | |