Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/particles/qquickpointattractor.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||
---|---|---|---|---|---|---|---|---|
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 "qquickpointattractor_p.h" | - | ||||||
41 | #include <cmath> | - | ||||||
42 | #include <QDebug> | - | ||||||
43 | QT_BEGIN_NAMESPACE | - | ||||||
44 | /*! | - | ||||||
45 | \qmltype Attractor | - | ||||||
46 | \instantiates QQuickAttractorAffector | - | ||||||
47 | \inqmlmodule QtQuick.Particles | - | ||||||
48 | \ingroup qtquick-particles | - | ||||||
49 | \inherits Affector | - | ||||||
50 | \brief For attracting particles towards a specific point. | - | ||||||
51 | - | |||||||
52 | Note that the size and position of this element affects which particles it affects. | - | ||||||
53 | The size of the point attracted to is always 0x0, and the location of that point | - | ||||||
54 | is specified by the pointX and pointY properties. | - | ||||||
55 | - | |||||||
56 | Note that Attractor has the standard Item x,y,width and height properties. | - | ||||||
57 | Like other affectors, these represent the affected area. They | - | ||||||
58 | do not represent the 0x0 point which is the target of the attraction. | - | ||||||
59 | */ | - | ||||||
60 | - | |||||||
61 | - | |||||||
62 | /*! | - | ||||||
63 | \qmlproperty real QtQuick.Particles::PointAttractor::pointX | - | ||||||
64 | - | |||||||
65 | The x coordinate of the attracting point. This is relative | - | ||||||
66 | to the x coordinate of the Attractor. | - | ||||||
67 | */ | - | ||||||
68 | /*! | - | ||||||
69 | \qmlproperty real QtQuick.Particles::PointAttractor::pointY | - | ||||||
70 | - | |||||||
71 | The y coordinate of the attracting point. This is relative | - | ||||||
72 | to the y coordinate of the Attractor. | - | ||||||
73 | */ | - | ||||||
74 | /*! | - | ||||||
75 | \qmlproperty real QtQuick.Particles::PointAttractor::strength | - | ||||||
76 | - | |||||||
77 | The pull, in units per second, to be exerted on an item one pixel away. | - | ||||||
78 | - | |||||||
79 | Depending on how the attraction is proportionalToDistance this may have to | - | ||||||
80 | be very high or very low to have a reasonable effect on particles at a | - | ||||||
81 | distance. | - | ||||||
82 | */ | - | ||||||
83 | /*! | - | ||||||
84 | \qmlproperty AffectableParameter QtQuick.Particles::Attractor::affectedParameter | - | ||||||
85 | - | |||||||
86 | What attribute of particles is directly affected. | - | ||||||
87 | \list | - | ||||||
88 | \li Attractor.Position | - | ||||||
89 | \li Attractor.Velocity | - | ||||||
90 | \li Attractor.Acceleration | - | ||||||
91 | \endlist | - | ||||||
92 | */ | - | ||||||
93 | /*! | - | ||||||
94 | \qmlproperty Proportion QtQuick.Particles::Attractor::proportionalToDistance | - | ||||||
95 | - | |||||||
96 | How the distance from the particle to the point affects the strength of the attraction. | - | ||||||
97 | - | |||||||
98 | \list | - | ||||||
99 | \li Attractor.Constant | - | ||||||
100 | \li Attractor.Linear | - | ||||||
101 | \li Attractor.InverseLinear | - | ||||||
102 | \li Attractor.Quadratic | - | ||||||
103 | \li Attractor.InverseQuadratic | - | ||||||
104 | \endlist | - | ||||||
105 | */ | - | ||||||
106 | - | |||||||
107 | - | |||||||
108 | QQuickAttractorAffector::QQuickAttractorAffector(QQuickItem *parent) : | - | ||||||
109 | QQuickParticleAffector(parent), m_strength(0.0), m_x(0), m_y(0) | - | ||||||
110 | , m_physics(Velocity), m_proportionalToDistance(Linear) | - | ||||||
111 | { | - | ||||||
112 | } executed 4 times by 2 tests: end of block Executed by:
| 4 | ||||||
113 | - | |||||||
114 | bool QQuickAttractorAffector::affectParticle(QQuickParticleData *d, qreal dt) | - | ||||||
115 | { | - | ||||||
116 | if (m_strength == 0.0)
| 0-22846 | ||||||
117 | return false; never executed: return false; | 0 | ||||||
118 | qreal dx = m_x+m_offset.x() - d->curX(m_system); | - | ||||||
119 | qreal dy = m_y+m_offset.y() - d->curY(m_system); | - | ||||||
120 | qreal r = std::sqrt((dx*dx) + (dy*dy)); | - | ||||||
121 | qreal theta = std::atan2(dy,dx); | - | ||||||
122 | qreal ds = 0; | - | ||||||
123 | switch (m_proportionalToDistance){ | - | ||||||
124 | case InverseQuadratic: never executed: case InverseQuadratic: | 0 | ||||||
125 | ds = (m_strength / qMax<qreal>(1.,r*r)); | - | ||||||
126 | break; never executed: break; | 0 | ||||||
127 | case InverseLinear: never executed: case InverseLinear: | 0 | ||||||
128 | ds = (m_strength / qMax<qreal>(1.,r)); | - | ||||||
129 | break; never executed: break; | 0 | ||||||
130 | case Quadratic: never executed: case Quadratic: | 0 | ||||||
131 | ds = (m_strength * qMax<qreal>(1.,r*r)); | - | ||||||
132 | break; never executed: break; | 0 | ||||||
133 | case Linear: never executed: case Linear: | 0 | ||||||
134 | ds = (m_strength * qMax<qreal>(1.,r)); | - | ||||||
135 | break; never executed: break; | 0 | ||||||
136 | default: //also Constant executed 22846 times by 1 test: default: Executed by:
| 22846 | ||||||
137 | ds = m_strength; | - | ||||||
138 | } executed 22846 times by 1 test: end of block Executed by:
| 22846 | ||||||
139 | ds *= dt; | - | ||||||
140 | dx = ds * std::cos(theta); | - | ||||||
141 | dy = ds * std::sin(theta); | - | ||||||
142 | qreal vx,vy; | - | ||||||
143 | switch (m_physics){ | - | ||||||
144 | case Position: executed 22846 times by 1 test: case Position: Executed by:
| 22846 | ||||||
145 | d->x = (d->x + dx); | - | ||||||
146 | d->y = (d->y + dy); | - | ||||||
147 | break; executed 22846 times by 1 test: break; Executed by:
| 22846 | ||||||
148 | case Acceleration: never executed: case Acceleration: | 0 | ||||||
149 | d->setInstantaneousAX(d->ax + dx, m_system); | - | ||||||
150 | d->setInstantaneousAY(d->ay + dy, m_system); | - | ||||||
151 | break; never executed: break; | 0 | ||||||
152 | case Velocity: //also default never executed: case Velocity: | 0 | ||||||
153 | default: never executed: default: | 0 | ||||||
154 | vx = d->curVX(m_system); | - | ||||||
155 | vy = d->curVY(m_system); | - | ||||||
156 | d->setInstantaneousVX(vx + dx, m_system); | - | ||||||
157 | d->setInstantaneousVY(vy + dy, m_system); | - | ||||||
158 | } never executed: end of block | 0 | ||||||
159 | - | |||||||
160 | return true; executed 22846 times by 1 test: return true; Executed by:
| 22846 | ||||||
161 | } | - | ||||||
162 | QT_END_NAMESPACE | - | ||||||
163 | - | |||||||
164 | #include "moc_qquickpointattractor_p.cpp" | - | ||||||
Source code | Switch to Preprocessed file |