qvector3d.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/gui/math3d/qvector3d.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3QVector3D::QVector3D(const QVector2D& vector)-
4{-
5 xp = vector.xp;-
6 yp = vector.yp;-
7 zp = 0.0f;-
8}
never executed: end of block
0
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}
never executed: end of block
0
22QVector3D::QVector3D(const QVector4D& vector)-
23{-
24 xp = vector.xp;-
25 yp = vector.yp;-
26 zp = vector.zp;-
27}
never executed: end of block
0
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)
qFuzzyIsNull(len - 1.0f)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
35 return
never executed: return *this;
*this;
never executed: return *this;
0
36 } else if (!qFuzzyIsNull(len)
!qFuzzyIsNull(len)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
37 double sqrtLen = std::sqrt(len);-
38 return
never executed: return QVector3D(float(double(xp) / sqrtLen), float(double(yp) / sqrtLen), float(double(zp) / sqrtLen));
QVector3D(float(double(xp) / sqrtLen),
never executed: return QVector3D(float(double(xp) / sqrtLen), float(double(yp) / sqrtLen), float(double(zp) / sqrtLen));
0
39 float(double(yp) / sqrtLen),
never executed: return QVector3D(float(double(xp) / sqrtLen), float(double(yp) / sqrtLen), float(double(zp) / sqrtLen));
0
40 float(double(zp) / sqrtLen));
never executed: return QVector3D(float(double(xp) / sqrtLen), float(double(yp) / sqrtLen), float(double(zp) / sqrtLen));
0
41 } else {-
42 return
never executed: return QVector3D();
QVector3D();
never executed: return QVector3D();
0
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 - 1.0f)Description
TRUEnever evaluated
FALSEnever evaluated
|| qFuzzyIsNull(len)
qFuzzyIsNull(len)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
59 return;
never executed: return;
0
60-
61 len = std::sqrt(len);-
62-
63 xp = float(double(xp) / len);-
64 yp = float(double(yp) / len);-
65 zp = float(double(zp) / len);-
66}
never executed: end of block
0
67float QVector3D::dotProduct(const QVector3D& v1, const QVector3D& v2)-
68{-
69 return
never executed: return v1.xp * v2.xp + v1.yp * v2.yp + v1.zp * v2.zp;
v1.xp * v2.xp + v1.yp * v2.yp + v1.zp * v2.zp;
never executed: return v1.xp * v2.xp + v1.yp * v2.yp + v1.zp * v2.zp;
0
70}-
71-
72-
73-
74-
75-
76-
77-
78QVector3D QVector3D::crossProduct(const QVector3D& v1, const QVector3D& v2)-
79{-
80 return
never 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);
QVector3D(v1.yp * v2.zp - v1.zp * v2.yp,
never 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);
0
81 v1.zp * v2.xp - v1.xp * v2.zp,
never 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);
0
82 v1.xp * v2.yp - v1.yp * v2.xp);
never 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);
0
83}-
84QVector3D QVector3D::normal(const QVector3D& v1, const QVector3D& v2)-
85{-
86 return
never executed: return crossProduct(v1, v2).normalized();
crossProduct(v1, v2).normalized();
never executed: return crossProduct(v1, v2).normalized();
0
87}-
88QVector3D QVector3D::normal-
89 (const QVector3D& v1, const QVector3D& v2, const QVector3D& v3)-
90{-
91 return
never executed: return crossProduct((v2 - v1), (v3 - v1)).normalized();
crossProduct((v2 - v1), (v3 - v1)).normalized();
never executed: return crossProduct((v2 - v1), (v3 - v1)).normalized();
0
92}-
93QVector3D QVector3D::project(const QMatrix4x4 &modelView, const QMatrix4x4 &projection, const QRect &viewport) const-
94{-
95 QVector4D tmp(*this, 1.0f);-
96 tmp = projection * modelView * tmp;-
97 if (qFuzzyIsNull(tmp.w())
qFuzzyIsNull(tmp.w())Description
TRUEnever evaluated
FALSEnever evaluated
)
0
98 tmp.setW(1.0f);
never executed: tmp.setW(1.0f);
0
99 tmp /= tmp.w();-
100-
101 tmp = tmp * 0.5f + QVector4D(0.5f, 0.5f, 0.5f, 0.5f);-
102 tmp.setX(tmp.x() * viewport.width() + viewport.x());-
103 tmp.setY(tmp.y() * viewport.height() + viewport.y());-
104-
105 return
never executed: return tmp.toVector3D();
tmp.toVector3D();
never executed: return tmp.toVector3D();
0
106}-
107QVector3D QVector3D::unproject(const QMatrix4x4 &modelView, const QMatrix4x4 &projection, const QRect &viewport) const-
108{-
109 QMatrix4x4 inverse = QMatrix4x4( projection * modelView ).inverted();-
110-
111 QVector4D tmp(*this, 1.0f);-
112 tmp.setX((tmp.x() - float(viewport.x())) / float(viewport.width()));-
113 tmp.setY((tmp.y() - float(viewport.y())) / float(viewport.height()));-
114 tmp = tmp * 2.0f - QVector4D(1.0f, 1.0f, 1.0f, 1.0f);-
115-
116 QVector4D obj = inverse * tmp;-
117 if (qFuzzyIsNull(obj.w())
qFuzzyIsNull(obj.w())Description
TRUEnever evaluated
FALSEnever evaluated
)
0
118 obj.setW(1.0f);
never executed: obj.setW(1.0f);
0
119 obj /= obj.w();-
120 return
never executed: return obj.toVector3D();
obj.toVector3D();
never executed: return obj.toVector3D();
0
121}-
122float QVector3D::distanceToPoint(const QVector3D& point) const-
123{-
124 return
never executed: return (*this - point).length();
(*this - point).length();
never executed: return (*this - point).length();
0
125}-
126float QVector3D::distanceToPlane-
127 (const QVector3D& plane, const QVector3D& normal) const-
128{-
129 return
never executed: return dotProduct(*this - plane, normal);
dotProduct(*this - plane, normal);
never executed: return dotProduct(*this - plane, normal);
0
130}-
131float QVector3D::distanceToPlane-
132 (const QVector3D& plane1, const QVector3D& plane2, const QVector3D& plane3) const-
133{-
134 QVector3D n = normal(plane2 - plane1, plane3 - plane1);-
135 return
never executed: return dotProduct(*this - plane1, n);
dotProduct(*this - plane1, n);
never executed: return dotProduct(*this - plane1, n);
0
136}-
137float QVector3D::distanceToLine-
138 (const QVector3D& point, const QVector3D& direction) const-
139{-
140 if (direction.isNull()
direction.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
141 return
never executed: return (*this - point).length();
(*this - point).length();
never executed: return (*this - point).length();
0
142 QVector3D p = point + dotProduct(*this - point, direction) * direction;-
143 return
never executed: return (*this - p).length();
(*this - p).length();
never executed: return (*this - p).length();
0
144}-
145QVector2D QVector3D::toVector2D() const-
146{-
147 return
never executed: return QVector2D(xp, yp);
QVector2D(xp, yp);
never executed: return QVector2D(xp, yp);
0
148}-
149QVector4D QVector3D::toVector4D() const-
150{-
151 return
never executed: return QVector4D(xp, yp, zp, 0.0f);
QVector4D(xp, yp, zp, 0.0f);
never executed: return QVector4D(xp, yp, zp, 0.0f);
0
152}-
153QVector3D::operator QVariant() const-
154{-
155 return
never executed: return QVariant(QVariant::Vector3D, this);
QVariant(QVariant::Vector3D, this);
never executed: return QVariant(QVariant::Vector3D, this);
0
156}-
157-
158-
159-
160-
161-
162-
163float QVector3D::length() const-
164{-
165-
166 double len = double(xp) * double(xp) +-
167 double(yp) * double(yp) +-
168 double(zp) * double(zp);-
169 return
never executed: return float(std::sqrt(len));
float(std::sqrt(len));
never executed: return float(std::sqrt(len));
0
170}-
171-
172-
173-
174-
175-
176-
177-
178float QVector3D::lengthSquared() const-
179{-
180 return
never executed: return xp * xp + yp * yp + zp * zp;
xp * xp + yp * yp + zp * zp;
never executed: return xp * xp + yp * yp + zp * zp;
0
181}-
182-
183-
184-
185QDebug operator<<(QDebug dbg, const QVector3D &vector)-
186{-
187 QDebugStateSaver saver(dbg);-
188 dbg.nospace() << "QVector3D("-
189 << vector.x() << ", " << vector.y() << ", " << vector.z() << ')';-
190 return
never executed: return dbg;
dbg;
never executed: return dbg;
0
191}-
192QDataStream &operator<<(QDataStream &stream, const QVector3D &vector)-
193{-
194 stream << vector.x() << vector.y() << vector.z();-
195 return
never executed: return stream;
stream;
never executed: return stream;
0
196}-
197QDataStream &operator>>(QDataStream &stream, QVector3D &vector)-
198{-
199 float x, y, z;-
200 stream >> x;-
201 stream >> y;-
202 stream >> z;-
203 vector.setX(x);-
204 vector.setY(y);-
205 vector.setZ(z);-
206 return
never executed: return stream;
stream;
never executed: return stream;
0
207}-
208-
209-
210-
211-
212-
213-
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9