OpenCoverage

qquickwander.cpp

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/particles/qquickwander.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2016 The Qt Company Ltd.-
4** Contact: https://www.qt.io/licensing/-
5**-
6** This file is part of the QtQuick 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 The Qt Company. For licensing terms-
14** and conditions see https://www.qt.io/terms-conditions. For further-
15** information use the contact form at https://www.qt.io/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 3 as published by the Free Software-
20** Foundation and appearing in the file LICENSE.LGPL3 included in the-
21** packaging of this file. Please review the following information to-
22** ensure the GNU Lesser General Public License version 3 requirements-
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.-
24**-
25** GNU General Public License Usage-
26** Alternatively, this file may be used under the terms of the GNU-
27** General Public License version 2.0 or (at your option) the GNU General-
28** Public license version 3 or any later version approved by the KDE Free-
29** Qt Foundation. The licenses are as published by the Free Software-
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3-
31** included in the packaging of this file. Please review the following-
32** information to ensure the GNU General Public License requirements will-
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and-
34** https://www.gnu.org/licenses/gpl-3.0.html.-
35**-
36** $QT_END_LICENSE$-
37**-
38****************************************************************************/-
39-
40#include "qquickwander_p.h"-
41#include "qquickparticlesystem_p.h"//for ParticlesVertices-
42#include <QRandomGenerator>-
43QT_BEGIN_NAMESPACE-
44/*!-
45 \qmltype Wander-
46 \instantiates QQuickWanderAffector-
47 \inqmlmodule QtQuick.Particles-
48 \ingroup qtquick-particles-
49 \inherits Affector-
50 \brief For applying random particle trajectory.-
51-
52*/-
53/*!-
54 \qmlproperty real QtQuick.Particles::Wander::pace-
55-
56 Maximum attribute change per second.-
57*/-
58/*!-
59 \qmlproperty real QtQuick.Particles::Wander::xVariance-
60-
61 Maximum attribute x value (as a result of Wander).-
62-
63 If unset, Wander will not affect x values.-
64*/-
65/*!-
66 \qmlproperty real QtQuick.Particles::Wander::yVariance-
67-
68 Maximum attribute y value (as a result of Wander).-
69-
70 If unset, Wander will not affect y values.-
71*/-
72/*!-
73 \qmlproperty AffectableParameter QtQuick.Particles::Wander::affectedParameter-
74-
75 What attribute of particles is directly affected.-
76 \list-
77 \li PointAttractor.Position-
78 \li PointAttractor.Velocity-
79 \li PointAttractor.Acceleration-
80 \endlist-
81*/-
82-
83QQuickWanderAffector::QQuickWanderAffector(QQuickItem *parent) :-
84 QQuickParticleAffector(parent), m_xVariance(0), m_yVariance(0), m_pace(0)-
85 , m_affectedParameter(Velocity)-
86{-
87 m_needsReset = true;-
88}
executed 6 times by 2 tests: end of block
Executed by:
  • tst_examples
  • tst_qquickwander
6
89-
90QQuickWanderAffector::~QQuickWanderAffector()-
91{-
92 for (QHash<int, WanderData*>::const_iterator iter=m_wanderData.constBegin();-
93 iter != m_wanderData.constEnd(); ++iter)
iter != m_wand...ata.constEnd()Description
TRUEnever evaluated
FALSEevaluated 6 times by 2 tests
Evaluated by:
  • tst_examples
  • tst_qquickwander
0-6
94 delete (*iter);
never executed: delete (*iter);
0
95}
executed 6 times by 2 tests: end of block
Executed by:
  • tst_examples
  • tst_qquickwander
