Line | Source Code | Coverage |
---|
1 | | - |
2 | | - |
3 | | - |
4 | | - |
5 | | - |
6 | | - |
7 | | - |
8 | | - |
9 | | - |
10 | | - |
11 | static bool isConfigFunction(QEasingCurve::Type type) | - |
12 | { | - |
13 | return (type >= QEasingCurve::InElastic | 1184 |
14 | && type <= QEasingCurve::OutInBounce) || | 1184 |
15 | type == QEasingCurve::BezierSpline || | 1184 |
16 | type == QEasingCurve::TCBSpline; executed: return (type >= QEasingCurve::InElastic && type <= QEasingCurve::OutInBounce) || type == QEasingCurve::BezierSpline || type == QEasingCurve::TCBSpline; Execution Count:1184 | 1184 |
17 | } | - |
18 | | - |
19 | struct TCBPoint { | - |
20 | QPointF _point; | - |
21 | qreal _t; | - |
22 | qreal _c; | - |
23 | qreal _b; | - |
24 | | - |
25 | TCBPoint() {} | - |
26 | TCBPoint(QPointF point, qreal t, qreal c, qreal b) : _point(point), _t(t), _c(c), _b(b) {} executed: } Execution Count:12 | 12 |
27 | | - |
28 | bool operator==(const TCBPoint &other) const | - |
29 | { | - |
30 | return _point == other._point && | 0 |
31 | qFuzzyCompare(_t, other._t) && | 0 |
32 | qFuzzyCompare(_c, other._c) && | 0 |
33 | qFuzzyCompare(_b, other._b); never executed: return _point == other._point && qFuzzyCompare(_t, other._t) && qFuzzyCompare(_c, other._c) && qFuzzyCompare(_b, other._b); | 0 |
34 | } | - |
35 | }; | - |
36 | | - |
37 | | - |
38 | typedef QVector<TCBPoint> TCBPoints; | - |
39 | | - |
40 | class QEasingCurveFunction | - |
41 | { | - |
42 | public: | - |
43 | enum Type { In, Out, InOut, OutIn }; | - |
44 | | - |
45 | QEasingCurveFunction(QEasingCurveFunction::Type type = In, qreal period = 0.3, qreal amplitude = 1.0, | - |
46 | qreal overshoot = 1.70158) | - |
47 | : _t(type), _p(period), _a(amplitude), _o(overshoot) | - |
48 | { } executed: } Execution Count:118 | 118 |
49 | virtual ~QEasingCurveFunction() {} | - |
50 | virtual qreal value(qreal t); | - |
51 | virtual QEasingCurveFunction *copy() const; | - |
52 | bool operator==(const QEasingCurveFunction &other) const; | - |
53 | | - |
54 | Type _t; | - |
55 | qreal _p; | - |
56 | qreal _a; | - |
57 | qreal _o; | - |
58 | QVector<QPointF> _bezierCurves; | - |
59 | TCBPoints _tcbPoints; | - |
60 | | - |
61 | }; | - |
62 | | - |
63 | qreal QEasingCurveFunction::value(qreal t) | - |
64 | { | - |
65 | return t; never executed: return t; | 0 |
66 | } | - |
67 | | - |
68 | QEasingCurveFunction *QEasingCurveFunction::copy() const | - |
69 | { | - |
70 | QEasingCurveFunction *rv = new QEasingCurveFunction(_t, _p, _a, _o); | - |
71 | rv->_bezierCurves = _bezierCurves; | - |
72 | rv->_tcbPoints = _tcbPoints; | - |
73 | return rv; never executed: return rv; | 0 |
74 | } | - |
75 | | - |
76 | bool QEasingCurveFunction::operator==(const QEasingCurveFunction &other) const | - |
77 | { | - |
78 | return _t == other._t && | 27 |
79 | qFuzzyCompare(_p, other._p) && | 27 |
80 | qFuzzyCompare(_a, other._a) && | 27 |
81 | qFuzzyCompare(_o, other._o) && | 27 |
82 | _bezierCurves == other._bezierCurves && | 27 |
83 | _tcbPoints == other._tcbPoints; executed: return _t == other._t && qFuzzyCompare(_p, other._p) && qFuzzyCompare(_a, other._a) && qFuzzyCompare(_o, other._o) && _bezierCurves == other._bezierCurves && _tcbPoints == other._tcbPoints; Execution Count:27 | 27 |
84 | } | - |
85 | | - |
86 | | - |
87 | | - |
88 | | - |
89 | class QEasingCurvePrivate | - |
90 | { | - |
91 | public: | - |
92 | QEasingCurvePrivate() | - |
93 | : type(QEasingCurve::Linear), | - |
94 | config(0), | - |
95 | func(&easeNone) | - |
96 | { } executed: } Execution Count:2554 | 2554 |
97 | QEasingCurvePrivate(const QEasingCurvePrivate &other) | - |
98 | : type(other.type), | - |
99 | config(other.config ? other.config->copy() : 0), | - |
100 | func(other.func) | - |
101 | { } executed: } Execution Count:1239 | 1239 |
102 | ~QEasingCurvePrivate() { delete config; } executed: } Execution Count:3681 | 3681 |
103 | void setType_helper(QEasingCurve::Type); | - |
104 | | - |
105 | QEasingCurve::Type type; | - |
106 | QEasingCurveFunction *config; | - |
107 | QEasingCurve::EasingFunction func; | - |
108 | }; | - |
109 | | - |
110 | struct BezierEase : public QEasingCurveFunction | - |
111 | { | - |
112 | struct SingleCubicBezier { | - |
113 | qreal p0x, p0y; | - |
114 | qreal p1x, p1y; | - |
115 | qreal p2x, p2y; | - |
116 | qreal p3x, p3y; | - |
117 | }; | - |
118 | | - |
119 | bool _init; | - |
120 | bool _valid; | - |
121 | QVector<SingleCubicBezier> _curves; | - |
122 | int _curveCount; | - |
123 | QVector<qreal> _intervals; | - |
124 | | - |
125 | BezierEase() | - |
126 | : QEasingCurveFunction(InOut), _init(false), _valid(false), _curves(10), _intervals(10) | - |
127 | { } executed: } Execution Count:7 | 7 |
128 | | - |
129 | void init() | - |
130 | { | - |
131 | if (_bezierCurves.last() == QPointF(1.0, 1.0)) { partially evaluated: _bezierCurves.last() == QPointF(1.0, 1.0) yes Evaluation Count:7 | no Evaluation Count:0 |
| 0-7 |
132 | _init = true; | - |
133 | _curveCount = _bezierCurves.count() / 3; | - |
134 | | - |
135 | for (int i=0; i < _curveCount; i++) { evaluated: i < _curveCount yes Evaluation Count:19 | yes Evaluation Count:7 |
| 7-19 |
136 | _intervals[i] = _bezierCurves.at(i * 3 + 2).x(); | - |
137 | | - |
138 | if (i == 0) { evaluated: i == 0 yes Evaluation Count:7 | yes Evaluation Count:12 |
| 7-12 |
139 | _curves[0].p0x = 0.0; | - |
140 | _curves[0].p0y = 0.0; | - |
141 | | - |
142 | _curves[0].p1x = _bezierCurves.at(0).x(); | - |
143 | _curves[0].p1y = _bezierCurves.at(0).y(); | - |
144 | | - |
145 | _curves[0].p2x = _bezierCurves.at(1).x(); | - |
146 | _curves[0].p2y = _bezierCurves.at(1).y(); | - |
147 | | - |
148 | _curves[0].p3x = _bezierCurves.at(2).x(); | - |
149 | _curves[0].p3y = _bezierCurves.at(2).y(); | - |
150 | | - |
151 | } else if (i == (_curveCount - 1)) { executed: } Execution Count:7 evaluated: i == (_curveCount - 1) yes Evaluation Count:7 | yes Evaluation Count:5 |
| 5-7 |
152 | _curves[i].p0x = _bezierCurves.at(_bezierCurves.count() - 4).x(); | - |
153 | _curves[i].p0y = _bezierCurves.at(_bezierCurves.count() - 4).y(); | - |
154 | | - |
155 | _curves[i].p1x = _bezierCurves.at(_bezierCurves.count() - 3).x(); | - |
156 | _curves[i].p1y = _bezierCurves.at(_bezierCurves.count() - 3).y(); | - |
157 | | - |
158 | _curves[i].p2x = _bezierCurves.at(_bezierCurves.count() - 2).x(); | - |
159 | _curves[i].p2y = _bezierCurves.at(_bezierCurves.count() - 2).y(); | - |
160 | | - |
161 | _curves[i].p3x = _bezierCurves.at(_bezierCurves.count() - 1).x(); | - |
162 | _curves[i].p3y = _bezierCurves.at(_bezierCurves.count() - 1).y(); | - |
163 | } else { executed: } Execution Count:7 | 7 |
164 | _curves[i].p0x = _bezierCurves.at(i * 3 - 1).x(); | - |
165 | _curves[i].p0y = _bezierCurves.at(i * 3 - 1).y(); | - |
166 | | - |
167 | _curves[i].p1x = _bezierCurves.at(i * 3).x(); | - |
168 | _curves[i].p1y = _bezierCurves.at(i * 3).y(); | - |
169 | | - |
170 | _curves[i].p2x = _bezierCurves.at(i * 3 + 1).x(); | - |
171 | _curves[i].p2y = _bezierCurves.at(i * 3 + 1).y(); | - |
172 | | - |
173 | _curves[i].p3x = _bezierCurves.at(i * 3 + 2).x(); | - |
174 | _curves[i].p3y = _bezierCurves.at(i * 3 + 2).y(); | - |
175 | } executed: } Execution Count:5 | 5 |
176 | } | - |
177 | _valid = true; | - |
178 | } else { executed: } Execution Count:7 | 7 |
179 | _valid = false; | - |
180 | } | 0 |
181 | } | - |
182 | | - |
183 | QEasingCurveFunction *copy() const | - |
184 | { | - |
185 | BezierEase *rv = new BezierEase(); | - |
186 | rv->_t = _t; | - |
187 | rv->_p = _p; | - |
188 | rv->_a = _a; | - |
189 | rv->_o = _o; | - |
190 | rv->_bezierCurves = _bezierCurves; | - |
191 | rv->_tcbPoints = _tcbPoints; | - |
192 | return rv; never executed: return rv; | 0 |
193 | } | - |
194 | | - |
195 | void getBezierSegment(SingleCubicBezier * &singleCubicBezier, qreal x) | - |
196 | { | - |
197 | | - |
198 | int currentSegment = 0; | - |
199 | | - |
200 | while (currentSegment < _curveCount) { partially evaluated: currentSegment < _curveCount yes Evaluation Count:88 | no Evaluation Count:0 |
| 0-88 |
201 | if (x <= _intervals.data()[currentSegment]) evaluated: x <= _intervals.data()[currentSegment] yes Evaluation Count:47 | yes Evaluation Count:41 |
| 41-47 |
202 | break; executed: break; Execution Count:47 | 47 |
203 | currentSegment++; | - |
204 | } executed: } Execution Count:41 | 41 |
205 | | - |
206 | singleCubicBezier = &_curves.data()[currentSegment]; | - |
207 | } executed: } Execution Count:47 | 47 |
208 | | - |
209 | | - |
210 | qreal static inline newtonIteration(const SingleCubicBezier &singleCubicBezier, qreal t, qreal x) | - |
211 | { | - |
212 | qreal currentXValue = evaluateForX(singleCubicBezier, t); | - |
213 | | - |
214 | const qreal newT = t - (currentXValue - x) / evaluateDerivateForX(singleCubicBezier, t); | - |
215 | | - |
216 | return newT; never executed: return newT; | 0 |
217 | } | - |
218 | | - |
219 | qreal value(qreal x) | - |
220 | { | - |
221 | qt_noop(); | - |
222 | | - |
223 | if (_bezierCurves.isEmpty()) { partially evaluated: _bezierCurves.isEmpty() no Evaluation Count:0 | yes Evaluation Count:47 |
| 0-47 |
224 | return x; never executed: return x; | 0 |
225 | } | - |
226 | | - |
227 | if (!_init) evaluated: !_init yes Evaluation Count:7 | yes Evaluation Count:40 |
| 7-40 |
228 | init(); executed: init(); Execution Count:7 | 7 |
229 | | - |
230 | if (!_valid) { partially evaluated: !_valid no Evaluation Count:0 | yes Evaluation Count:47 |
| 0-47 |
231 | QMessageLogger("tools/qeasingcurve.cpp", 547, __PRETTY_FUNCTION__).warning("QEasingCurve: Invalid bezier curve"); | - |
232 | return x; never executed: return x; | 0 |
233 | } | - |
234 | SingleCubicBezier *singleCubicBezier = 0; | - |
235 | getBezierSegment(singleCubicBezier, x); | - |
236 | | - |
237 | return evaluateSegmentForY(*singleCubicBezier, findTForX(*singleCubicBezier, x)); executed: return evaluateSegmentForY(*singleCubicBezier, findTForX(*singleCubicBezier, x)); Execution Count:47 | 47 |
238 | } | - |
239 | | - |
240 | qreal static inline evaluateSegmentForY(const SingleCubicBezier &singleCubicBezier, qreal t) | - |
241 | { | - |
242 | const qreal p0 = singleCubicBezier.p0y; | - |
243 | const qreal p1 = singleCubicBezier.p1y; | - |
244 | const qreal p2 = singleCubicBezier.p2y; | - |
245 | const qreal p3 = singleCubicBezier.p3y; | - |
246 | | - |
247 | const qreal s = 1 - t; | - |
248 | | - |
249 | const qreal s_squared = s*s; | - |
250 | const qreal t_squared = t*t; | - |
251 | | - |
252 | const qreal s_cubic = s_squared * s; | - |
253 | const qreal t_cubic = t_squared * t; | - |
254 | | - |
255 | return s_cubic * p0 + 3 * s_squared * t * p1 + 3 * s * t_squared * p2 + t_cubic * p3; executed: return s_cubic * p0 + 3 * s_squared * t * p1 + 3 * s * t_squared * p2 + t_cubic * p3; Execution Count:47 | 47 |
256 | } | - |
257 | | - |
258 | qreal static inline evaluateForX(const SingleCubicBezier &singleCubicBezier, qreal t) | - |
259 | { | - |
260 | const qreal p0 = singleCubicBezier.p0x; | - |
261 | const qreal p1 = singleCubicBezier.p1x; | - |
262 | const qreal p2 = singleCubicBezier.p2x; | - |
263 | const qreal p3 = singleCubicBezier.p3x; | - |
264 | | - |
265 | const qreal s = 1 - t; | - |
266 | | - |
267 | const qreal s_squared = s*s; | - |
268 | const qreal t_squared = t*t; | - |
269 | | - |
270 | const qreal s_cubic = s_squared * s; | - |
271 | const qreal t_cubic = t_squared * t; | - |
272 | | - |
273 | return s_cubic * p0 + 3 * s_squared * t * p1 + 3 * s * t_squared * p2 + t_cubic * p3; never executed: return s_cubic * p0 + 3 * s_squared * t * p1 + 3 * s * t_squared * p2 + t_cubic * p3; | 0 |
274 | } | - |
275 | | - |
276 | qreal static inline evaluateDerivateForX(const SingleCubicBezier &singleCubicBezier, qreal t) | - |
277 | { | - |
278 | const qreal p0 = singleCubicBezier.p0x; | - |
279 | const qreal p1 = singleCubicBezier.p1x; | - |
280 | const qreal p2 = singleCubicBezier.p2x; | - |
281 | const qreal p3 = singleCubicBezier.p3x; | - |
282 | | - |
283 | const qreal t_squared = t*t; | - |
284 | | - |
285 | return -3*p0 + 3*p1 + 6*p0*t - 12*p1*t + 6*p2*t + 3*p3*t_squared - 3*p0*t_squared + 9*p1*t_squared - 9*p2*t_squared; never executed: return -3*p0 + 3*p1 + 6*p0*t - 12*p1*t + 6*p2*t + 3*p3*t_squared - 3*p0*t_squared + 9*p1*t_squared - 9*p2*t_squared; | 0 |
286 | } | - |
287 | | - |
288 | qreal static inline _cbrt(qreal d) | - |
289 | { | - |
290 | qreal sign = 1; | - |
291 | if (d < 0) evaluated: d < 0 yes Evaluation Count:14 | yes Evaluation Count:10 |
| 10-14 |
292 | sign = -1; executed: sign = -1; Execution Count:14 | 14 |
293 | d = d * sign; | - |
294 | | - |
295 | qreal t_i = _fast_cbrt(d); | - |
296 | | - |
297 | | - |
298 | const qreal t_i_cubic = t_i * t_i * t_i; | - |
299 | qreal t = t_i * (t_i_cubic + d + d) / (t_i_cubic + t_i_cubic + d); | - |
300 | | - |
301 | | - |
302 | | - |
303 | | - |
304 | | - |
305 | | - |
306 | return t * sign; executed: return t * sign; Execution Count:24 | 24 |
307 | } | - |
308 | | - |
309 | float static inline _fast_cbrt(float x) | - |
310 | { | - |
311 | union { | - |
312 | float f; | - |
313 | quint32 i; | - |
314 | } ux; | - |
315 | | - |
316 | const unsigned int B1 = 709921077; | - |
317 | | - |
318 | ux.f = x; | - |
319 | ux.i = (ux.i / 3 + B1); | - |
320 | | - |
321 | return ux.f; never executed: return ux.f; | 0 |
322 | } | - |
323 | | - |
324 | double static inline _fast_cbrt(double d) | - |
325 | { | - |
326 | union { | - |
327 | double d; | - |
328 | quint32 pt[2]; | - |
329 | } ut, ux; | - |
330 | | - |
331 | const unsigned int B1 = 715094163; | - |
332 | | - |
333 | | - |
334 | const int h0 = 1; | - |
335 | | - |
336 | | - |
337 | | - |
338 | ut.d = 0.0; | - |
339 | ux.d = d; | - |
340 | | - |
341 | quint32 hx = ux.pt[h0]; | - |
342 | ut.pt[h0] = hx / 3 + B1; | - |
343 | | - |
344 | return ut.d; executed: return ut.d; Execution Count:24 | 24 |
345 | } | - |
346 | | - |
347 | qreal static inline _acos(qreal x) | - |
348 | { | - |
349 | return sqrt(1-x)*(1.5707963267948966192313216916398f + x*(-0.213300989f + x*(0.077980478f + x*-0.02164095f))); never executed: return sqrt(1-x)*(1.5707963267948966192313216916398f + x*(-0.213300989f + x*(0.077980478f + x*-0.02164095f))); | 0 |
350 | } | - |
351 | | - |
352 | qreal static inline _cos(qreal x) | - |
353 | { | - |
354 | const qreal pi_times2 = 2 * 3.14159265358979323846; | - |
355 | const qreal pi_neg = -1 * 3.14159265358979323846; | - |
356 | const qreal pi_by2 = 3.14159265358979323846 / 2.0; | - |
357 | | - |
358 | x += pi_by2; | - |
359 | | - |
360 | if (x < pi_neg) never evaluated: x < pi_neg | 0 |
361 | x += pi_times2; never executed: x += pi_times2; | 0 |
362 | else if (x > 3.14159265358979323846) never evaluated: x > 3.14159265358979323846 | 0 |
363 | x -= pi_times2; never executed: x -= pi_times2; | 0 |
364 | | - |
365 | const qreal a = 0.405284735; | - |
366 | const qreal b = 1.27323954; | - |
367 | | - |
368 | const qreal x_squared = x * x; | - |
369 | | - |
370 | if (x < 0) { | 0 |
371 | qreal cos = b * x + a * x_squared; | - |
372 | | - |
373 | if (cos < 0) | 0 |
374 | return 0.225 * (cos * -1 * cos - cos) + cos; never executed: return 0.225 * (cos * -1 * cos - cos) + cos; | 0 |
375 | return 0.225 * (cos * cos - cos) + cos; never executed: return 0.225 * (cos * cos - cos) + cos; | 0 |
376 | } | - |
377 | | - |
378 | qreal cos = b * x - a * x_squared; | - |
379 | | - |
380 | if (cos < 0) | 0 |
381 | return 0.225 * (cos * 1 *-cos - cos) + cos; never executed: return 0.225 * (cos * 1 *-cos - cos) + cos; | 0 |
382 | return 0.225 * (cos * cos - cos) + cos; never executed: return 0.225 * (cos * cos - cos) + cos; | 0 |
383 | } | - |
384 | | - |
385 | bool static inline inRange(qreal f) | - |
386 | { | - |
387 | return (f >= -0.01 && f <= 1.01); executed: return (f >= -0.01 && f <= 1.01); Execution Count:40 | 40 |
388 | } | - |
389 | | - |
390 | void static inline cosacos(qreal x, qreal &s1, qreal &s2, qreal &s3 ) | - |
391 | { | - |
392 | | - |
393 | | - |
394 | | - |
395 | const qreal x_squared = x * x; | - |
396 | const qreal x_plus_one_sqrt = sqrt(1.0 + x); | - |
397 | const qreal one_minus_x_sqrt = sqrt(1.0 - x); | - |
398 | | - |
399 | | - |
400 | | - |
401 | s1 = 0.463614 - 0.0347815 * x + 0.00218245 * x_squared + 0.402421 * x_plus_one_sqrt; | - |
402 | | - |
403 | | - |
404 | | - |
405 | s3 = 0.463614 + 0.402421 * one_minus_x_sqrt + 0.0347815 * x + 0.00218245 * x_squared; | - |
406 | | - |
407 | | - |
408 | | - |
409 | s2 = -0.401644 * one_minus_x_sqrt - 0.0686804 * x + 0.401644 * x_plus_one_sqrt; | - |
410 | } executed: } Execution Count:28 | 28 |
411 | | - |
412 | qreal static inline singleRealSolutionForCubic(qreal a, qreal b, qreal c) | - |
413 | { | - |
414 | | - |
415 | | - |
416 | | - |
417 | | - |
418 | | - |
419 | | - |
420 | if (c < 0.000001 && c > -0.000001) evaluated: c < 0.000001 yes Evaluation Count:18 | yes Evaluation Count:29 |
evaluated: c > -0.000001 yes Evaluation Count:7 | yes Evaluation Count:11 |
| 7-29 |
421 | return 0; executed: return 0; Execution Count:7 | 7 |
422 | | - |
423 | const qreal a_by3 = a / 3.0; | - |
424 | | - |
425 | const qreal a_cubic = a * a * a; | - |
426 | | - |
427 | const qreal p = b - a * a_by3; | - |
428 | const qreal q = 2.0 * a_cubic / 27.0 - a * b / 3.0 + c; | - |
429 | | - |
430 | const qreal q_squared = q * q; | - |
431 | const qreal p_cubic = p * p * p; | - |
432 | const qreal D = 0.25 * q_squared + p_cubic / 27.0; | - |
433 | | - |
434 | if (D >= 0) { evaluated: D >= 0 yes Evaluation Count:12 | yes Evaluation Count:28 |
| 12-28 |
435 | const qreal D_sqrt = sqrt(D); | - |
436 | qreal u = _cbrt( -q * 0.5 + D_sqrt); | - |
437 | qreal v = _cbrt( -q * 0.5 - D_sqrt); | - |
438 | qreal z1 = u + v; | - |
439 | | - |
440 | qreal t1 = z1 - a_by3; | - |
441 | | - |
442 | if (inRange(t1)) evaluated: inRange(t1) yes Evaluation Count:11 | yes Evaluation Count:1 |
| 1-11 |
443 | return t1; executed: return t1; Execution Count:11 | 11 |
444 | qreal z2 = -1 *u; | - |
445 | qreal t2 = z2 - a_by3; | - |
446 | return t2; executed: return t2; Execution Count:1 | 1 |
447 | } | - |
448 | | - |
449 | | - |
450 | const qreal p_minus_sqrt = sqrt(-p); | - |
451 | | - |
452 | | - |
453 | const qreal f = sqrt(4.0 / 3.0) * p_minus_sqrt; | - |
454 | | - |
455 | | - |
456 | const qreal sqrtP = -3.0*sqrt(3.0) / (p_minus_sqrt * p); | - |
457 | | - |
458 | | - |
459 | const qreal g = -q * 0.5 * sqrtP; | - |
460 | | - |
461 | qreal s1; | - |
462 | qreal s2; | - |
463 | qreal s3; | - |
464 | | - |
465 | cosacos(g, s1, s2, s3); | - |
466 | | - |
467 | qreal z1 = -1* f * s2; | - |
468 | qreal t1 = z1 - a_by3; | - |
469 | if (inRange(t1)) partially evaluated: inRange(t1) yes Evaluation Count:28 | no Evaluation Count:0 |
| 0-28 |
470 | return t1; executed: return t1; Execution Count:28 | 28 |
471 | | - |
472 | qreal z2 = f * s1; | - |
473 | qreal t2 = z2 - a_by3; | - |
474 | if (inRange(t2)) never evaluated: inRange(t2) | 0 |
475 | return t2; never executed: return t2; | 0 |
476 | | - |
477 | qreal z3 = -1 * f * s3; | - |
478 | qreal t3 = z3 - a_by3; | - |
479 | return t3; never executed: return t3; | 0 |
480 | } | - |
481 | | - |
482 | qreal static inline findTForX(const SingleCubicBezier &singleCubicBezier, qreal x) | - |
483 | { | - |
484 | const qreal p0 = singleCubicBezier.p0x; | - |
485 | const qreal p1 = singleCubicBezier.p1x; | - |
486 | const qreal p2 = singleCubicBezier.p2x; | - |
487 | const qreal p3 = singleCubicBezier.p3x; | - |
488 | | - |
489 | const qreal factorT3 = p3 - p0 + 3 * p1 - 3 * p2; | - |
490 | const qreal factorT2 = 3 * p0 - 6 * p1 + 3 * p2; | - |
491 | const qreal factorT1 = -3 * p0 + 3 * p1; | - |
492 | const qreal factorT0 = p0 - x; | - |
493 | | - |
494 | const qreal a = factorT2 / factorT3; | - |
495 | const qreal b = factorT1 / factorT3; | - |
496 | const qreal c = factorT0 / factorT3; | - |
497 | | - |
498 | return singleRealSolutionForCubic(a, b, c); executed: return singleRealSolutionForCubic(a, b, c); Execution Count:47 | 47 |
499 | | - |
500 | | - |
501 | | - |
502 | } | - |
503 | }; | - |
504 | | - |
505 | struct TCBEase : public BezierEase | - |
506 | { | - |
507 | qreal value(qreal x) | - |
508 | { | - |
509 | qt_noop(); | - |
510 | | - |
511 | if (_bezierCurves.isEmpty()) { partially evaluated: _bezierCurves.isEmpty() no Evaluation Count:0 | yes Evaluation Count:28 |
| 0-28 |
512 | QMessageLogger("tools/qeasingcurve.cpp", 828, __PRETTY_FUNCTION__).warning("QEasingCurve: Invalid tcb curve"); | - |
513 | return x; never executed: return x; | 0 |
514 | } | - |
515 | | - |
516 | return BezierEase::value(x); executed: return BezierEase::value(x); Execution Count:28 | 28 |
517 | } | - |
518 | | - |
519 | }; | - |
520 | | - |
521 | struct ElasticEase : public QEasingCurveFunction | - |
522 | { | - |
523 | ElasticEase(Type type) | - |
524 | : QEasingCurveFunction(type, qreal(0.3), qreal(1.0)) | - |
525 | { } executed: } Execution Count:39 | 39 |
526 | | - |
527 | QEasingCurveFunction *copy() const | - |
528 | { | - |
529 | ElasticEase *rv = new ElasticEase(_t); | - |
530 | rv->_p = _p; | - |
531 | rv->_a = _a; | - |
532 | rv->_bezierCurves = _bezierCurves; | - |
533 | rv->_tcbPoints = _tcbPoints; | - |
534 | return rv; executed: return rv; Execution Count:4 | 4 |
535 | } | - |
536 | | - |
537 | qreal value(qreal t) | - |
538 | { | - |
539 | qreal p = (_p < 0) ? qreal(0.3) : _p; partially evaluated: (_p < 0) no Evaluation Count:0 | yes Evaluation Count:44 |
| 0-44 |
540 | qreal a = (_a < 0) ? qreal(1.0) : _a; partially evaluated: (_a < 0) no Evaluation Count:0 | yes Evaluation Count:44 |
| 0-44 |
541 | switch(_t) { | - |
542 | case In: | - |
543 | return easeInElastic(t, a, p); executed: return easeInElastic(t, a, p); Execution Count:11 | 11 |
544 | case Out: | - |
545 | return easeOutElastic(t, a, p); executed: return easeOutElastic(t, a, p); Execution Count:11 | 11 |
546 | case InOut: | - |
547 | return easeInOutElastic(t, a, p); executed: return easeInOutElastic(t, a, p); Execution Count:11 | 11 |
548 | case OutIn: | - |
549 | return easeOutInElastic(t, a, p); executed: return easeOutInElastic(t, a, p); Execution Count:11 | 11 |
550 | default: | - |
551 | return t; never executed: return t; | 0 |
552 | } | - |
553 | } | 0 |
554 | }; | - |
555 | | - |
556 | struct BounceEase : public QEasingCurveFunction | - |
557 | { | - |
558 | BounceEase(Type type) | - |
559 | : QEasingCurveFunction(type, qreal(0.3), qreal(1.0)) | - |
560 | { } executed: } Execution Count:5 | 5 |
561 | | - |
562 | QEasingCurveFunction *copy() const | - |
563 | { | - |
564 | BounceEase *rv = new BounceEase(_t); | - |
565 | rv->_a = _a; | - |
566 | rv->_bezierCurves = _bezierCurves; | - |
567 | rv->_tcbPoints = _tcbPoints; | - |
568 | return rv; never executed: return rv; | 0 |
569 | } | - |
570 | | - |
571 | qreal value(qreal t) | - |
572 | { | - |
573 | qreal a = (_a < 0) ? qreal(1.0) : _a; partially evaluated: (_a < 0) no Evaluation Count:0 | yes Evaluation Count:44 |
| 0-44 |
574 | switch(_t) { | - |
575 | case In: | - |
576 | return easeInBounce(t, a); executed: return easeInBounce(t, a); Execution Count:11 | 11 |
577 | case Out: | - |
578 | return easeOutBounce(t, a); executed: return easeOutBounce(t, a); Execution Count:11 | 11 |
579 | case InOut: | - |
580 | return easeInOutBounce(t, a); executed: return easeInOutBounce(t, a); Execution Count:11 | 11 |
581 | case OutIn: | - |
582 | return easeOutInBounce(t, a); executed: return easeOutInBounce(t, a); Execution Count:11 | 11 |
583 | default: | - |
584 | return t; never executed: return t; | 0 |
585 | } | - |
586 | } | 0 |
587 | }; | - |
588 | | - |
589 | struct BackEase : public QEasingCurveFunction | - |
590 | { | - |
591 | BackEase(Type type) | - |
592 | : QEasingCurveFunction(type, qreal(0.3), qreal(1.0), qreal(1.70158)) | - |
593 | { } executed: } Execution Count:60 | 60 |
594 | | - |
595 | QEasingCurveFunction *copy() const | - |
596 | { | - |
597 | BackEase *rv = new BackEase(_t); | - |
598 | rv->_o = _o; | - |
599 | rv->_bezierCurves = _bezierCurves; | - |
600 | rv->_tcbPoints = _tcbPoints; | - |
601 | return rv; executed: return rv; Execution Count:5 | 5 |
602 | } | - |
603 | | - |
604 | qreal value(qreal t) | - |
605 | { | - |
606 | qreal o = (_o < 0) ? qreal(1.70158) : _o; partially evaluated: (_o < 0) no Evaluation Count:0 | yes Evaluation Count:44 |
| 0-44 |
607 | switch(_t) { | - |
608 | case In: | - |
609 | return easeInBack(t, o); executed: return easeInBack(t, o); Execution Count:11 | 11 |
610 | case Out: | - |
611 | return easeOutBack(t, o); executed: return easeOutBack(t, o); Execution Count:11 | 11 |
612 | case InOut: | - |
613 | return easeInOutBack(t, o); executed: return easeInOutBack(t, o); Execution Count:11 | 11 |
614 | case OutIn: | - |
615 | return easeOutInBack(t, o); executed: return easeOutInBack(t, o); Execution Count:11 | 11 |
616 | default: | - |
617 | return t; never executed: return t; | 0 |
618 | } | - |
619 | } | 0 |
620 | }; | - |
621 | | - |
622 | static QEasingCurve::EasingFunction curveToFunc(QEasingCurve::Type curve) | - |
623 | { | - |
624 | switch(curve) { | - |
625 | case QEasingCurve::Linear: | - |
626 | return &easeNone; executed: return &easeNone; Execution Count:2 | 2 |
627 | case QEasingCurve::InQuad: | - |
628 | return &easeInQuad; executed: return &easeInQuad; Execution Count:5 | 5 |
629 | case QEasingCurve::OutQuad: | - |
630 | return &easeOutQuad; executed: return &easeOutQuad; Execution Count:13 | 13 |
631 | case QEasingCurve::InOutQuad: | - |
632 | return &easeInOutQuad; executed: return &easeInOutQuad; Execution Count:952 | 952 |
633 | case QEasingCurve::OutInQuad: | - |
634 | return &easeOutInQuad; executed: return &easeOutInQuad; Execution Count:1 | 1 |
635 | case QEasingCurve::InCubic: | - |
636 | return &easeInCubic; executed: return &easeInCubic; Execution Count:2 | 2 |
637 | case QEasingCurve::OutCubic: | - |
638 | return &easeOutCubic; executed: return &easeOutCubic; Execution Count:19 | 19 |
639 | case QEasingCurve::InOutCubic: | - |
640 | return &easeInOutCubic; executed: return &easeInOutCubic; Execution Count:1 | 1 |
641 | case QEasingCurve::OutInCubic: | - |
642 | return &easeOutInCubic; executed: return &easeOutInCubic; Execution Count:1 | 1 |
643 | case QEasingCurve::InQuart: | - |
644 | return &easeInQuart; executed: return &easeInQuart; Execution Count:1 | 1 |
645 | case QEasingCurve::OutQuart: | - |
646 | return &easeOutQuart; executed: return &easeOutQuart; Execution Count:2 | 2 |
647 | case QEasingCurve::InOutQuart: | - |
648 | return &easeInOutQuart; executed: return &easeInOutQuart; Execution Count:1 | 1 |
649 | case QEasingCurve::OutInQuart: | - |
650 | return &easeOutInQuart; executed: return &easeOutInQuart; Execution Count:1 | 1 |
651 | case QEasingCurve::InQuint: | - |
652 | return &easeInQuint; executed: return &easeInQuint; Execution Count:1 | 1 |
653 | case QEasingCurve::OutQuint: | - |
654 | return &easeOutQuint; executed: return &easeOutQuint; Execution Count:1 | 1 |
655 | case QEasingCurve::InOutQuint: | - |
656 | return &easeInOutQuint; executed: return &easeInOutQuint; Execution Count:1 | 1 |
657 | case QEasingCurve::OutInQuint: | - |
658 | return &easeOutInQuint; executed: return &easeOutInQuint; Execution Count:1 | 1 |
659 | case QEasingCurve::InSine: | - |
660 | return &easeInSine; executed: return &easeInSine; Execution Count:1 | 1 |
661 | case QEasingCurve::OutSine: | - |
662 | return &easeOutSine; executed: return &easeOutSine; Execution Count:1 | 1 |
663 | case QEasingCurve::InOutSine: | - |
664 | return &easeInOutSine; executed: return &easeInOutSine; Execution Count:47 | 47 |
665 | case QEasingCurve::OutInSine: | - |
666 | return &easeOutInSine; executed: return &easeOutInSine; Execution Count:1 | 1 |
667 | case QEasingCurve::InExpo: | - |
668 | return &easeInExpo; executed: return &easeInExpo; Execution Count:1 | 1 |
669 | case QEasingCurve::OutExpo: | - |
670 | return &easeOutExpo; executed: return &easeOutExpo; Execution Count:1 | 1 |
671 | case QEasingCurve::InOutExpo: | - |
672 | return &easeInOutExpo; executed: return &easeInOutExpo; Execution Count:1 | 1 |
673 | case QEasingCurve::OutInExpo: | - |
674 | return &easeOutInExpo; executed: return &easeOutInExpo; Execution Count:1 | 1 |
675 | case QEasingCurve::InCirc: | - |
676 | return &easeInCirc; executed: return &easeInCirc; Execution Count:1 | 1 |
677 | case QEasingCurve::OutCirc: | - |
678 | return &easeOutCirc; executed: return &easeOutCirc; Execution Count:1 | 1 |
679 | case QEasingCurve::InOutCirc: | - |
680 | return &easeInOutCirc; executed: return &easeInOutCirc; Execution Count:1 | 1 |
681 | case QEasingCurve::OutInCirc: | - |
682 | return &easeOutInCirc; executed: return &easeOutInCirc; Execution Count:1 | 1 |
683 | | - |
684 | case QEasingCurve::InCurve: | - |
685 | return &easeInCurve; executed: return &easeInCurve; Execution Count:1 | 1 |
686 | case QEasingCurve::OutCurve: | - |
687 | return &easeOutCurve; executed: return &easeOutCurve; Execution Count:19 | 19 |
688 | case QEasingCurve::SineCurve: | - |
689 | return &easeSineCurve; executed: return &easeSineCurve; Execution Count:3 | 3 |
690 | case QEasingCurve::CosineCurve: | - |
691 | return &easeCosineCurve; executed: return &easeCosineCurve; Execution Count:3 | 3 |
692 | default: | - |
693 | return 0; never executed: return 0; | 0 |
694 | }; | - |
695 | } | 0 |
696 | | - |
697 | static QEasingCurveFunction *curveToFunctionObject(QEasingCurve::Type type) | - |
698 | { | - |
699 | QEasingCurveFunction *curveFunc = 0; | - |
700 | switch(type) { | - |
701 | case QEasingCurve::InElastic: | - |
702 | curveFunc = new ElasticEase(ElasticEase::In); | - |
703 | break; executed: break; Execution Count:6 | 6 |
704 | case QEasingCurve::OutElastic: | - |
705 | curveFunc = new ElasticEase(ElasticEase::Out); | - |
706 | break; executed: break; Execution Count:1 | 1 |
707 | case QEasingCurve::InOutElastic: | - |
708 | curveFunc = new ElasticEase(ElasticEase::InOut); | - |
709 | break; executed: break; Execution Count:27 | 27 |
710 | case QEasingCurve::OutInElastic: | - |
711 | curveFunc = new ElasticEase(ElasticEase::OutIn); | - |
712 | break; executed: break; Execution Count:1 | 1 |
713 | case QEasingCurve::OutBounce: | - |
714 | curveFunc = new BounceEase(BounceEase::Out); | - |
715 | break; executed: break; Execution Count:1 | 1 |
716 | case QEasingCurve::InBounce: | - |
717 | curveFunc = new BounceEase(BounceEase::In); | - |
718 | break; executed: break; Execution Count:2 | 2 |
719 | case QEasingCurve::OutInBounce: | - |
720 | curveFunc = new BounceEase(BounceEase::OutIn); | - |
721 | break; executed: break; Execution Count:1 | 1 |
722 | case QEasingCurve::InOutBounce: | - |
723 | curveFunc = new BounceEase(BounceEase::InOut); | - |
724 | break; executed: break; Execution Count:1 | 1 |
725 | case QEasingCurve::InBack: | - |
726 | curveFunc = new BackEase(BackEase::In); | - |
727 | break; executed: break; Execution Count:3 | 3 |
728 | case QEasingCurve::OutBack: | - |
729 | curveFunc = new BackEase(BackEase::Out); | - |
730 | break; executed: break; Execution Count:1 | 1 |
731 | case QEasingCurve::InOutBack: | - |
732 | curveFunc = new BackEase(BackEase::InOut); | - |
733 | break; executed: break; Execution Count:26 | 26 |
734 | case QEasingCurve::OutInBack: | - |
735 | curveFunc = new BackEase(BackEase::OutIn); | - |
736 | break; executed: break; Execution Count:25 | 25 |
737 | case QEasingCurve::BezierSpline: | - |
738 | curveFunc = new BezierEase(); | - |
739 | break; executed: break; Execution Count:3 | 3 |
740 | case QEasingCurve::TCBSpline: | - |
741 | curveFunc = new TCBEase(); | - |
742 | break; executed: break; Execution Count:4 | 4 |
743 | default: | - |
744 | curveFunc = new QEasingCurveFunction(QEasingCurveFunction::In, qreal(0.3), qreal(1.0), qreal(1.70158)); | - |
745 | } executed: } Execution Count:7 | 7 |
746 | | - |
747 | return curveFunc; executed: return curveFunc; Execution Count:109 | 109 |
748 | } | - |
749 | | - |
750 | | - |
751 | | - |
752 | | - |
753 | QEasingCurve::QEasingCurve(Type type) | - |
754 | : d_ptr(new QEasingCurvePrivate) | - |
755 | { | - |
756 | setType(type); | - |
757 | } executed: } Execution Count:2554 | 2554 |
758 | | - |
759 | | - |
760 | | - |
761 | | - |
762 | QEasingCurve::QEasingCurve(const QEasingCurve &other) | - |
763 | : d_ptr(new QEasingCurvePrivate(*other.d_ptr)) | - |
764 | { | - |
765 | | - |
766 | } executed: } Execution Count:1239 | 1239 |
767 | | - |
768 | | - |
769 | | - |
770 | | - |
771 | | - |
772 | QEasingCurve::~QEasingCurve() | - |
773 | { | - |
774 | delete d_ptr; | - |
775 | } executed: } Execution Count:3681 | 3681 |
776 | bool QEasingCurve::operator==(const QEasingCurve &other) const | - |
777 | { | - |
778 | bool res = d_ptr->func == other.d_ptr->func partially evaluated: d_ptr->func == other.d_ptr->func yes Evaluation Count:73 | no Evaluation Count:0 |
| 0-73 |
779 | && d_ptr->type == other.d_ptr->type; evaluated: d_ptr->type == other.d_ptr->type yes Evaluation Count:72 | yes Evaluation Count:1 |
| 1-72 |
780 | if (res) { evaluated: res yes Evaluation Count:72 | yes Evaluation Count:1 |
| 1-72 |
781 | if (d_ptr->config && other.d_ptr->config) { evaluated: d_ptr->config yes Evaluation Count:27 | yes Evaluation Count:45 |
partially evaluated: other.d_ptr->config yes Evaluation Count:27 | no Evaluation Count:0 |
| 0-45 |
782 | | - |
783 | res = d_ptr->config->operator==(*(other.d_ptr->config)); | - |
784 | | - |
785 | } else if (d_ptr->config || other.d_ptr->config) { executed: } Execution Count:27 partially evaluated: d_ptr->config no Evaluation Count:0 | yes Evaluation Count:45 |
evaluated: other.d_ptr->config yes Evaluation Count:2 | yes Evaluation Count:43 |
| 0-45 |
786 | | - |
787 | res = qFuzzyCompare(amplitude(), other.amplitude()) && evaluated: qFuzzyCompare(amplitude(), other.amplitude()) yes Evaluation Count:1 | yes Evaluation Count:1 |
| 1 |
788 | qFuzzyCompare(period(), other.period()) && partially evaluated: qFuzzyCompare(period(), other.period()) yes Evaluation Count:1 | no Evaluation Count:0 |
| 0-1 |
789 | qFuzzyCompare(overshoot(), other.overshoot()); partially evaluated: qFuzzyCompare(overshoot(), other.overshoot()) yes Evaluation Count:1 | no Evaluation Count:0 |
| 0-1 |
790 | } executed: } Execution Count:2 | 2 |
791 | } | - |
792 | return res; executed: return res; Execution Count:73 | 73 |
793 | } | - |
794 | qreal QEasingCurve::amplitude() const | - |
795 | { | - |
796 | return d_ptr->config ? d_ptr->config->_a : qreal(1.0); executed: return d_ptr->config ? d_ptr->config->_a : qreal(1.0); Execution Count:19 | 19 |
797 | } | - |
798 | void QEasingCurve::setAmplitude(qreal amplitude) | - |
799 | { | - |
800 | if (!d_ptr->config) evaluated: !d_ptr->config yes Evaluation Count:2 | yes Evaluation Count:15 |
| 2-15 |
801 | d_ptr->config = curveToFunctionObject(d_ptr->type); executed: d_ptr->config = curveToFunctionObject(d_ptr->type); Execution Count:2 | 2 |
802 | d_ptr->config->_a = amplitude; | - |
803 | } executed: } Execution Count:17 | 17 |
804 | | - |
805 | | - |
806 | | - |
807 | | - |
808 | | - |
809 | | - |
810 | qreal QEasingCurve::period() const | - |
811 | { | - |
812 | return d_ptr->config ? d_ptr->config->_p : qreal(0.3); executed: return d_ptr->config ? d_ptr->config->_p : qreal(0.3); Execution Count:16 | 16 |
813 | } | - |
814 | void QEasingCurve::setPeriod(qreal period) | - |
815 | { | - |
816 | if (!d_ptr->config) evaluated: !d_ptr->config yes Evaluation Count:1 | yes Evaluation Count:13 |
| 1-13 |
817 | d_ptr->config = curveToFunctionObject(d_ptr->type); executed: d_ptr->config = curveToFunctionObject(d_ptr->type); Execution Count:1 | 1 |
818 | d_ptr->config->_p = period; | - |
819 | } executed: } Execution Count:14 | 14 |
820 | | - |
821 | | - |
822 | | - |
823 | | - |
824 | | - |
825 | | - |
826 | qreal QEasingCurve::overshoot() const | - |
827 | { | - |
828 | return d_ptr->config ? d_ptr->config->_o : qreal(1.70158) ; executed: return d_ptr->config ? d_ptr->config->_o : qreal(1.70158) ; Execution Count:17 | 17 |
829 | } | - |
830 | void QEasingCurve::setOvershoot(qreal overshoot) | - |
831 | { | - |
832 | if (!d_ptr->config) partially evaluated: !d_ptr->config no Evaluation Count:0 | yes Evaluation Count:17 |
| 0-17 |
833 | d_ptr->config = curveToFunctionObject(d_ptr->type); never executed: d_ptr->config = curveToFunctionObject(d_ptr->type); | 0 |
834 | d_ptr->config->_o = overshoot; | - |
835 | } executed: } Execution Count:17 | 17 |
836 | | - |
837 | | - |
838 | | - |
839 | | - |
840 | | - |
841 | | - |
842 | | - |
843 | void QEasingCurve::addCubicBezierSegment(const QPointF & c1, const QPointF & c2, const QPointF & endPoint) | - |
844 | { | - |
845 | if (!d_ptr->config) partially evaluated: !d_ptr->config no Evaluation Count:0 | yes Evaluation Count:11 |
| 0-11 |
846 | d_ptr->config = curveToFunctionObject(d_ptr->type); never executed: d_ptr->config = curveToFunctionObject(d_ptr->type); | 0 |
847 | d_ptr->config->_bezierCurves << c1 << c2 << endPoint; | - |
848 | } executed: } Execution Count:11 | 11 |
849 | | - |
850 | QVector<QPointF> static inline tcbToBezier(const TCBPoints &tcbPoints) | - |
851 | { | - |
852 | const int count = tcbPoints.count(); | - |
853 | QVector<QPointF> bezierPoints; | - |
854 | | - |
855 | for (int i = 1; i < count; i++) { evaluated: i < count yes Evaluation Count:8 | yes Evaluation Count:4 |
| 4-8 |
856 | const qreal t_0 = tcbPoints.at(i - 1)._t; | - |
857 | const qreal c_0 = tcbPoints.at(i - 1)._c; | - |
858 | qreal b_0 = -1; | - |
859 | | - |
860 | qreal const t_1 = tcbPoints.at(i)._t; | - |
861 | qreal const c_1 = tcbPoints.at(i)._c; | - |
862 | qreal b_1 = 1; | - |
863 | | - |
864 | QPointF c_minusOne; | - |
865 | const QPointF c0(tcbPoints.at(i - 1)._point); | - |
866 | const QPointF c3(tcbPoints.at(i)._point); | - |
867 | QPointF c4; | - |
868 | | - |
869 | if (i > 1) { evaluated: i > 1 yes Evaluation Count:4 | yes Evaluation Count:4 |
| 4 |
870 | c_minusOne = tcbPoints.at(i - 2)._point; | - |
871 | b_0 = tcbPoints.at(i - 1)._b; | - |
872 | } executed: } Execution Count:4 | 4 |
873 | | - |
874 | if (i < (count - 1)) { evaluated: i < (count - 1) yes Evaluation Count:4 | yes Evaluation Count:4 |
| 4 |
875 | c4 = tcbPoints.at(i + 1)._point; | - |
876 | b_1 = tcbPoints.at(i)._b; | - |
877 | } executed: } Execution Count:4 | 4 |
878 | | - |
879 | const qreal dx_0 = 0.5 * (1-t_0) * ((1 + b_0) * (1 + c_0) * (c0.x() - c_minusOne.x()) + (1- b_0) * (1 - c_0) * (c3.x() - c0.x())); | - |
880 | const qreal dy_0 = 0.5 * (1-t_0) * ((1 + b_0) * (1 + c_0) * (c0.y() - c_minusOne.y()) + (1- b_0) * (1 - c_0) * (c3.y() - c0.y())); | - |
881 | | - |
882 | const qreal dx_1 = 0.5 * (1-t_1) * ((1 + b_1) * (1 - c_1) * (c3.x() - c0.x()) + (1 - b_1) * (1 + c_1) * (c4.x() - c3.x())); | - |
883 | const qreal dy_1 = 0.5 * (1-t_1) * ((1 + b_1) * (1 - c_1) * (c3.y() - c0.y()) + (1 - b_1) * (1 + c_1) * (c4.y() - c3.y())); | - |
884 | | - |
885 | const QPointF d_0 = QPointF(dx_0, dy_0); | - |
886 | const QPointF d_1 = QPointF(dx_1, dy_1); | - |
887 | | - |
888 | QPointF c1 = (3 * c0 + d_0) / 3; | - |
889 | QPointF c2 = (3 * c3 - d_1) / 3; | - |
890 | bezierPoints << c1 << c2 << c3; | - |
891 | } executed: } Execution Count:8 | 8 |
892 | return bezierPoints; executed: return bezierPoints; Execution Count:4 | 4 |
893 | } | - |
894 | void QEasingCurve::addTCBSegment(const QPointF &nextPoint, qreal t, qreal c, qreal b) | - |
895 | { | - |
896 | if (!d_ptr->config) partially evaluated: !d_ptr->config no Evaluation Count:0 | yes Evaluation Count:12 |
| 0-12 |
897 | d_ptr->config = curveToFunctionObject(d_ptr->type); never executed: d_ptr->config = curveToFunctionObject(d_ptr->type); | 0 |
898 | | - |
899 | d_ptr->config->_tcbPoints.append(TCBPoint(nextPoint, t, c ,b)); | - |
900 | | - |
901 | if (nextPoint == QPointF(1.0, 1.0)) { evaluated: nextPoint == QPointF(1.0, 1.0) yes Evaluation Count:4 | yes Evaluation Count:8 |
| 4-8 |
902 | d_ptr->config->_bezierCurves = tcbToBezier(d_ptr->config->_tcbPoints); | - |
903 | d_ptr->config->_tcbPoints.clear(); | - |
904 | } executed: } Execution Count:4 | 4 |
905 | | - |
906 | } executed: } Execution Count:12 | 12 |
907 | QVector<QPointF> QEasingCurve::toCubicSpline() const | - |
908 | { | - |
909 | return d_ptr->config ? d_ptr->config->_bezierCurves : QVector<QPointF>(); never executed: return d_ptr->config ? d_ptr->config->_bezierCurves : QVector<QPointF>(); | 0 |
910 | } | - |
911 | | - |
912 | | - |
913 | | - |
914 | | - |
915 | QEasingCurve::Type QEasingCurve::type() const | - |
916 | { | - |
917 | return d_ptr->type; executed: return d_ptr->type; Execution Count:36 | 36 |
918 | } | - |
919 | | - |
920 | void QEasingCurvePrivate::setType_helper(QEasingCurve::Type newType) | - |
921 | { | - |
922 | qreal amp = -1.0; | - |
923 | qreal period = -1.0; | - |
924 | qreal overshoot = -1.0; | - |
925 | QVector<QPointF> bezierCurves; | - |
926 | QVector<TCBPoint> tcbPoints; | - |
927 | | - |
928 | if (config) { evaluated: config yes Evaluation Count:9 | yes Evaluation Count:1175 |
| 9-1175 |
929 | amp = config->_a; | - |
930 | period = config->_p; | - |
931 | overshoot = config->_o; | - |
932 | bezierCurves = config->_bezierCurves; | - |
933 | tcbPoints = config->_tcbPoints; | - |
934 | | - |
935 | delete config; | - |
936 | config = 0; | - |
937 | } executed: } Execution Count:9 | 9 |
938 | | - |
939 | if (isConfigFunction(newType) || (amp != -1.0) || (period != -1.0) || (overshoot != -1.0) || evaluated: isConfigFunction(newType) yes Evaluation Count:84 | yes Evaluation Count:1100 |
evaluated: (amp != -1.0) yes Evaluation Count:4 | yes Evaluation Count:1096 |
partially evaluated: (period != -1.0) no Evaluation Count:0 | yes Evaluation Count:1096 |
partially evaluated: (overshoot != -1.0) no Evaluation Count:0 | yes Evaluation Count:1096 |
| 0-1100 |
940 | !bezierCurves.isEmpty()) { partially evaluated: !bezierCurves.isEmpty() no Evaluation Count:0 | yes Evaluation Count:1096 |
| 0-1096 |
941 | config = curveToFunctionObject(newType); | - |
942 | if (amp != -1.0) evaluated: amp != -1.0 yes Evaluation Count:9 | yes Evaluation Count:79 |
| 9-79 |
943 | config->_a = amp; executed: config->_a = amp; Execution Count:9 | 9 |
944 | if (period != -1.0) evaluated: period != -1.0 yes Evaluation Count:9 | yes Evaluation Count:79 |
| 9-79 |
945 | config->_p = period; executed: config->_p = period; Execution Count:9 | 9 |
946 | if (overshoot != -1.0) evaluated: overshoot != -1.0 yes Evaluation Count:9 | yes Evaluation Count:79 |
| 9-79 |
947 | config->_o = overshoot; executed: config->_o = overshoot; Execution Count:9 | 9 |
948 | config->_bezierCurves = bezierCurves; | - |
949 | config->_tcbPoints = tcbPoints; | - |
950 | func = 0; | - |
951 | } else if (newType != QEasingCurve::Custom) { executed: } Execution Count:88 evaluated: newType != QEasingCurve::Custom yes Evaluation Count:1089 | yes Evaluation Count:7 |
| 7-1089 |
952 | func = curveToFunc(newType); | - |
953 | } executed: } Execution Count:1089 | 1089 |
954 | qt_noop(); | - |
955 | type = newType; | - |
956 | } executed: } Execution Count:1184 | 1184 |
957 | | - |
958 | | - |
959 | | - |
960 | | - |
961 | void QEasingCurve::setType(Type type) | - |
962 | { | - |
963 | if (d_ptr->type == type) evaluated: d_ptr->type == type yes Evaluation Count:1539 | yes Evaluation Count:1182 |
| 1182-1539 |
964 | return; executed: return; Execution Count:1539 | 1539 |
965 | if (type < Linear || type >= NCurveTypes - 1) { evaluated: type < Linear yes Evaluation Count:2 | yes Evaluation Count:1180 |
evaluated: type >= NCurveTypes - 1 yes Evaluation Count:3 | yes Evaluation Count:1177 |
| 2-1180 |
966 | QMessageLogger("tools/qeasingcurve.cpp", 1364, __PRETTY_FUNCTION__).warning("QEasingCurve: Invalid curve type %d", type); | - |
967 | return; executed: return; Execution Count:5 | 5 |
968 | } | - |
969 | | - |
970 | d_ptr->setType_helper(type); | - |
971 | } executed: } Execution Count:1177 | 1177 |
972 | void QEasingCurve::setCustomType(EasingFunction func) | - |
973 | { | - |
974 | if (!func) { partially evaluated: !func no Evaluation Count:0 | yes Evaluation Count:7 |
| 0-7 |
975 | QMessageLogger("tools/qeasingcurve.cpp", 1385, __PRETTY_FUNCTION__).warning("Function pointer must not be null"); | - |
976 | return; | 0 |
977 | } | - |
978 | d_ptr->func = func; | - |
979 | d_ptr->setType_helper(Custom); | - |
980 | } executed: } Execution Count:7 | 7 |
981 | | - |
982 | | - |
983 | | - |
984 | | - |
985 | | - |
986 | | - |
987 | QEasingCurve::EasingFunction QEasingCurve::customType() const | - |
988 | { | - |
989 | return d_ptr->type == Custom ? d_ptr->func : 0; never executed: return d_ptr->type == Custom ? d_ptr->func : 0; | 0 |
990 | } | - |
991 | | - |
992 | | - |
993 | | - |
994 | | - |
995 | | - |
996 | | - |
997 | | - |
998 | qreal QEasingCurve::valueForProgress(qreal progress) const | - |
999 | { | - |
1000 | progress = qBound<qreal>(0, progress, 1); | - |
1001 | if (d_ptr->func) evaluated: d_ptr->func yes Evaluation Count:11161 | yes Evaluation Count:179 |
| 179-11161 |
1002 | return d_ptr->func(progress); executed: return d_ptr->func(progress); Execution Count:11161 | 11161 |
1003 | else if (d_ptr->config) partially evaluated: d_ptr->config yes Evaluation Count:179 | no Evaluation Count:0 |
| 0-179 |
1004 | return d_ptr->config->value(progress); executed: return d_ptr->config->value(progress); Execution Count:179 | 179 |
1005 | else | - |
1006 | return progress; never executed: return progress; | 0 |
1007 | } | - |
1008 | | - |
1009 | | - |
1010 | QDebug operator<<(QDebug debug, const QEasingCurve &item) | - |
1011 | { | - |
1012 | debug << "type:" << item.d_ptr->type | - |
1013 | << "func:" << item.d_ptr->func; | - |
1014 | if (item.d_ptr->config) { partially evaluated: item.d_ptr->config no Evaluation Count:0 | yes Evaluation Count:1 |
| 0-1 |
1015 | debug << QString::fromLatin1("period:%1").arg(item.d_ptr->config->_p, 0, 'f', 20) | - |
1016 | << QString::fromLatin1("amp:%1").arg(item.d_ptr->config->_a, 0, 'f', 20) | - |
1017 | << QString::fromLatin1("overshoot:%1").arg(item.d_ptr->config->_o, 0, 'f', 20); | - |
1018 | } | 0 |
1019 | return debug; executed: return debug; Execution Count:1 | 1 |
1020 | } | - |
1021 | QDataStream &operator<<(QDataStream &stream, const QEasingCurve &easing) | - |
1022 | { | - |
1023 | stream << quint8(easing.d_ptr->type); | - |
1024 | stream << quint64(quintptr(easing.d_ptr->func)); | - |
1025 | | - |
1026 | bool hasConfig = easing.d_ptr->config; | - |
1027 | stream << hasConfig; | - |
1028 | if (hasConfig) { evaluated: hasConfig yes Evaluation Count:18 | yes Evaluation Count:31 |
| 18-31 |
1029 | stream << easing.d_ptr->config->_p; | - |
1030 | stream << easing.d_ptr->config->_a; | - |
1031 | stream << easing.d_ptr->config->_o; | - |
1032 | } executed: } Execution Count:18 | 18 |
1033 | return stream; executed: return stream; Execution Count:49 | 49 |
1034 | } | - |
1035 | QDataStream &operator>>(QDataStream &stream, QEasingCurve &easing) | - |
1036 | { | - |
1037 | QEasingCurve::Type type; | - |
1038 | quint8 int_type; | - |
1039 | stream >> int_type; | - |
1040 | type = static_cast<QEasingCurve::Type>(int_type); | - |
1041 | easing.setType(type); | - |
1042 | | - |
1043 | quint64 ptr_func; | - |
1044 | stream >> ptr_func; | - |
1045 | easing.d_ptr->func = QEasingCurve::EasingFunction(quintptr(ptr_func)); | - |
1046 | | - |
1047 | bool hasConfig; | - |
1048 | stream >> hasConfig; | - |
1049 | if (hasConfig) { evaluated: hasConfig yes Evaluation Count:18 | yes Evaluation Count:33 |
| 18-33 |
1050 | QEasingCurveFunction *config = curveToFunctionObject(type); | - |
1051 | stream >> config->_p; | - |
1052 | stream >> config->_a; | - |
1053 | stream >> config->_o; | - |
1054 | easing.d_ptr->config = config; | - |
1055 | } executed: } Execution Count:18 | 18 |
1056 | return stream; executed: return stream; Execution Count:51 | 51 |
1057 | } | - |
1058 | | - |
1059 | | - |
1060 | | - |
1061 | | - |
| | |