math3d/qvector3d.cpp

Switch to Source codePreprocessed file
LineSource CodeCoverage
1 -
2 -
3QVector3D::QVector3D(const QVector2D& vector) -
4{ -
5 xp = vector.xp; -
6 yp = vector.yp; -
7 zp = 0.0f; -
8}
executed: }
Execution Count:1
1
9 -
10 -
11 -
12 -
13 -
14 -
15 -
16QVector3D::QVector3D(const QVector2D& vector, float zpos) -
17{ -
18 xp = vector.xp; -
19 yp = vector.yp; -
20 zp = zpos; -
21}
executed: }
Execution Count:1
1
22QVector3D::QVector3D(const QVector4D& vector) -
23{ -
24 xp = vector.xp; -
25 yp = vector.yp; -
26 zp = vector.zp; -
27}
executed: }
Execution Count:1
1
28QVector3D QVector3D::normalized() const -
29{ -
30 -
31 double len = double(xp) * double(xp) + -
32 double(yp) * double(yp) + -
33 double(zp) * double(zp); -
34 if (qFuzzyIsNull(len - 1.0f)) {
evaluated: qFuzzyIsNull(len - 1.0f)
TRUEFALSE
yes
Evaluation Count:30
yes
Evaluation Count:25
25-30
35 return *this;
executed: return *this;
Execution Count:30
30
36 } else if (!qFuzzyIsNull(len)) {
evaluated: !qFuzzyIsNull(len)
TRUEFALSE
yes
Evaluation Count:16
yes
Evaluation Count:9
9-16
37 double sqrtLen = sqrt(len); -
38 return QVector3D(float(double(xp) / sqrtLen), 16
39 float(double(yp) / sqrtLen), 16
40 float(double(zp) / sqrtLen));
executed: return QVector3D(float(double(xp) / sqrtLen), float(double(yp) / sqrtLen), float(double(zp) / sqrtLen));
Execution Count:16
16
41 } else { -
42 return QVector3D();
executed: return QVector3D();
Execution Count:9
9
43 } -
44} -
45 -
46 -
47 -
48 -
49 -
50 -
51 -
52void QVector3D::normalize() -
53{ -
54 -
55 double len = double(xp) * double(xp) + -
56 double(yp) * double(yp) + -
57 double(zp) * double(zp); -
58 if (qFuzzyIsNull(len - 1.0f) || qFuzzyIsNull(len))
evaluated: qFuzzyIsNull(len - 1.0f)
TRUEFALSE
yes
Evaluation Count:6
yes
Evaluation Count:2
evaluated: qFuzzyIsNull(len)
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:1
1-6
59 return;
executed: return;
Execution Count:7
7
60 -
61 len = sqrt(len); -
62 -
63 xp = float(double(xp) / len); -
64 yp = float(double(yp) / len); -
65 zp = float(double(zp) / len); -
66}
executed: }
Execution Count:1
1
67float QVector3D::dotProduct(const QVector3D& v1, const QVector3D& v2) -
68{ -
69 return v1.xp * v2.xp + v1.yp * v2.yp + v1.zp * v2.zp;
executed: return v1.xp * v2.xp + v1.yp * v2.yp + v1.zp * v2.zp;
Execution Count:644
644
70} -
71 -
72 -
73 -
74 -
75 -
76 -
77 -
78QVector3D QVector3D::crossProduct(const QVector3D& v1, const QVector3D& v2) -
79{ -
80 return QVector3D(v1.yp * v2.zp - v1.zp * v2.yp, 643
81 v1.zp * v2.xp - v1.xp * v2.zp, 643
82 v1.xp * v2.yp - v1.yp * v2.xp);
executed: return QVector3D(v1.yp * v2.zp - v1.zp * v2.yp, v1.zp * v2.xp - v1.xp * v2.zp, v1.xp * v2.yp - v1.yp * v2.xp);
Execution Count:643
643
83} -
84QVector3D QVector3D::normal(const QVector3D& v1, const QVector3D& v2) -
85{ -
86 return crossProduct(v1, v2).normalized();
executed: return crossProduct(v1, v2).normalized();
Execution Count:6
6
87} -
88QVector3D QVector3D::normal -
89 (const QVector3D& v1, const QVector3D& v2, const QVector3D& v3) -
90{ -
91 return crossProduct((v2 - v1), (v3 - v1)).normalized();
executed: return crossProduct((v2 - v1), (v3 - v1)).normalized();
Execution Count:6
6
92} -
93float QVector3D::distanceToPlane -
94 (const QVector3D& plane, const QVector3D& normal) const -
95{ -
96 return dotProduct(*this - plane, normal);
executed: return dotProduct(*this - plane, normal);
Execution Count:3
3
97} -
98float QVector3D::distanceToPlane -
99 (const QVector3D& plane1, const QVector3D& plane2, const QVector3D& plane3) const -
100{ -
101 QVector3D n = normal(plane2 - plane1, plane3 - plane1); -
102 return dotProduct(*this - plane1, n);
executed: return dotProduct(*this - plane1, n);
Execution Count:3
3
103} -
104float QVector3D::distanceToLine -
105 (const QVector3D& point, const QVector3D& direction) const -
106{ -
107 if (direction.isNull())
evaluated: direction.isNull()
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:4
1-4
108 return (*this - point).length();
executed: return (*this - point).length();
Execution Count:1
1
109 QVector3D p = point + dotProduct(*this - point, direction) * direction; -
110 return (*this - p).length();
executed: return (*this - p).length();
Execution Count:4
4
111} -
112QVector2D QVector3D::toVector2D() const -
113{ -
114 return QVector2D(xp, yp);
executed: return QVector2D(xp, yp);
Execution Count:1
1
115} -
116QVector4D QVector3D::toVector4D() const -
117{ -
118 return QVector4D(xp, yp, zp, 0.0f);
executed: return QVector4D(xp, yp, zp, 0.0f);
Execution Count:1
1
119} -
120QVector3D::operator QVariant() const -
121{ -
122 return QVariant(QVariant::Vector3D, this);
executed: return QVariant(QVariant::Vector3D, this);
Execution Count:1
1
123} -
124 -
125 -
126 -
127 -
128 -
129 -
130float QVector3D::length() const -
131{ -
132 -
133 double len = double(xp) * double(xp) + -
134 double(yp) * double(yp) + -
135 double(zp) * double(zp); -
136 return float(sqrt(len));
executed: return float(sqrt(len));
Execution Count:27
27
137} -
138 -
139 -
140 -
141 -
142 -
143 -
144 -
145float QVector3D::lengthSquared() const -
146{ -
147 return xp * xp + yp * yp + zp * zp;
executed: return xp * xp + yp * yp + zp * zp;
Execution Count:8
8
148} -
149 -
150 -
151 -
152QDebug operator<<(QDebug dbg, const QVector3D &vector) -
153{ -
154 dbg.nospace() << "QVector3D(" -
155 << vector.x() << ", " << vector.y() << ", " << vector.z() << ')'; -
156 return dbg.space();
executed: return dbg.space();
Execution Count:1
1
157} -
158QDataStream &operator<<(QDataStream &stream, const QVector3D &vector) -
159{ -
160 stream << vector.x() << vector.y() << vector.z(); -
161 return stream;
never executed: return stream;
0
162} -
163QDataStream &operator>>(QDataStream &stream, QVector3D &vector) -
164{ -
165 float x, y, z; -
166 stream >> x; -
167 stream >> y; -
168 stream >> z; -
169 vector.setX(x); -
170 vector.setY(y); -
171 vector.setZ(z); -
172 return stream;
never executed: return stream;
0
173} -
174 -
175 -
176 -
177 -
178 -
179 -
180 -
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial