qvector3d.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/gui/math3d/qvector3d.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 QtGui 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 "qvector3d.h"-
41#include "qvector2d.h"-
42#include "qvector4d.h"-
43#include "qmatrix4x4.h"-
44#include <QtCore/qdatastream.h>-
45#include <QtCore/qmath.h>-
46#include <QtCore/qvariant.h>-
47#include <QtCore/qdebug.h>-
48#include <QtCore/qrect.h>-
49-
50QT_BEGIN_NAMESPACE-
51-
52#ifndef QT_NO_VECTOR3D-
53-
54/*!-
55 \class QVector3D-
56 \brief The QVector3D class represents a vector or vertex in 3D space.-
57 \since 4.6-
58 \ingroup painting-3D-
59 \inmodule QtGui-
60-
61 Vectors are one of the main building blocks of 3D representation and-
62 drawing. They consist of three coordinates, traditionally called-
63 x, y, and z.-
64-
65 The QVector3D class can also be used to represent vertices in 3D space.-
66 We therefore do not need to provide a separate vertex class.-
67-
68 \sa QVector2D, QVector4D, QQuaternion-
69*/-
70-
71/*!-
72 \fn QVector3D::QVector3D()-
73-
74 Constructs a null vector, i.e. with coordinates (0, 0, 0).-
75*/-
76-
77/*!-
78 \fn QVector3D::QVector3D(Qt::Initialization)-
79 \since 5.5-
80 \internal-
81-
82 Constructs a vector without initializing the contents.-
83*/-
84-
85/*!-
86 \fn QVector3D::QVector3D(float xpos, float ypos, float zpos)-
87-
88 Constructs a vector with coordinates (\a xpos, \a ypos, \a zpos).-
89*/-
90-
91/*!-
92 \fn QVector3D::QVector3D(const QPoint& point)-
93-
94 Constructs a vector with x and y coordinates from a 2D \a point, and a-
95 z coordinate of 0.-
96*/-
97-
98/*!-
99 \fn QVector3D::QVector3D(const QPointF& point)-
100-
101 Constructs a vector with x and y coordinates from a 2D \a point, and a-
102 z coordinate of 0.-
103*/-
104-
105#ifndef QT_NO_VECTOR2D-
106-
107/*!-
108 Constructs a 3D vector from the specified 2D \a vector. The z-
109 coordinate is set to zero.-
110-
111 \sa toVector2D()-
112*/-
113QVector3D::QVector3D(const QVector2D& vector)-
114{-
115 xp = vector.xp;-
116 yp = vector.yp;-
117 zp = 0.0f;-
118}
never executed: end of block
0
119-
120/*!-
121 Constructs a 3D vector from the specified 2D \a vector. The z-
122 coordinate is set to \a zpos.-
123-
124 \sa toVector2D()-
125*/-
126QVector3D::QVector3D(const QVector2D& vector, float zpos)-
127{-
128 xp = vector.xp;-
129 yp = vector.yp;-
130 zp = zpos;-
131}
never executed: end of block
0
132-
133#endif-
134-
135#ifndef QT_NO_VECTOR4D-
136-
137/*!-
138 Constructs a 3D vector from the specified 4D \a vector. The w-
139 coordinate is dropped.-
140-
141 \sa toVector4D()-
142*/-
143QVector3D::QVector3D(const QVector4D& vector)-
144{-
145 xp = vector.xp;-
146 yp = vector.yp;-
147 zp = vector.zp;-
148}
never executed: end of block
0
149-
150#endif-
151-
152/*!-
153 \fn bool QVector3D::isNull() const-
154-
155 Returns \c true if the x, y, and z coordinates are set to 0.0,-
156 otherwise returns \c false.-
157*/-
158-
159/*!-
160 \fn float QVector3D::x() const-
161-
162 Returns the x coordinate of this point.-
163-
164 \sa setX(), y(), z()-
165*/-
166-
167/*!-
168 \fn float QVector3D::y() const-
169-
170 Returns the y coordinate of this point.-
171-
172 \sa setY(), x(), z()-
173*/-
174-
175/*!-
176 \fn float QVector3D::z() const-
177-
178 Returns the z coordinate of this point.-
179-
180 \sa setZ(), x(), y()-
181*/-
182-
183/*!-
184 \fn void QVector3D::setX(float x)-
185-
186 Sets the x coordinate of this point to the given \a x coordinate.-
187-
188 \sa x(), setY(), setZ()-
189*/-
190-
191/*!-
192 \fn void QVector3D::setY(float y)-
193-
194 Sets the y coordinate of this point to the given \a y coordinate.-
195-
196 \sa y(), setX(), setZ()-
197*/-
198-
199/*!-
200 \fn void QVector3D::setZ(float z)-
201-
202 Sets the z coordinate of this point to the given \a z coordinate.-
203-
204 \sa z(), setX(), setY()-
205*/-
206-
207/*! \fn float &QVector3D::operator[](int i)-
208 \since 5.2-
209-
210 Returns the component of the vector at index position \a i-
211 as a modifiable reference.-
212-
213 \a i must be a valid index position in the vector (i.e., 0 <= \a i-
214 < 3).-
215*/-
216-
217/*! \fn float QVector3D::operator[](int i) const-
218 \since 5.2-
219-
220 Returns the component of the vector at index position \a i.-
221-
222 \a i must be a valid index position in the vector (i.e., 0 <= \a i-
223 < 3).-
224*/-
225-
226/*!-
227 Returns the normalized unit vector form of this vector.-
228-
229 If this vector is null, then a null vector is returned. If the length-
230 of the vector is very close to 1, then the vector will be returned as-is.-
231 Otherwise the normalized form of the vector of length 1 will be returned.-
232-
233 \sa length(), normalize()-
234*/-
235QVector3D QVector3D::normalized() const-
236{-
237 // Need some extra precision if the length is very small.-
238 double len = double(xp) * double(xp) +-
239 double(yp) * double(yp) +-
240 double(zp) * double(zp);-
241 if (qFuzzyIsNull(len - 1.0f)) {
qFuzzyIsNull(len - 1.0f)Description
TRUEnever evaluated
FALSEnever evaluated
0
242 return *this;
never executed: return *this;
0
243 } else if (!qFuzzyIsNull(len)) {
!qFuzzyIsNull(len)Description
TRUEnever evaluated
FALSEnever evaluated
0
244 double sqrtLen = std::sqrt(len);-
245 return QVector3D(float(double(xp) / sqrtLen),
never executed: return QVector3D(float(double(xp) / sqrtLen), float(double(yp) / sqrtLen), float(double(zp) / sqrtLen));
0
246 float(double(yp) / sqrtLen),
never executed: return QVector3D(float(double(xp) / sqrtLen), float(double(yp) / sqrtLen), float(double(zp) / sqrtLen));
0
247 float(double(zp) / sqrtLen));
never executed: return QVector3D(float(double(xp) / sqrtLen), float(double(yp) / sqrtLen), float(double(zp) / sqrtLen));
0
248 } else {-
249 return QVector3D();
never executed: return QVector3D();
0
250 }-
251}-
252-
253/*!-
254 Normalizes the currect vector in place. Nothing happens if this-
255 vector is a null vector or the length of the vector is very close to 1.-
256-
257 \sa length(), normalized()-
258*/-
259void QVector3D::normalize()-
260{-
261 // Need some extra precision if the length is very small.-
262 double len = double(xp) * double(xp) +-
263 double(yp) * double(yp) +-
264 double(zp) * double(zp);-
265 if (qFuzzyIsNull(len - 1.0f) || qFuzzyIsNull(len))
qFuzzyIsNull(len - 1.0f)Description
TRUEnever evaluated
FALSEnever evaluated
qFuzzyIsNull(len)Description
TRUEnever evaluated
FALSEnever evaluated
0
266 return;
never executed: return;
0
267-
268 len = std::sqrt(len);-
269-
270 xp = float(double(xp) / len);-
271 yp = float(double(yp) / len);-
272 zp = float(double(zp) / len);-
273}
never executed: end of block
0
274-
275/*!-
276 \fn QVector3D &QVector3D::operator+=(const QVector3D &vector)-
277-
278 Adds the given \a vector to this vector and returns a reference to-
279 this vector.-
280-
281 \sa operator-=()-
282*/-
283-
284/*!-
285 \fn QVector3D &QVector3D::operator-=(const QVector3D &vector)-
286-
287 Subtracts the given \a vector from this vector and returns a reference to-
288 this vector.-
289-
290 \sa operator+=()-
291*/-
292-
293/*!-
294 \fn QVector3D &QVector3D::operator*=(float factor)-
295-
296 Multiplies this vector's coordinates by the given \a factor, and-
297 returns a reference to this vector.-
298-
299 \sa operator/=()-
300*/-
301-
302/*!-
303 \fn QVector3D &QVector3D::operator*=(const QVector3D& vector)-
304 \overload-
305-
306 Multiplies the components of this vector by the corresponding-
307 components in \a vector.-
308-
309 Note: this is not the same as the crossProduct() of this-
310 vector and \a vector.-
311-
312 \sa crossProduct()-
313*/-
314-
315/*!-
316 \fn QVector3D &QVector3D::operator/=(float divisor)-
317-
318 Divides this vector's coordinates by the given \a divisor, and-
319 returns a reference to this vector.-
320-
321 \sa operator*=()-
322*/-
323-
324/*!-
325 \fn QVector3D &QVector3D::operator/=(const QVector3D &vector)-
326 \since 5.5-
327-
328 Divides the components of this vector by the corresponding-
329 components in \a vector.-
330-
331 \sa operator*=()-
332*/-
333-
334/*!-
335 Returns the dot product of \a v1 and \a v2.-
336*/-
337float QVector3D::dotProduct(const QVector3D& v1, const QVector3D& v2)-
338{-
339 return 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
340}-
341-
342/*!-
343 Returns the cross-product of vectors \a v1 and \a v2, which corresponds-
344 to the normal vector of a plane defined by \a v1 and \a v2.-
345-
346 \sa normal()-
347*/-
348QVector3D QVector3D::crossProduct(const QVector3D& v1, const QVector3D& v2)-
349{-
350 return 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
351 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
352 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
353}-
354-
355/*!-
356 Returns the normal vector of a plane defined by vectors \a v1 and \a v2,-
357 normalized to be a unit vector.-
358-
359 Use crossProduct() to compute the cross-product of \a v1 and \a v2 if you-
360 do not need the result to be normalized to a unit vector.-
361-
362 \sa crossProduct(), distanceToPlane()-
363*/-
364QVector3D QVector3D::normal(const QVector3D& v1, const QVector3D& v2)-
365{-
366 return crossProduct(v1, v2).normalized();
never executed: return crossProduct(v1, v2).normalized();
0
367}-
368-
369/*!-
370 \overload-
371-
372 Returns the normal vector of a plane defined by vectors-
373 \a v2 - \a v1 and \a v3 - \a v1, normalized to be a unit vector.-
374-
375 Use crossProduct() to compute the cross-product of \a v2 - \a v1 and-
376 \a v3 - \a v1 if you do not need the result to be normalized to a-
377 unit vector.-
378-
379 \sa crossProduct(), distanceToPlane()-
380*/-
381QVector3D QVector3D::normal-
382 (const QVector3D& v1, const QVector3D& v2, const QVector3D& v3)-
383{-
384 return crossProduct((v2 - v1), (v3 - v1)).normalized();
never executed: return crossProduct((v2 - v1), (v3 - v1)).normalized();
0
385}-
386-
387/*!-
388 \since 5.5-
389-
390 Returns the window coordinates of this vector initially in object/model-
391 coordinates using the model view matrix \a modelView, the projection matrix-
392 \a projection and the viewport dimensions \a viewport.-
393-
394 When transforming from clip to normalized space, a division by the w-
395 component on the vector components takes place. To prevent dividing by 0 if-
396 w equals to 0, it is set to 1.-
397-
398 \note the returned y coordinates are in OpenGL orientation. OpenGL expects-
399 the bottom to be 0 whereas for Qt top is 0.-
400-
401 \sa unproject()-
402 */-
403QVector3D QVector3D::project(const QMatrix4x4 &modelView, const QMatrix4x4 &projection, const QRect &viewport) const-
404{-
405 QVector4D tmp(*this, 1.0f);-
406 tmp = projection * modelView * tmp;-
407 if (qFuzzyIsNull(tmp.w()))
qFuzzyIsNull(tmp.w())Description
TRUEnever evaluated
FALSEnever evaluated
0
408 tmp.setW(1.0f);
never executed: tmp.setW(1.0f);
0
409 tmp /= tmp.w();-
410-
411 tmp = tmp * 0.5f + QVector4D(0.5f, 0.5f, 0.5f, 0.5f);-
412 tmp.setX(tmp.x() * viewport.width() + viewport.x());-
413 tmp.setY(tmp.y() * viewport.height() + viewport.y());-
414-
415 return tmp.toVector3D();
never executed: return tmp.toVector3D();
0
416}-
417-
418/*!-
419 \since 5.5-
420-
421 Returns the object/model coordinates of this vector initially in window-
422 coordinates using the model view matrix \a modelView, the projection matrix-
423 \a projection and the viewport dimensions \a viewport.-
424-
425 When transforming from clip to normalized space, a division by the w-
426 component of the vector components takes place. To prevent dividing by 0 if-
427 w equals to 0, it is set to 1.-
428-
429 \note y coordinates in \a viewport should use OpenGL orientation. OpenGL-
430 expects the bottom to be 0 whereas for Qt top is 0.-
431-
432 \sa project()-
433 */-
434QVector3D QVector3D::unproject(const QMatrix4x4 &modelView, const QMatrix4x4 &projection, const QRect &viewport) const-
435{-
436 QMatrix4x4 inverse = QMatrix4x4( projection * modelView ).inverted();-
437-
438 QVector4D tmp(*this, 1.0f);-
439 tmp.setX((tmp.x() - float(viewport.x())) / float(viewport.width()));-
440 tmp.setY((tmp.y() - float(viewport.y())) / float(viewport.height()));-
441 tmp = tmp * 2.0f - QVector4D(1.0f, 1.0f, 1.0f, 1.0f);-
442-
443 QVector4D obj = inverse * tmp;-
444 if (qFuzzyIsNull(obj.w()))
qFuzzyIsNull(obj.w())Description
TRUEnever evaluated
FALSEnever evaluated
0
445 obj.setW(1.0f);
never executed: obj.setW(1.0f);
0
446 obj /= obj.w();-
447 return obj.toVector3D();
never executed: return obj.toVector3D();
0
448}-
449-
450/*!-
451 \since 5.1-
452-
453 Returns the distance from this vertex to a point defined by-
454 the vertex \a point.-
455-
456 \sa distanceToPlane(), distanceToLine()-
457*/-
458float QVector3D::distanceToPoint(const QVector3D& point) const-
459{-
460 return (*this - point).length();
never executed: return (*this - point).length();
0
461}-
462-
463/*!-
464 Returns the distance from this vertex to a plane defined by-
465 the vertex \a plane and a \a normal unit vector. The \a normal-
466 parameter is assumed to have been normalized to a unit vector.-
467-
468 The return value will be negative if the vertex is below the plane,-
469 or zero if it is on the plane.-
470-
471 \sa normal(), distanceToLine()-
472*/-
473float QVector3D::distanceToPlane-
474 (const QVector3D& plane, const QVector3D& normal) const-
475{-
476 return dotProduct(*this - plane, normal);
never executed: return dotProduct(*this - plane, normal);
0
477}-
478-
479/*!-
480 \overload-
481-
482 Returns the distance from this vertex a plane defined by-
483 the vertices \a plane1, \a plane2 and \a plane3.-
484-
485 The return value will be negative if the vertex is below the plane,-
486 or zero if it is on the plane.-
487-
488 The two vectors that define the plane are \a plane2 - \a plane1-
489 and \a plane3 - \a plane1.-
490-
491 \sa normal(), distanceToLine()-
492*/-
493float QVector3D::distanceToPlane-
494 (const QVector3D& plane1, const QVector3D& plane2, const QVector3D& plane3) const-
495{-
496 QVector3D n = normal(plane2 - plane1, plane3 - plane1);-
497 return dotProduct(*this - plane1, n);
never executed: return dotProduct(*this - plane1, n);
0
498}-
499-
500/*!-
501 Returns the distance that this vertex is from a line defined-
502 by \a point and the unit vector \a direction.-
503-
504 If \a direction is a null vector, then it does not define a line.-
505 In that case, the distance from \a point to this vertex is returned.-
506-
507 \sa distanceToPlane()-
508*/-
509float QVector3D::distanceToLine-
510 (const QVector3D& point, const QVector3D& direction) const-
511{-
512 if (direction.isNull())
direction.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
513 return (*this - point).length();
never executed: return (*this - point).length();
0
514 QVector3D p = point + dotProduct(*this - point, direction) * direction;-
515 return (*this - p).length();
never executed: return (*this - p).length();
0
516}-
517-
518/*!-
519 \fn bool operator==(const QVector3D &v1, const QVector3D &v2)-
520 \relates QVector3D-
521-
522 Returns \c true if \a v1 is equal to \a v2; otherwise returns \c false.-
523 This operator uses an exact floating-point comparison.-
524*/-
525-
526/*!-
527 \fn bool operator!=(const QVector3D &v1, const QVector3D &v2)-
528 \relates QVector3D-
529-
530 Returns \c true if \a v1 is not equal to \a v2; otherwise returns \c false.-
531 This operator uses an exact floating-point comparison.-
532*/-
533-
534/*!-
535 \fn const QVector3D operator+(const QVector3D &v1, const QVector3D &v2)-
536 \relates QVector3D-
537-
538 Returns a QVector3D object that is the sum of the given vectors, \a v1-
539 and \a v2; each component is added separately.-
540-
541 \sa QVector3D::operator+=()-
542*/-
543-
544/*!-
545 \fn const QVector3D operator-(const QVector3D &v1, const QVector3D &v2)-
546 \relates QVector3D-
547-
548 Returns a QVector3D object that is formed by subtracting \a v2 from \a v1;-
549 each component is subtracted separately.-
550-
551 \sa QVector3D::operator-=()-
552*/-
553-
554/*!-
555 \fn const QVector3D operator*(float factor, const QVector3D &vector)-
556 \relates QVector3D-
557-
558 Returns a copy of the given \a vector, multiplied by the given \a factor.-
559-
560 \sa QVector3D::operator*=()-
561*/-
562-
563/*!-
564 \fn const QVector3D operator*(const QVector3D &vector, float factor)-
565 \relates QVector3D-
566-
567 Returns a copy of the given \a vector, multiplied by the given \a factor.-
568-
569 \sa QVector3D::operator*=()-
570*/-
571-
572/*!-
573 \fn const QVector3D operator*(const QVector3D &v1, const QVector3D& v2)-
574 \relates QVector3D-
575-
576 Multiplies the components of \a v1 by the corresponding components in \a v2.-
577-
578 Note: this is not the same as the crossProduct() of \a v1 and \a v2.-
579-
580 \sa QVector3D::crossProduct()-
581*/-
582-
583/*!-
584 \fn const QVector3D operator-(const QVector3D &vector)-
585 \relates QVector3D-
586 \overload-
587-
588 Returns a QVector3D object that is formed by changing the sign of-
589 all three components of the given \a vector.-
590-
591 Equivalent to \c {QVector3D(0,0,0) - vector}.-
592*/-
593-
594/*!-
595 \fn const QVector3D operator/(const QVector3D &vector, float divisor)-
596 \relates QVector3D-
597-
598 Returns the QVector3D object formed by dividing all three components of-
599 the given \a vector by the given \a divisor.-
600-
601 \sa QVector3D::operator/=()-
602*/-
603-
604/*!-
605 \fn const QVector3D operator/(const QVector3D &vector, const QVector3D &divisor)-
606 \relates QVector3D-
607 \since 5.5-
608-
609 Returns the QVector3D object formed by dividing components of the given-
610 \a vector by a respective components of the given \a divisor.-
611-
612 \sa QVector3D::operator/=()-
613*/-
614-
615/*!-
616 \fn bool qFuzzyCompare(const QVector3D& v1, const QVector3D& v2)-
617 \relates QVector3D-
618-
619 Returns \c true if \a v1 and \a v2 are equal, allowing for a small-
620 fuzziness factor for floating-point comparisons; false otherwise.-
621*/-
622-
623#ifndef QT_NO_VECTOR2D-
624-
625/*!-
626 Returns the 2D vector form of this 3D vector, dropping the z coordinate.-
627-
628 \sa toVector4D(), toPoint()-
629*/-
630QVector2D QVector3D::toVector2D() const-
631{-
632 return QVector2D(xp, yp);
never executed: return QVector2D(xp, yp);
0
633}-
634-
635#endif-
636-
637#ifndef QT_NO_VECTOR4D-
638-
639/*!-
640 Returns the 4D form of this 3D vector, with the w coordinate set to zero.-
641-
642 \sa toVector2D(), toPoint()-
643*/-
644QVector4D QVector3D::toVector4D() const-
645{-
646 return QVector4D(xp, yp, zp, 0.0f);
never executed: return QVector4D(xp, yp, zp, 0.0f);
0
647}-
648-
649#endif-
650-
651/*!-
652 \fn QPoint QVector3D::toPoint() const-
653-
654 Returns the QPoint form of this 3D vector. The z coordinate-
655 is dropped.-
656-
657 \sa toPointF(), toVector2D()-
658*/-
659-
660/*!-
661 \fn QPointF QVector3D::toPointF() const-
662-
663 Returns the QPointF form of this 3D vector. The z coordinate-
664 is dropped.-
665-
666 \sa toPoint(), toVector2D()-
667*/-
668-
669/*!-
670 Returns the 3D vector as a QVariant.-
671*/-
672QVector3D::operator QVariant() const-
673{-
674 return QVariant(QVariant::Vector3D, this);
never executed: return QVariant(QVariant::Vector3D, this);
0
675}-
676-
677/*!-
678 Returns the length of the vector from the origin.-
679-
680 \sa lengthSquared(), normalized()-
681*/-
682float QVector3D::length() const-
683{-
684 // Need some extra precision if the length is very small.-
685 double len = double(xp) * double(xp) +-
686 double(yp) * double(yp) +-
687 double(zp) * double(zp);-
688 return float(std::sqrt(len));
never executed: return float(std::sqrt(len));
0
689}-
690-
691/*!-
692 Returns the squared length of the vector from the origin.-
693 This is equivalent to the dot product of the vector with itself.-
694-
695 \sa length(), dotProduct()-
696*/-
697float QVector3D::lengthSquared() const-
698{-
699 return xp * xp + yp * yp + zp * zp;
never executed: return xp * xp + yp * yp + zp * zp;
0
700}-
701-
702#ifndef QT_NO_DEBUG_STREAM-
703-
704QDebug operator<<(QDebug dbg, const QVector3D &vector)-
705{-
706 QDebugStateSaver saver(dbg);-
707 dbg.nospace() << "QVector3D("-
708 << vector.x() << ", " << vector.y() << ", " << vector.z() << ')';-
709 return dbg;
never executed: return dbg;
0
710}-
711-
712#endif-
713-
714#ifndef QT_NO_DATASTREAM-
715-
716/*!-
717 \fn QDataStream &operator<<(QDataStream &stream, const QVector3D &vector)-
718 \relates QVector3D-
719-
720 Writes the given \a vector to the given \a stream and returns a-
721 reference to the stream.-
722-
723 \sa {Serializing Qt Data Types}-
724*/-
725-
726QDataStream &operator<<(QDataStream &stream, const QVector3D &vector)-
727{-
728 stream << vector.x() << vector.y() << vector.z();-
729 return stream;
never executed: return stream;
0
730}-
731-
732/*!-
733 \fn QDataStream &operator>>(QDataStream &stream, QVector3D &vector)-
734 \relates QVector3D-
735-
736 Reads a 3D vector from the given \a stream into the given \a vector-
737 and returns a reference to the stream.-
738-
739 \sa {Serializing Qt Data Types}-
740*/-
741-
742QDataStream &operator>>(QDataStream &stream, QVector3D &vector)-
743{-
744 float x, y, z;-
745 stream >> x;-
746 stream >> y;-
747 stream >> z;-
748 vector.setX(x);-
749 vector.setY(y);-
750 vector.setZ(z);-
751 return stream;
never executed: return stream;
0
752}-
753-
754#endif // QT_NO_DATASTREAM-
755-
756#endif // QT_NO_VECTOR3D-
757-
758QT_END_NAMESPACE-
Source codeSwitch to Preprocessed file

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