6
96-
97WanderData* QQuickWanderAffector::getData(int idx)-
98{-
99 if (m_wanderData.contains(idx))
m_wanderData.contains(idx)Description
TRUEnever evaluated
FALSEnever evaluated
0
100 return m_wanderData[idx];
never executed: return m_wanderData[idx];
0
101 WanderData* d = new WanderData;-
102 d->x_vel = 0;-
103 d->y_vel = 0;-
104 d->x_peak = m_xVariance;-
105 d->y_peak = m_yVariance;-
106 d->x_var = m_pace * QRandomGenerator::global()->generateDouble();-
107 d->y_var = m_pace * QRandomGenerator::global()->generateDouble();-
108-
109 m_wanderData.insert(idx, d);-
110 return d;
never executed: return d;
0
111}-
112-
113// TODO: see below-
114//void QQuickWanderAffector::reset(int systemIdx)-
115//{-
116// if (m_wanderData.contains(systemIdx))-
117// delete m_wanderData[systemIdx];-
118// m_wanderData.remove(systemIdx);-
119//}-
120-
121bool QQuickWanderAffector::affectParticle(QQuickParticleData* data, qreal dt)-
122{-
123 /*TODO: Add a mode which does basically this - picking a direction, going in it (random velocity) and then going back-
124 WanderData* d = getData(data->systemIndex);-
125 if (m_xVariance != 0.) {-
126 if ((d->x_vel > d->x_peak && d->x_var > 0.0) || (d->x_vel < -d->x_peak && d->x_var < 0.0)) {-
127 d->x_var = -d->x_var;-
128 d->x_peak = m_xVariance + m_xVariance * QRandomGenerator::global()->generateDouble();-
129 }-
130 d->x_vel += d->x_var * dt;-
131 }-
132 qreal dx = dt * d->x_vel;-
133-
134 if (m_yVariance != 0.) {-
135 if ((d->y_vel > d->y_peak && d->y_var > 0.0) || (d->y_vel < -d->y_peak && d->y_var < 0.0)) {-
136 d->y_var = -d->y_var;-
137 d->y_peak = m_yVariance + m_yVariance * QRandomGenerator::global()->generateDouble();-
138 }-
139 d->y_vel += d->y_var * dt;-
140 }-
141 qreal dy = dt * d->x_vel;-
142-
143 //### Should we be amending vel instead?-
144 ParticleVertex* p = &(data->pv);-
145 p->x += dx;-
146-
147 p->y += dy;-
148 return true;-
149 */-
150 qreal dx = dt * m_pace * (2 * QRandomGenerator::global()->generateDouble() - 1);-
151 qreal dy = dt * m_pace * (2 * QRandomGenerator::global()->generateDouble() - 1);-
152 qreal newX, newY;-
153 switch (m_affectedParameter){-
154 case Position:
never executed: case Position:
0
155 newX = data->curX(m_system) + dx;-
156 if (m_xVariance > qAbs(newX) )
m_xVariance > qAbs(newX)Description
TRUEnever evaluated
FALSEnever evaluated
0
157 data->x += dx;
never executed: data->x += dx;
0
158 newY = data->curY(m_system) + dy;-
159 if (m_yVariance > qAbs(newY) )
m_yVariance > qAbs(newY)Description
TRUEnever evaluated
FALSEnever evaluated
0
160 data->y += dy;
never executed: data->y += dy;
0
161 break;
never executed: break;
0
162 default:
never executed: default:
0
163 case Velocity:
executed 22348 times by 1 test: case Velocity:
Executed by:
  • tst_qquickwander
22348
164 newX = data->curVX(m_system) + dx;-
165 if (m_xVariance > qAbs(newX))
m_xVariance > qAbs(newX)Description
TRUEevaluated 22348 times by 1 test
Evaluated by:
  • tst_qquickwander
FALSEnever evaluated
0-22348
166 data->setInstantaneousVX(newX, m_system);
executed 22348 times by 1 test: data->setInstantaneousVX(newX, m_system);
Executed by:
  • tst_qquickwander
22348
167 newY = data->curVY(m_system) + dy;-
168 if (m_yVariance > qAbs(newY))
m_yVariance > qAbs(newY)Description
TRUEevaluated 22348 times by 1 test
Evaluated by:
  • tst_qquickwander
FALSEnever evaluated
0-22348
169 data->setInstantaneousVY(newY, m_system);
executed 22348 times by 1 test: data->setInstantaneousVY(newY, m_system);
Executed by:
  • tst_qquickwander
22348
170 break;
executed 22348 times by 1 test: break;
Executed by:
  • tst_qquickwander
22348
171 case Acceleration:
never executed: case Acceleration:
0
172 newX = data->ax + dx;-
173 if (m_xVariance > qAbs(newX))
m_xVariance > qAbs(newX)Description
TRUEnever evaluated
FALSEnever evaluated
0
174 data->setInstantaneousAX(newX, m_system);
never executed: data->setInstantaneousAX(newX, m_system);
0
175 newY = data->ay + dy;-
176 if (m_yVariance > qAbs(newY))
m_yVariance > qAbs(newY)Description
TRUEnever evaluated
FALSEnever evaluated
0
177 data->setInstantaneousAY(newY, m_system);
never executed: data->setInstantaneousAY(newY, m_system);
0
178 break;
never executed: break;
0
179 }-
180 return true;
executed 22348 times by 1 test: return true;
Executed by:
  • tst_qquickwander
22348
181}-
182QT_END_NAMESPACE-
183-
184#include "moc_qquickwander_p.cpp"-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.0