Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/particles/qquickturbulence.cpp |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||||||||
2 | QQuickTurbulenceAffector::QQuickTurbulenceAffector(QQuickItem *parent) : | - | ||||||||||||||||||
3 | QQuickParticleAffector(parent), | - | ||||||||||||||||||
4 | m_strength(10), m_lastT(0), m_gridSize(0), m_field(nullptr), m_vectorField(nullptr), m_inited(false) | - | ||||||||||||||||||
5 | { | - | ||||||||||||||||||
6 | } executed 8 times by 2 tests: end of block Executed by:
| 8 | ||||||||||||||||||
7 | - | |||||||||||||||||||
8 | void QQuickTurbulenceAffector::geometryChanged(const QRectF &, const QRectF &) | - | ||||||||||||||||||
9 | { | - | ||||||||||||||||||
10 | initializeGrid(); | - | ||||||||||||||||||
11 | } executed 16 times by 2 tests: end of block Executed by:
| 16 | ||||||||||||||||||
12 | - | |||||||||||||||||||
13 | QQuickTurbulenceAffector::~QQuickTurbulenceAffector() | - | ||||||||||||||||||
14 | { | - | ||||||||||||||||||
15 | if (m_field
| 2-6 | ||||||||||||||||||
16 | for (int i=0; i<m_gridSize
| 2-640 | ||||||||||||||||||
17 | free(m_field[i]); executed 640 times by 1 test: free(m_field[i]); Executed by:
| 640 | ||||||||||||||||||
18 | free(m_field); | - | ||||||||||||||||||
19 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||
20 | if (m_vectorField
| 2-6 | ||||||||||||||||||
21 | for (int i=0; i<m_gridSize
| 2-640 | ||||||||||||||||||
22 | free(m_vectorField[i]); executed 640 times by 1 test: free(m_vectorField[i]); Executed by:
| 640 | ||||||||||||||||||
23 | free(m_vectorField); | - | ||||||||||||||||||
24 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||
25 | } executed 8 times by 2 tests: end of block Executed by:
| 8 | ||||||||||||||||||
26 | - | |||||||||||||||||||
27 | void QQuickTurbulenceAffector::initializeGrid() | - | ||||||||||||||||||
28 | { | - | ||||||||||||||||||
29 | if (!m_inited
| 2-16 | ||||||||||||||||||
30 | return; executed 16 times by 2 tests: return; Executed by:
| 16 | ||||||||||||||||||
31 | - | |||||||||||||||||||
32 | int arg = qMax(width(), height()); | - | ||||||||||||||||||
33 | if (m_gridSize != arg
| 0-2 | ||||||||||||||||||
34 | if (m_field
| 0-2 | ||||||||||||||||||
35 | for (int i=0; i<m_gridSize
| 0 | ||||||||||||||||||
36 | free(m_field[i]); never executed: free(m_field[i]); | 0 | ||||||||||||||||||
37 | free(m_field); | - | ||||||||||||||||||
38 | } never executed: end of block | 0 | ||||||||||||||||||
39 | if (m_vectorField
| 0-2 | ||||||||||||||||||
40 | for (int i=0; i<m_gridSize
| 0 | ||||||||||||||||||
41 | free(m_vectorField[i]); never executed: free(m_vectorField[i]); | 0 | ||||||||||||||||||
42 | free(m_vectorField); | - | ||||||||||||||||||
43 | } never executed: end of block | 0 | ||||||||||||||||||
44 | m_gridSize = arg; | - | ||||||||||||||||||
45 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||
46 | - | |||||||||||||||||||
47 | m_field = (qreal**)malloc(m_gridSize * sizeof(qreal*)); | - | ||||||||||||||||||
48 | for (int i=0; i<m_gridSize
| 2-640 | ||||||||||||||||||
49 | m_field[i] = (qreal*)malloc(m_gridSize * sizeof(qreal)); executed 640 times by 1 test: m_field[i] = (qreal*)malloc(m_gridSize * sizeof(qreal)); Executed by:
| 640 | ||||||||||||||||||
50 | m_vectorField = (QPointF**)malloc(m_gridSize * sizeof(QPointF*)); | - | ||||||||||||||||||
51 | for (int i=0; i<m_gridSize
| 2-640 | ||||||||||||||||||
52 | m_vectorField[i] = (QPointF*)malloc(m_gridSize * sizeof(QPointF)); executed 640 times by 1 test: m_vectorField[i] = (QPointF*)malloc(m_gridSize * sizeof(QPointF)); Executed by:
| 640 | ||||||||||||||||||
53 | - | |||||||||||||||||||
54 | QImage image; | - | ||||||||||||||||||
55 | if (!m_noiseSource.isEmpty()
| 0-2 | ||||||||||||||||||
56 | image = QImage(QQmlFile::urlToLocalFileOrQrc(m_noiseSource)).scaled(QSize(m_gridSize, m_gridSize)); never executed: image = QImage(QQmlFile::urlToLocalFileOrQrc(m_noiseSource)).scaled(QSize(m_gridSize, m_gridSize)); | 0 | ||||||||||||||||||
57 | if (image.isNull()
| 0-2 | ||||||||||||||||||
58 | image = QImage(([]() noexcept -> QString { enum { Size = sizeof(u"" ":particleresources/noise.png")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" ":particleresources/noise.png" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return executed 2 times by 1 test: qstring_literal_temp;return qstring_literal_temp; Executed by:
executed 2 times by 1 test: }())).scaled(QSize(m_gridSize, m_gridSize));return qstring_literal_temp; Executed by:
executed 2 times by 1 test: image = QImage(([]() noexcept -> QString { enum { Size = sizeof(u"" ":particleresources/noise.png")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" ":particleresources/noise.png" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }())).scaled(QSize(m_gridSize, m_gridSize)); Executed by:
| 2 | ||||||||||||||||||
59 | - | |||||||||||||||||||
60 | for (int i=0; i<m_gridSize
| 2-640 | ||||||||||||||||||
61 | for (int j=0; j<m_gridSize
| 640-204800 | ||||||||||||||||||
62 | m_field[i][j] = qGray(image.pixel(QPoint(i,j))); executed 204800 times by 1 test: m_field[i][j] = qGray(image.pixel(QPoint(i,j))); Executed by:
| 204800 | ||||||||||||||||||
63 | for (int i=0; i<m_gridSize
| 2-640 | ||||||||||||||||||
64 | for (int j=0; j<m_gridSize
| 640-204800 | ||||||||||||||||||
65 | m_vectorField[i][j].setX(boundsRespectingField(i-1,j) - boundsRespectingField(i,j)); | - | ||||||||||||||||||
66 | m_vectorField[i][j].setY(boundsRespectingField(i,j) - boundsRespectingField(i,j-1)); | - | ||||||||||||||||||
67 | } executed 204800 times by 1 test: end of block Executed by:
| 204800 | ||||||||||||||||||
68 | } executed 640 times by 1 test: end of block Executed by:
| 640 | ||||||||||||||||||
69 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||
70 | - | |||||||||||||||||||
71 | qreal QQuickTurbulenceAffector::boundsRespectingField(int x, int y) | - | ||||||||||||||||||
72 | { | - | ||||||||||||||||||
73 | if (x < 0
| 640-818560 | ||||||||||||||||||
74 | x = 0; executed 640 times by 1 test: x = 0; Executed by:
| 640 | ||||||||||||||||||
75 | if (x >= m_gridSize
| 0-819200 | ||||||||||||||||||
76 | x = m_gridSize - 1; never executed: x = m_gridSize - 1; | 0 | ||||||||||||||||||
77 | if (y < 0
| 640-818560 | ||||||||||||||||||
78 | y = 0; executed 640 times by 1 test: y = 0; Executed by:
| 640 | ||||||||||||||||||
79 | if (y >= m_gridSize
| 0-819200 | ||||||||||||||||||
80 | y = m_gridSize - 1; never executed: y = m_gridSize - 1; | 0 | ||||||||||||||||||
81 | return executed 819200 times by 1 test: m_field[x][y];return m_field[x][y]; Executed by:
executed 819200 times by 1 test: return m_field[x][y]; Executed by:
| 819200 | ||||||||||||||||||
82 | } | - | ||||||||||||||||||
83 | - | |||||||||||||||||||
84 | void QQuickTurbulenceAffector::ensureInit() | - | ||||||||||||||||||
85 | { | - | ||||||||||||||||||
86 | if (m_inited
| 2-78 | ||||||||||||||||||
87 | return; executed 78 times by 1 test: return; Executed by:
| 78 | ||||||||||||||||||
88 | m_inited = true; | - | ||||||||||||||||||
89 | initializeGrid(); | - | ||||||||||||||||||
90 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||
91 | - | |||||||||||||||||||
92 | void QQuickTurbulenceAffector::affectSystem(qreal dt) | - | ||||||||||||||||||
93 | { | - | ||||||||||||||||||
94 | if (!m_system
| 0-80 | ||||||||||||||||||
95 | return; never executed: return; | 0 | ||||||||||||||||||
96 | ensureInit(); | - | ||||||||||||||||||
97 | if (!m_gridSize
| 0-80 | ||||||||||||||||||
98 | return; never executed: return; | 0 | ||||||||||||||||||
99 | - | |||||||||||||||||||
100 | updateOffsets(); | - | ||||||||||||||||||
101 | - | |||||||||||||||||||
102 | QRect boundsRect(0,0,m_gridSize,m_gridSize); | - | ||||||||||||||||||
103 | for (auto _container_ = QtPrivate::qMakeForeachContainer(m_system->groupData); _container_.control
| 0-160 | ||||||||||||||||||
104 | if (!activeGroup(gd->index)
| 0-80 | ||||||||||||||||||
105 | continue; never executed: continue; | 0 | ||||||||||||||||||
106 | for (auto _container_ = QtPrivate::qMakeForeachContainer(gd->data); _container_.control
| 0-40080 | ||||||||||||||||||
107 | if (!shouldAffect(d)
| 16156-23844 | ||||||||||||||||||
108 | continue; executed 16156 times by 1 test: continue; Executed by:
| 16156 | ||||||||||||||||||
109 | QPoint pos = (QPointF(d->curX(m_system), d->curY(m_system)) - m_offset).toPoint(); | - | ||||||||||||||||||
110 | if (!boundsRect.contains(pos,true)
| 0-23844 | ||||||||||||||||||
111 | continue; never executed: continue; | 0 | ||||||||||||||||||
112 | qreal fx = 0.0; | - | ||||||||||||||||||
113 | qreal fy = 0.0; | - | ||||||||||||||||||
114 | fx += m_vectorField[pos.x()][pos.y()].x() * m_strength; | - | ||||||||||||||||||
115 | fy += m_vectorField[pos.x()][pos.y()].y() * m_strength; | - | ||||||||||||||||||
116 | if (fx || fy){ | - | ||||||||||||||||||
117 | d->setInstantaneousVX(d->curVX(m_system)+ fx * dt, m_system); | - | ||||||||||||||||||
118 | d->setInstantaneousVY(d->curVY(m_system)+ fy * dt, m_system); | - | ||||||||||||||||||
119 | postAffect(d); | - | ||||||||||||||||||
120 | } executed 20708 times by 1 test: end of block Executed by:
| 20708 | ||||||||||||||||||
121 | } executed 23844 times by 1 test: end of block Executed by:
| 23844 | ||||||||||||||||||
122 | } executed 80 times by 1 test: end of block Executed by:
| 80 | ||||||||||||||||||
123 | } executed 80 times by 1 test: end of block Executed by:
| 80 | ||||||||||||||||||
124 | - | |||||||||||||||||||
125 | - | |||||||||||||||||||
126 | - | |||||||||||||||||||
Switch to Source code | Preprocessed file |