Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qvectornd.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// Copyright (C) 2020 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4// Qt-Security score:significant reason:default
5
6#include "qvectornd.h"
7#include <QtCore/qdatastream.h>
8#include <QtCore/qdebug.h>
9#include <QtCore/qvariant.h>
10#include <QtGui/qmatrix4x4.h>
11
13
14#ifndef QT_NO_VECTOR2D
15
16/*!
17 \class QVector2D
18 \brief The QVector2D class represents a vector or vertex in 2D space.
19 \since 4.6
20 \ingroup painting
21 \ingroup painting-3D
22 \inmodule QtGui
23
24 Vectors are one of the main building blocks of 2D representation and
25 drawing. They consist of two finite floating-point coordinates,
26 traditionally called x and y.
27
28 The QVector2D class can also be used to represent vertices in 2D space.
29 We therefore do not need to provide a separate vertex class.
30
31 \sa QVector3D, QVector4D, QQuaternion
32*/
33
34/*!
35 \fn QVector2D::QVector2D()
36
37 Constructs a null vector, i.e. with coordinates (0, 0).
38*/
39
40/*!
41 \fn QVector2D::QVector2D(Qt::Initialization)
42 \since 5.5
43 \internal
44
45 Constructs a vector without initializing the contents.
46*/
47
48/*!
49 \fn QVector2D::QVector2D(float xpos, float ypos)
50
51 Constructs a vector with coordinates (\a xpos, \a ypos).
52 Both coordinates must be finite.
53*/
54
55/*!
56 \fn QVector2D::QVector2D(QPoint point)
57
58 Constructs a vector with x and y coordinates from a 2D \a point.
59*/
60
61/*!
62 \fn QVector2D::QVector2D(QPointF point)
63
64 Constructs a vector with x and y coordinates from a 2D \a point.
65*/
66
67#ifndef QT_NO_VECTOR3D
68
69/*!
70 \fn QVector2D::QVector2D(QVector3D vector)
71
72 Constructs a vector with x and y coordinates from a 3D \a vector.
73 The z coordinate of \a vector is dropped.
74
75 \sa toVector3D()
76*/
77
78#endif
79
80#ifndef QT_NO_VECTOR4D
81
82/*!
83 \fn QVector2D::QVector2D(QVector4D vector)
84
85 Constructs a vector with x and y coordinates from a 3D \a vector.
86 The z and w coordinates of \a vector are dropped.
87
88 \sa toVector4D()
89*/
90
91#endif
92
93/*!
94 \fn bool QVector2D::isNull() const
95
96 Returns \c true if the x and y coordinates are set to 0.0,
97 otherwise returns \c false.
98*/
99
100/*!
101 \fn float QVector2D::x() const
102
103 Returns the x coordinate of this point.
104
105 \sa setX(), y()
106*/
107
108/*!
109 \fn float QVector2D::y() const
110
111 Returns the y coordinate of this point.
112
113 \sa setY(), x()
114*/
115
116/*!
117 \fn void QVector2D::setX(float x)
118
119 Sets the x coordinate of this point to the given finite \a x coordinate.
120
121 \sa x(), setY()
122*/
123
124/*!
125 \fn void QVector2D::setY(float y)
126
127 Sets the y coordinate of this point to the given finite \a y coordinate.
128
129 \sa y(), setX()
130*/
131
132/*! \fn float &QVector2D::operator[](int i)
133 \since 5.2
134
135 Returns the component of the vector at index position \a i
136 as a modifiable reference.
137
138 \a i must be a valid index position in the vector (i.e., 0 <= \a i
139 < 2).
140*/
141
142/*! \fn float QVector2D::operator[](int i) const
143 \since 5.2
144
145 Returns the component of the vector at index position \a i.
146
147 \a i must be a valid index position in the vector (i.e., 0 <= \a i
148 < 2).
149*/
150
151/*!
152 \fn float QVector2D::length() const
153
154 Returns the length of the vector from the origin.
155
156 \sa lengthSquared(), normalized()
157*/
158
159/*!
160 \fn float QVector2D::lengthSquared() const
161
162 Returns the squared length of the vector from the origin.
163 This is equivalent to the dot product of the vector with itself.
164
165 \sa length(), dotProduct()
166*/
167
168/*!
169 \fn QVector2D QVector2D::normalized() const
170
171 Returns the normalized unit vector form of this vector.
172
173 If this vector is null, then a null vector is returned. If the length
174 of the vector is very close to 1, then the vector will be returned as-is.
175 Otherwise the normalized form of the vector of length 1 will be returned.
176
177 \sa length(), normalize()
178*/
179
180/*!
181 \fn void QVector2D::normalize()
182
183 Normalizes the current vector in place. Nothing happens if this
184 vector is a null vector or the length of the vector is very close to 1.
185
186 \sa length(), normalized()
187*/
188
189/*!
190 \fn float QVector2D::distanceToPoint(QVector2D point) const
191 \since 5.1
192
193 Returns the distance from this vertex to a point defined by
194 the vertex \a point.
195
196 \sa distanceToLine()
197*/
198
199/*!
200 \fn float QVector2D::distanceToLine(QVector2D point, QVector2D direction) const
201 \since 5.1
202
203 Returns the distance that this vertex is from a line defined
204 by \a point and the unit vector \a direction.
205
206 If \a direction is a null vector, then it does not define a line.
207 In that case, the distance from \a point to this vertex is returned.
208
209 \sa distanceToPoint()
210*/
211
212/*!
213 \fn QVector2D &QVector2D::operator+=(QVector2D vector)
214
215 Adds the given \a vector to this vector and returns a reference to
216 this vector.
217
218 \sa operator-=()
219*/
220
221/*!
222 \fn QVector2D &QVector2D::operator-=(QVector2D vector)
223
224 Subtracts the given \a vector from this vector and returns a reference to
225 this vector.
226
227 \sa operator+=()
228*/
229
230/*!
231 \fn QVector2D &QVector2D::operator*=(float factor)
232
233 Multiplies this vector's coordinates by the given finite \a factor and
234 returns a reference to this vector.
235
236 \sa operator/=(), operator*()
237*/
238
239/*!
240 \fn QVector2D &QVector2D::operator*=(QVector2D vector)
241
242 Multiplies each component of this vector by the corresponding component of
243 \a vector and returns a reference to this vector.
244
245 \note This is not a cross product of this vector with \a vector. (Its
246 components add up to the dot product of this vector and \a vector.)
247
248 \sa operator/=(), operator*()
249*/
250
251/*!
252 \fn QVector2D &QVector2D::operator/=(float divisor)
253
254 Divides this vector's coordinates by the given \a divisor and returns a
255 reference to this vector. The \a divisor must not be either zero or NaN.
256
257 \sa operator*=()
258*/
259
260/*!
261 \fn QVector2D &QVector2D::operator/=(QVector2D vector)
262 \since 5.5
263
264 Divides each component of this vector by the corresponding component of \a
265 vector and returns a reference to this vector.
266
267 The \a vector must have no component that is either zero or NaN.
268
269 \sa operator*=(), operator/()
270*/
271
272/*!
273 \fn float QVector2D::dotProduct(QVector2D v1, QVector2D v2)
274
275 Returns the dot product of \a v1 and \a v2.
276*/
277
278/*!
279 \fn bool QVector2D::operator==(QVector2D v1, QVector2D v2)
280
281 Returns \c true if \a v1 is equal to \a v2; otherwise returns \c false.
282 This operator uses an exact floating-point comparison.
283*/
284
285/*!
286 \fn bool QVector2D::operator!=(QVector2D v1, QVector2D v2)
287
288 Returns \c true if \a v1 is not equal to \a v2; otherwise returns \c false.
289 This operator uses an exact floating-point comparison.
290*/
291
292/*! //! friend
293 \fn const QVector2D QVector2D::operator+(QVector2D v1, QVector2D v2)
294
295 Returns a QVector2D object that is the sum of the given vectors, \a v1
296 and \a v2; each component is added separately.
297
298 \sa QVector2D::operator+=()
299*/
300
301/*! //! friend
302 \fn const QVector2D QVector2D::operator-(QVector2D v1, QVector2D v2)
303
304 Returns a QVector2D object that is formed by subtracting \a v2 from \a v1;
305 each component is subtracted separately.
306
307 \sa QVector2D::operator-=()
308*/
309
310/*! //! friend
311 \fn const QVector2D QVector2D::operator*(float factor, QVector2D vector)
312
313 Returns a copy of the given \a vector, multiplied by the given finite \a factor.
314
315 \sa QVector2D::operator*=()
316*/
317
318/*! //! friend
319 \fn const QVector2D QVector2D::operator*(QVector2D vector, float factor)
320
321 Returns a copy of the given \a vector, multiplied by the given finite \a factor.
322
323 \sa QVector2D::operator*=()
324*/
325
326/*! //! friend
327 \fn const QVector2D QVector2D::operator*(QVector2D v1, QVector2D v2)
328
329 Returns the QVector2D object formed by multiplying each component of \a v1
330 by the corresponding component of \a v2.
331
332 \note This is not a cross product of \a v1 and \a v2 in any sense.
333 (Its components add up to the dot product of \a v1 and \a v2.)
334
335 \sa QVector2D::operator*=()
336*/
337
338/*! //! friend
339 \fn const QVector2D QVector2D::operator-(QVector2D vector)
340 \overload
341
342 Returns a QVector2D object that is formed by changing the sign of each
343 component of the given \a vector.
344
345 Equivalent to \c {QVector2D(0,0) - vector}.
346*/
347
348/*! //! friend
349 \fn const QVector2D QVector2D::operator/(QVector2D vector, float divisor)
350
351 Returns the QVector2D object formed by dividing each component of the given
352 \a vector by the given \a divisor.
353
354 The \a divisor must not be either zero or NaN.
355
356 \sa QVector2D::operator/=()
357*/
358
359/*! //! friend
360 \fn const QVector2D QVector2D::operator/(QVector2D vector, QVector2D divisor)
361 \since 5.5
362
363 Returns the QVector2D object formed by dividing each component of the given
364 \a vector by the corresponding component of the given \a divisor.
365
366 The \a divisor must have no component that is either zero or NaN.
367
368 \sa QVector2D::operator/=()
369*/
370
371/*! //! friend
372 \fn bool QVector2D::qFuzzyCompare(QVector2D v1, QVector2D v2)
373
374 Returns \c true if \a v1 and \a v2 are equal, allowing for a small
375 fuzziness factor for floating-point comparisons; false otherwise.
376*/
377bool qFuzzyCompare(QVector2D v1, QVector2D v2) noexcept
378{
379 return QtPrivate::fuzzyCompare(v1.v[0], v2.v[0])
380 && QtPrivate::fuzzyCompare(v1.v[1], v2.v[1]);
381}
382
383#ifndef QT_NO_VECTOR3D
384/*!
385 \fn QVector3D QVector2D::toVector3D() const
386
387 Returns the 3D form of this 2D vector, with the z coordinate set to zero.
388
389 \sa toVector4D(), toPoint()
390*/
391#endif
392
393#ifndef QT_NO_VECTOR4D
394/*!
395 \fn QVector4D QVector2D::toVector4D() const
396
397 Returns the 4D form of this 2D vector, with the z and w coordinates set to zero.
398
399 \sa toVector3D(), toPoint()
400*/
401#endif
402
403/*!
404 \fn QPoint QVector2D::toPoint() const
405
406 Returns the QPoint form of this 2D vector.
407 Each coordinate is rounded to the nearest integer.
408
409 \sa toPointF(), toVector3D()
410*/
411
412/*!
413 \fn QPointF QVector2D::toPointF() const
414
415 Returns the QPointF form of this 2D vector.
416
417 \sa toPoint(), toVector3D()
418*/
419
420/*!
421 Returns the 2D vector as a QVariant.
422*/
423QVector2D::operator QVariant() const
424{
425 return QVariant::fromValue(*this);
426}
427
428#ifndef QT_NO_DEBUG_STREAM
429
430QDebug operator<<(QDebug dbg, QVector2D vector)
431{
432 QDebugStateSaver saver(dbg);
433 dbg.nospace() << "QVector2D(" << vector.x() << ", " << vector.y() << ')';
434 return dbg;
435}
436
437#endif
438
439#ifndef QT_NO_DATASTREAM
440
441/*!
442 \fn QDataStream &operator<<(QDataStream &stream, QVector2D vector)
443 \relates QVector2D
444
445 Writes the given \a vector to the given \a stream and returns a
446 reference to the stream.
447
448 \sa {Serializing Qt Data Types}
449*/
450
451QDataStream &operator<<(QDataStream &stream, QVector2D vector)
452{
453 stream << vector.x() << vector.y();
454 return stream;
455}
456
457/*!
458 \fn QDataStream &operator>>(QDataStream &stream, QVector2D &vector)
459 \relates QVector2D
460
461 Reads a 2D vector from the given \a stream into the given \a vector
462 and returns a reference to the stream.
463
464 \sa {Serializing Qt Data Types}
465*/
466
467QDataStream &operator>>(QDataStream &stream, QVector2D &vector)
468{
469 float x, y;
470 stream >> x;
471 stream >> y;
472 vector.setX(x);
473 vector.setY(y);
474 return stream;
475}
476
477#endif // QT_NO_DATASTREAM
478
479#endif // QT_NO_VECTOR2D
480
481
482
483#ifndef QT_NO_VECTOR3D
484
485/*!
486 \class QVector3D
487 \brief The QVector3D class represents a vector or vertex in 3D space.
488 \since 4.6
489 \ingroup painting-3D
490 \inmodule QtGui
491
492 Vectors are one of the main building blocks of 3D representation and
493 drawing. They consist of three finite floating-point coordinates,
494 traditionally called x, y, and z.
495
496 The QVector3D class can also be used to represent vertices in 3D space.
497 We therefore do not need to provide a separate vertex class.
498
499 \sa QVector2D, QVector4D, QQuaternion
500*/
501
502/*!
503 \fn QVector3D::QVector3D()
504
505 Constructs a null vector, i.e. with coordinates (0, 0, 0).
506*/
507
508/*!
509 \fn QVector3D::QVector3D(Qt::Initialization)
510 \since 5.5
511 \internal
512
513 Constructs a vector without initializing the contents.
514*/
515
516/*!
517 \fn QVector3D::QVector3D(float xpos, float ypos, float zpos)
518
519 Constructs a vector with coordinates (\a xpos, \a ypos, \a zpos).
520 All parameters must be finite.
521*/
522
523/*!
524 \fn QVector3D::QVector3D(QPoint point)
525
526 Constructs a vector with x and y coordinates from a 2D \a point, and a
527 z coordinate of 0.
528*/
529
530/*!
531 \fn QVector3D::QVector3D(QPointF point)
532
533 Constructs a vector with x and y coordinates from a 2D \a point, and a
534 z coordinate of 0.
535*/
536
537#ifndef QT_NO_VECTOR2D
538
539/*!
540 \fn QVector3D::QVector3D(QVector2D vector)
541
542 Constructs a 3D vector from the specified 2D \a vector. The z
543 coordinate is set to zero.
544
545 \sa toVector2D()
546*/
547
548/*!
549 \fn QVector3D::QVector3D(QVector2D vector, float zpos)
550
551 Constructs a 3D vector from the specified 2D \a vector. The z
552 coordinate is set to \a zpos, which must be finite.
553
554 \sa toVector2D()
555*/
556#endif
557
558#ifndef QT_NO_VECTOR4D
559
560/*!
561 \fn QVector3D::QVector3D(QVector4D vector)
562
563 Constructs a 3D vector from the specified 4D \a vector. The w
564 coordinate is dropped.
565
566 \sa toVector4D()
567*/
568
569#endif
570
571/*!
572 \fn bool QVector3D::isNull() const
573
574 Returns \c true if the x, y, and z coordinates are set to 0.0,
575 otherwise returns \c false.
576*/
577
578/*!
579 \fn float QVector3D::x() const
580
581 Returns the x coordinate of this point.
582
583 \sa setX(), y(), z()
584*/
585
586/*!
587 \fn float QVector3D::y() const
588
589 Returns the y coordinate of this point.
590
591 \sa setY(), x(), z()
592*/
593
594/*!
595 \fn float QVector3D::z() const
596
597 Returns the z coordinate of this point.
598
599 \sa setZ(), x(), y()
600*/
601
602/*!
603 \fn void QVector3D::setX(float x)
604
605 Sets the x coordinate of this point to the given finite \a x coordinate.
606
607 \sa x(), setY(), setZ()
608*/
609
610/*!
611 \fn void QVector3D::setY(float y)
612
613 Sets the y coordinate of this point to the given finite \a y coordinate.
614
615 \sa y(), setX(), setZ()
616*/
617
618/*!
619 \fn void QVector3D::setZ(float z)
620
621 Sets the z coordinate of this point to the given finite \a z coordinate.
622
623 \sa z(), setX(), setY()
624*/
625
626/*! \fn float &QVector3D::operator[](int i)
627 \since 5.2
628
629 Returns the component of the vector at index position \a i
630 as a modifiable reference.
631
632 \a i must be a valid index position in the vector (i.e., 0 <= \a i
633 < 3).
634*/
635
636/*! \fn float QVector3D::operator[](int i) const
637 \since 5.2
638
639 Returns the component of the vector at index position \a i.
640
641 \a i must be a valid index position in the vector (i.e., 0 <= \a i
642 < 3).
643*/
644
645/*!
646 \fn QVector3D QVector3D::normalized() const
647
648 Returns the normalized unit vector form of this vector.
649
650 If this vector is null, then a null vector is returned. If the length
651 of the vector is very close to 1, then the vector will be returned as-is.
652 Otherwise the normalized form of the vector of length 1 will be returned.
653
654 \sa length(), normalize()
655*/
656
657/*!
658 \fn void QVector3D::normalize()
659
660 Normalizes the current vector in place. Nothing happens if this
661 vector is a null vector or the length of the vector is very close to 1.
662
663 \sa length(), normalized()
664*/
665
666/*!
667 \fn QVector3D &QVector3D::operator+=(QVector3D vector)
668
669 Adds the given \a vector to this vector and returns a reference to
670 this vector.
671
672 \sa operator-=()
673*/
674
675/*!
676 \fn QVector3D &QVector3D::operator-=(QVector3D vector)
677
678 Subtracts the given \a vector from this vector and returns a reference to
679 this vector.
680
681 \sa operator+=()
682*/
683
684/*!
685 \fn QVector3D &QVector3D::operator*=(float factor)
686
687 Multiplies this vector's coordinates by the given finite \a factor and
688 returns a reference to this vector.
689
690 \sa operator/=(), operator*()
691*/
692
693/*!
694 \fn QVector3D &QVector3D::operator*=(QVector3D vector)
695 \overload
696
697 Multiplies each component of this vector by the corresponding component in
698 \a vector and returns a reference to this vector.
699
700 Note: this is not the same as the crossProduct() of this vector and
701 \a vector. (Its components add up to the dot product of this vector and
702 \a vector.)
703
704 \sa crossProduct(), operator/=(), operator*()
705*/
706
707/*!
708 \fn QVector3D &QVector3D::operator/=(float divisor)
709
710 Divides this vector's coordinates by the given \a divisor, and returns a
711 reference to this vector. The \a divisor must not be either zero or NaN.
712
713 \sa operator*=(), operator/()
714*/
715
716/*!
717 \fn QVector3D &QVector3D::operator/=(QVector3D vector)
718 \since 5.5
719
720 Divides each component of this vector by the corresponding component in \a
721 vector and returns a reference to this vector.
722
723 The \a vector must have no component that is either zero or NaN.
724
725 \sa operator*=(), operator/()
726*/
727
728/*!
729 \fn float QVector3D::dotProduct(QVector3D v1, QVector3D v2)
730
731 Returns the dot product of \a v1 and \a v2.
732*/
733
734/*!
735 \fn QVector3D QVector3D::crossProduct(QVector3D v1, QVector3D v2)
736
737 Returns the cross-product of vectors \a v1 and \a v2, which is normal to the
738 plane spanned by \a v1 and \a v2. It will be zero if the two vectors are
739 parallel.
740
741 \sa normal()
742*/
743
744/*!
745 \fn QVector3D QVector3D::normal(QVector3D v1, QVector3D v2)
746
747 Returns the unit normal vector of a plane spanned by vectors \a v1 and \a
748 v2, which must not be parallel to one another.
749
750 Use crossProduct() to compute the cross-product of \a v1 and \a v2 if you
751 do not need the result to be normalized to a unit vector.
752
753 \sa crossProduct(), distanceToPlane()
754*/
755
756/*!
757 \fn QVector3D QVector3D::normal(QVector3D v1, QVector3D v2, QVector3D v3)
758
759 Returns the unit normal vector of a plane spanned by vectors \a v2 - \a v1
760 and \a v3 - \a v1, which must not be parallel to one another.
761
762 Use crossProduct() to compute the cross-product of \a v2 - \a v1 and
763 \a v3 - \a v1 if you do not need the result to be normalized to a
764 unit vector.
765
766 \sa crossProduct(), distanceToPlane()
767*/
768
769/*!
770 \since 5.5
771
772 Returns the window coordinates of this vector initially in object/model
773 coordinates using the model view matrix \a modelView, the projection matrix
774 \a projection and the viewport dimensions \a viewport.
775
776 When transforming from clip to normalized space, a division by the w
777 component on the vector components takes place. To prevent dividing by 0 if
778 w equals to 0, it is set to 1.
779
780 \note the returned y coordinates are in OpenGL orientation. OpenGL expects
781 the bottom to be 0 whereas for Qt top is 0.
782
783 \sa unproject()
784 */
785QVector3D QVector3D::project(const QMatrix4x4 &modelView, const QMatrix4x4 &projection, const QRect &viewport) const
786{
787 QVector4D tmp(*this, 1.0f);
788 tmp = projection * modelView * tmp;
789 if (qFuzzyIsNull(tmp.w()))
790 tmp.setW(1.0f);
791 tmp /= tmp.w();
792
793 tmp = tmp * 0.5f + QVector4D(0.5f, 0.5f, 0.5f, 0.5f);
794 tmp.setX(tmp.x() * viewport.width() + viewport.x());
795 tmp.setY(tmp.y() * viewport.height() + viewport.y());
796
797 return tmp.toVector3D();
798}
799
800/*!
801 \since 5.5
802
803 Returns the object/model coordinates of this vector initially in window
804 coordinates using the model view matrix \a modelView, the projection matrix
805 \a projection and the viewport dimensions \a viewport.
806
807 When transforming from clip to normalized space, a division by the w
808 component of the vector components takes place. To prevent dividing by 0 if
809 w equals to 0, it is set to 1.
810
811 \note y coordinates in \a viewport should use OpenGL orientation. OpenGL
812 expects the bottom to be 0 whereas for Qt top is 0.
813
814 \sa project()
815 */
816QVector3D QVector3D::unproject(const QMatrix4x4 &modelView, const QMatrix4x4 &projection, const QRect &viewport) const
817{
818 QMatrix4x4 inverse = QMatrix4x4( projection * modelView ).inverted();
819
820 QVector4D tmp(*this, 1.0f);
821 tmp.setX((tmp.x() - float(viewport.x())) / float(viewport.width()));
822 tmp.setY((tmp.y() - float(viewport.y())) / float(viewport.height()));
823 tmp = tmp * 2.0f - QVector4D(1.0f, 1.0f, 1.0f, 1.0f);
824
825 QVector4D obj = inverse * tmp;
826 if (qFuzzyIsNull(obj.w()))
827 obj.setW(1.0f);
828 obj /= obj.w();
829 return obj.toVector3D();
830}
831
832/*!
833 \fn float QVector3D::distanceToPoint(QVector3D point) const
834
835 \since 5.1
836
837 Returns the distance from this vertex to a point defined by
838 the vertex \a point.
839
840 \sa distanceToPlane(), distanceToLine()
841*/
842
843/*!
844 \fn float QVector3D::distanceToPlane(QVector3D plane, QVector3D normal) const
845
846 Returns the distance from this vertex to a plane defined by
847 the vertex \a plane and a \a normal unit vector. The \a normal
848 parameter is assumed to have been normalized to a unit vector.
849
850 The return value will be negative if the vertex is below the plane,
851 or zero if it is on the plane.
852
853 \sa normal(), distanceToLine()
854*/
855
856/*!
857 \fn float QVector3D::distanceToPlane(QVector3D plane1, QVector3D plane2, QVector3D plane3) const
858
859 Returns the distance from this vertex to a plane defined by
860 the vertices \a plane1, \a plane2 and \a plane3.
861
862 The return value will be negative if the vertex is below the plane,
863 or zero if it is on the plane.
864
865 The two vectors that define the plane are \a plane2 - \a plane1
866 and \a plane3 - \a plane1.
867
868 \sa normal(), distanceToLine()
869*/
870
871/*!
872 \fn float QVector3D::distanceToLine(QVector3D point, QVector3D direction) const
873
874 Returns the distance that this vertex is from a line defined
875 by \a point and the unit vector \a direction.
876
877 If \a direction is a null vector, then it does not define a line.
878 In that case, the distance from \a point to this vertex is returned.
879
880 \sa distanceToPlane()
881*/
882
883/*!
884 \fn bool QVector3D::operator==(QVector3D v1, QVector3D v2)
885
886 Returns \c true if \a v1 is equal to \a v2; otherwise returns \c false.
887 This operator uses an exact floating-point comparison.
888*/
889
890/*!
891 \fn bool QVector3D::operator!=(QVector3D v1, QVector3D v2)
892
893 Returns \c true if \a v1 is not equal to \a v2; otherwise returns \c false.
894 This operator uses an exact floating-point comparison.
895*/
896
897/*! //! friend
898 \fn const QVector3D QVector3D::operator+(QVector3D v1, QVector3D v2)
899
900 Returns a QVector3D object that is the sum of the given vectors, \a v1
901 and \a v2; each component is added separately.
902
903 \sa QVector3D::operator+=()
904*/
905
906/*! //! friend
907 \fn const QVector3D QVector3D::operator-(QVector3D v1, QVector3D v2)
908
909 Returns a QVector3D object that is formed by subtracting \a v2 from \a v1;
910 each component is subtracted separately.
911
912 \sa QVector3D::operator-=()
913*/
914
915/*! //! friend
916 \fn const QVector3D QVector3D::operator*(float factor, QVector3D vector)
917
918 Returns a copy of the given \a vector, multiplied by the given finite \a factor.
919
920 \sa QVector3D::operator*=()
921*/
922
923/*! //! friend
924 \fn const QVector3D QVector3D::operator*(QVector3D vector, float factor)
925
926 Returns a copy of the given \a vector, multiplied by the given finite \a factor.
927
928 \sa QVector3D::operator*=()
929*/
930
931/*! //! friend
932 \fn const QVector3D QVector3D::operator*(QVector3D v1, QVector3D v2)
933
934 Returns the QVector3D object formed by multiplying each component of \a v1
935 by the corresponding component of \a v2.
936
937 \note This is not the same as the crossProduct() of \a v1 and \a v2.
938 (Its components add up to the dot product of \a v1 and \a v2.)
939
940 \sa QVector3D::crossProduct()
941*/
942
943/*! //! friend
944 \fn const QVector3D QVector3D::operator-(QVector3D vector)
945 \overload
946
947 Returns a QVector3D object that is formed by changing the sign of each
948 component of the given \a vector.
949
950 Equivalent to \c {QVector3D(0,0,0) - vector}.
951*/
952
953/*! //! friend
954 \fn const QVector3D QVector3D::operator/(QVector3D vector, float divisor)
955
956 Returns the QVector3D object formed by dividing each component of the given
957 \a vector by the given \a divisor.
958
959 The \a divisor must not be either zero or NaN.
960
961 \sa QVector3D::operator/=()
962*/
963
964/*! //! friend
965 \fn const QVector3D QVector3D::operator/(QVector3D vector, QVector3D divisor)
966 \since 5.5
967
968 Returns the QVector3D object formed by dividing each component of the given
969 \a vector by the corresponding component of the given \a divisor.
970
971 The \a divisor must have no component that is either zero or NaN.
972
973 \sa QVector3D::operator/=()
974*/
975
976/*! //! friend
977 \fn bool QVector3D::qFuzzyCompare(QVector3D v1, QVector3D v2)
978
979 Returns \c true if \a v1 and \a v2 are equal, allowing for a small
980 fuzziness factor for floating-point comparisons; false otherwise.
981*/
982bool qFuzzyCompare(QVector3D v1, QVector3D v2) noexcept
983{
984 return QtPrivate::fuzzyCompare(v1.v[0], v2.v[0])
985 && QtPrivate::fuzzyCompare(v1.v[1], v2.v[1])
986 && QtPrivate::fuzzyCompare(v1.v[2], v2.v[2]);
987}
988
989#ifndef QT_NO_VECTOR2D
990
991/*!
992 \fn QVector2D QVector3D::toVector2D() const
993
994 Returns the 2D vector form of this 3D vector, dropping the z coordinate.
995
996 \sa toVector4D(), toPoint()
997*/
998
999#endif
1000
1001#ifndef QT_NO_VECTOR4D
1002
1003/*!
1004 \fn QVector4D QVector3D::toVector4D() const
1005
1006 Returns the 4D form of this 3D vector, with the w coordinate set to zero.
1007
1008 \sa toVector2D(), toPoint()
1009*/
1010
1011#endif
1012
1013/*!
1014 \fn QPoint QVector3D::toPoint() const
1015
1016 Returns the QPoint form of this 3D vector. The z coordinate is dropped. The
1017 x and y coordinates are rounded to nearest integers.
1018
1019 \sa toPointF(), toVector2D()
1020*/
1021
1022/*!
1023 \fn QPointF QVector3D::toPointF() const
1024
1025 Returns the QPointF form of this 3D vector. The z coordinate
1026 is dropped.
1027
1028 \sa toPoint(), toVector2D()
1029*/
1030
1031/*!
1032 Returns the 3D vector as a QVariant.
1033*/
1034QVector3D::operator QVariant() const
1035{
1036 return QVariant::fromValue(*this);
1037}
1038
1039/*!
1040 \fn float QVector3D::length() const
1041
1042 Returns the length of the vector from the origin.
1043
1044 \sa lengthSquared(), normalized()
1045*/
1046
1047/*!
1048 \fn float QVector3D::lengthSquared() const
1049
1050 Returns the squared length of the vector from the origin.
1051 This is equivalent to the dot product of the vector with itself.
1052
1053 \sa length(), dotProduct()
1054*/
1055
1056#ifndef QT_NO_DEBUG_STREAM
1057
1058QDebug operator<<(QDebug dbg, QVector3D vector)
1059{
1060 QDebugStateSaver saver(dbg);
1061 dbg.nospace() << "QVector3D("
1062 << vector.x() << ", " << vector.y() << ", " << vector.z() << ')';
1063 return dbg;
1064}
1065
1066#endif
1067
1068#ifndef QT_NO_DATASTREAM
1069
1070/*!
1071 \fn QDataStream &operator<<(QDataStream &stream, QVector3D vector)
1072 \relates QVector3D
1073
1074 Writes the given \a vector to the given \a stream and returns a
1075 reference to the stream.
1076
1077 \sa {Serializing Qt Data Types}
1078*/
1079
1080QDataStream &operator<<(QDataStream &stream, QVector3D vector)
1081{
1082 stream << vector.x() << vector.y() << vector.z();
1083 return stream;
1084}
1085
1086/*!
1087 \fn QDataStream &operator>>(QDataStream &stream, QVector3D &vector)
1088 \relates QVector3D
1089
1090 Reads a 3D vector from the given \a stream into the given \a vector
1091 and returns a reference to the stream.
1092
1093 \sa {Serializing Qt Data Types}
1094*/
1095
1096QDataStream &operator>>(QDataStream &stream, QVector3D &vector)
1097{
1098 float x, y, z;
1099 stream >> x;
1100 stream >> y;
1101 stream >> z;
1102 vector.setX(x);
1103 vector.setY(y);
1104 vector.setZ(z);
1105 return stream;
1106}
1107
1108#endif // QT_NO_DATASTREAM
1109
1110#endif // QT_NO_VECTOR3D
1111
1112
1113
1114#ifndef QT_NO_VECTOR4D
1115
1116/*!
1117 \class QVector4D
1118 \brief The QVector4D class represents a vector or vertex in 4D space.
1119 \since 4.6
1120 \ingroup painting-3D
1121 \inmodule QtGui
1122
1123 Vectors are one of the main building blocks of 4D affine representations of
1124 3D space. They consist of four finite floating-point coordinates,
1125 traditionally called x, y, z and w.
1126
1127 The QVector4D class can also be used to represent vertices in 4D space.
1128 We therefore do not need to provide a separate vertex class.
1129
1130 \sa QQuaternion, QVector2D, QVector3D
1131*/
1132
1133/*!
1134 \fn QVector4D::QVector4D()
1135
1136 Constructs a null vector, i.e. with coordinates (0, 0, 0, 0).
1137*/
1138
1139/*!
1140 \fn QVector4D::QVector4D(Qt::Initialization)
1141 \since 5.5
1142 \internal
1143
1144 Constructs a vector without initializing the contents.
1145*/
1146
1147/*!
1148 \fn QVector4D::QVector4D(float xpos, float ypos, float zpos, float wpos)
1149
1150 Constructs a vector with coordinates (\a xpos, \a ypos, \a zpos, \a wpos).
1151 All parameters must be finite.
1152*/
1153
1154/*!
1155 \fn QVector4D::QVector4D(QPoint point)
1156
1157 Constructs a vector with x and y coordinates from a 2D \a point, and
1158 z and w coordinates of 0.
1159*/
1160
1161/*!
1162 \fn QVector4D::QVector4D(QPointF point)
1163
1164 Constructs a vector with x and y coordinates from a 2D \a point, and
1165 z and w coordinates of 0.
1166*/
1167
1168#ifndef QT_NO_VECTOR2D
1169
1170/*!
1171 \fn QVector4D::QVector4D(QVector2D vector)
1172
1173 Constructs a 4D vector from the specified 2D \a vector. The z
1174 and w coordinates are set to zero.
1175
1176 \sa toVector2D()
1177*/
1178
1179/*!
1180 \fn QVector4D::QVector4D(QVector2D vector, float zpos, float wpos)
1181
1182 Constructs a 4D vector from the specified 2D \a vector. The z
1183 and w coordinates are set to \a zpos and \a wpos respectively,
1184 each of which must be finite.
1185
1186 \sa toVector2D()
1187*/
1188
1189#endif
1190
1191#ifndef QT_NO_VECTOR3D
1192
1193/*!
1194 \fn QVector4D::QVector4D(QVector3D vector)
1195
1196 Constructs a 4D vector from the specified 3D \a vector. The w
1197 coordinate is set to zero.
1198
1199 \sa toVector3D()
1200*/
1201
1202/*!
1203 \fn QVector4D::QVector4D(QVector3D vector, float wpos)
1204
1205 Constructs a 4D vector from the specified 3D \a vector. The w
1206 coordinate is set to \a wpos, which must be finite.
1207
1208 \sa toVector3D()
1209*/
1210
1211#endif
1212
1213/*!
1214 \fn bool QVector4D::isNull() const
1215
1216 Returns \c true if the x, y, z, and w coordinates are set to 0.0,
1217 otherwise returns \c false.
1218*/
1219
1220/*!
1221 \fn float QVector4D::x() const
1222
1223 Returns the x coordinate of this point.
1224
1225 \sa setX(), y(), z(), w()
1226*/
1227
1228/*!
1229 \fn float QVector4D::y() const
1230
1231 Returns the y coordinate of this point.
1232
1233 \sa setY(), x(), z(), w()
1234*/
1235
1236/*!
1237 \fn float QVector4D::z() const
1238
1239 Returns the z coordinate of this point.
1240
1241 \sa setZ(), x(), y(), w()
1242*/
1243
1244/*!
1245 \fn float QVector4D::w() const
1246
1247 Returns the w coordinate of this point.
1248
1249 \sa setW(), x(), y(), z()
1250*/
1251
1252/*!
1253 \fn void QVector4D::setX(float x)
1254
1255 Sets the x coordinate of this point to the given finite \a x coordinate.
1256
1257 \sa x(), setY(), setZ(), setW()
1258*/
1259
1260/*!
1261 \fn void QVector4D::setY(float y)
1262
1263 Sets the y coordinate of this point to the given finite \a y coordinate.
1264
1265 \sa y(), setX(), setZ(), setW()
1266*/
1267
1268/*!
1269 \fn void QVector4D::setZ(float z)
1270
1271 Sets the z coordinate of this point to the given finite \a z coordinate.
1272
1273 \sa z(), setX(), setY(), setW()
1274*/
1275
1276/*!
1277 \fn void QVector4D::setW(float w)
1278
1279 Sets the w coordinate of this point to the given finite \a w coordinate.
1280
1281 \sa w(), setX(), setY(), setZ()
1282*/
1283
1284/*! \fn float &QVector4D::operator[](int i)
1285 \since 5.2
1286
1287 Returns the component of the vector at index position \a i
1288 as a modifiable reference.
1289
1290 \a i must be a valid index position in the vector (i.e., 0 <= \a i
1291 < 4).
1292*/
1293
1294/*! \fn float QVector4D::operator[](int i) const
1295 \since 5.2
1296
1297 Returns the component of the vector at index position \a i.
1298
1299 \a i must be a valid index position in the vector (i.e., 0 <= \a i
1300 < 4).
1301*/
1302
1303/*!
1304 \fn float QVector4D::length() const
1305
1306 Returns the length of the vector from the origin.
1307
1308 \sa lengthSquared(), normalized()
1309*/
1310
1311/*!
1312 \fn float QVector4D::lengthSquared() const
1313
1314 Returns the squared length of the vector from the origin.
1315 This is equivalent to the dot product of the vector with itself.
1316
1317 \sa length(), dotProduct()
1318*/
1319
1320/*!
1321 \fn QVector4D QVector4D::normalized() const
1322
1323 Returns the normalized unit vector form of this vector.
1324
1325 If this vector is null, then a null vector is returned. If the length
1326 of the vector is very close to 1, then the vector will be returned as-is.
1327 Otherwise the normalized form of the vector of length 1 will be returned.
1328
1329 \sa length(), normalize()
1330*/
1331
1332/*!
1333 \fn void QVector4D::normalize()
1334
1335 Normalizes the current vector in place. Nothing happens if this
1336 vector is a null vector or the length of the vector is very close to 1.
1337
1338 \sa length(), normalized()
1339*/
1340
1341
1342/*!
1343 \fn QVector4D &QVector4D::operator+=(QVector4D vector)
1344
1345 Adds the given \a vector to this vector and returns a reference to
1346 this vector.
1347
1348 \sa operator-=()
1349*/
1350
1351/*!
1352 \fn QVector4D &QVector4D::operator-=(QVector4D vector)
1353
1354 Subtracts the given \a vector from this vector and returns a reference to
1355 this vector.
1356
1357 \sa operator+=()
1358*/
1359
1360/*!
1361 \fn QVector4D &QVector4D::operator*=(float factor)
1362
1363 Multiplies this vector's coordinates by the given finite \a factor, and
1364 returns a reference to this vector.
1365
1366 \sa operator/=(), operator*()
1367*/
1368
1369/*!
1370 \fn QVector4D &QVector4D::operator*=(QVector4D vector)
1371
1372 Multiplies each component of this vector by the corresponding component of
1373 \a vector and returns a reference to this vector.
1374
1375 \sa operator/=(), operator*()
1376*/
1377
1378/*!
1379 \fn QVector4D &QVector4D::operator/=(float divisor)
1380
1381 Divides this vector's coordinates by the given \a divisor, and returns a
1382 reference to this vector. The \a divisor must not be either zero or NaN.
1383
1384 \sa operator*=()
1385*/
1386
1387/*!
1388 \fn QVector4D &QVector4D::operator/=(QVector4D vector)
1389 \since 5.5
1390
1391 Divides each component of this vector by the corresponding component of \a
1392 vector and returns a reference to this vector.
1393
1394 The \a vector must have no component that is either zero or NaN.
1395
1396 \sa operator*=(), operator/()
1397*/
1398
1399/*!
1400 \fn float QVector4D::dotProduct(QVector4D v1, QVector4D v2)
1401
1402 Returns the dot product of \a v1 and \a v2.
1403*/
1404
1405/*!
1406 \fn bool QVector4D::operator==(QVector4D v1, QVector4D v2)
1407
1408 Returns \c true if \a v1 is equal to \a v2; otherwise returns \c false.
1409 This operator uses an exact floating-point comparison.
1410*/
1411
1412/*!
1413 \fn bool QVector4D::operator!=(QVector4D v1, QVector4D v2)
1414
1415 Returns \c true if \a v1 is not equal to \a v2; otherwise returns \c false.
1416 This operator uses an exact floating-point comparison.
1417*/
1418
1419/*! //! friend
1420 \fn const QVector4D QVector4D::operator+(QVector4D v1, QVector4D v2)
1421
1422 Returns a QVector4D object that is the sum of the given vectors, \a v1
1423 and \a v2; each component is added separately.
1424
1425 \sa QVector4D::operator+=()
1426*/
1427
1428/*! //! friend
1429 \fn const QVector4D QVector4D::operator-(QVector4D v1, QVector4D v2)
1430
1431 Returns a QVector4D object that is formed by subtracting \a v2 from \a v1;
1432 each component is subtracted separately.
1433
1434 \sa QVector4D::operator-=()
1435*/
1436
1437/*! //! friend
1438 \fn const QVector4D QVector4D::operator*(float factor, QVector4D vector)
1439
1440 Returns a copy of the given \a vector, multiplied by the given \a factor.
1441
1442 \sa QVector4D::operator*=()
1443*/
1444
1445/*! //! friend
1446 \fn const QVector4D QVector4D::operator*(QVector4D vector, float factor)
1447
1448 Returns a copy of the given \a vector, multiplied by the given \a factor.
1449
1450 \sa QVector4D::operator*=()
1451*/
1452
1453/*! //! friend
1454 \fn const QVector4D QVector4D::operator*(QVector4D v1, QVector4D v2)
1455
1456 Returns the QVector4D object formed by multiplying each component of \a v1
1457 by the corresponding component of \a v2.
1458
1459 \note This is not a cross product of \a v1 and \a v2 in any sense.
1460 (Its components add up to the dot product of \a v1 and \a v2.)
1461
1462 \sa QVector4D::operator*=()
1463*/
1464
1465/*! //! friend
1466 \fn const QVector4D QVector4D::operator-(QVector4D vector)
1467 \overload
1468
1469 Returns a QVector4D object that is formed by changing the sign of
1470 all three components of the given \a vector.
1471
1472 Equivalent to \c {QVector4D(0,0,0,0) - vector}.
1473*/
1474
1475/*! //! friend
1476 \fn const QVector4D QVector4D::operator/(QVector4D vector, float divisor)
1477
1478 Returns the QVector4D object formed by dividing each component of the given
1479 \a vector by the given \a divisor.
1480
1481 The \a divisor must not be either zero or NaN.
1482
1483 \sa QVector4D::operator/=()
1484*/
1485
1486/*! //! friend
1487 \fn const QVector4D QVector4D::operator/(QVector4D vector, QVector4D divisor)
1488 \since 5.5
1489
1490 Returns the QVector4D object formed by dividing each component of the given
1491 \a vector by the corresponding component of the given \a divisor.
1492
1493 The \a divisor must have no component that is either zero or NaN.
1494
1495 \sa QVector4D::operator/=()
1496*/
1497
1498/*! //! friend
1499 \fn bool QVector4D::qFuzzyCompare(QVector4D v1, QVector4D v2)
1500
1501 Returns \c true if \a v1 and \a v2 are equal, allowing for a small
1502 fuzziness factor for floating-point comparisons; false otherwise.
1503*/
1504bool qFuzzyCompare(QVector4D v1, QVector4D v2) noexcept
1505{
1506 return QtPrivate::fuzzyCompare(v1.v[0], v2.v[0])
1507 && QtPrivate::fuzzyCompare(v1.v[1], v2.v[1])
1508 && QtPrivate::fuzzyCompare(v1.v[2], v2.v[2])
1509 && QtPrivate::fuzzyCompare(v1.v[3], v2.v[3]);
1510}
1511
1512#ifndef QT_NO_VECTOR2D
1513
1514/*!
1515 \fn QVector2D QVector4D::toVector2D() const
1516
1517 Returns the 2D vector form of this 4D vector, dropping the z and w coordinates.
1518
1519 \sa toVector2DAffine(), toVector3D(), toPoint()
1520*/
1521
1522/*!
1523 \fn QVector2D QVector4D::toVector2DAffine() const
1524
1525 Returns the 2D vector form of this 4D vector, dividing the x and y
1526 coordinates by the w coordinate and dropping the z coordinate.
1527 Returns a null vector if w is zero.
1528
1529 \sa toVector2D(), toVector3DAffine(), toPoint()
1530*/
1531
1532#endif
1533
1534#ifndef QT_NO_VECTOR3D
1535
1536/*!
1537 \fn QVector3D QVector4D::toVector3D() const
1538
1539 Returns the 3D vector form of this 4D vector, dropping the w coordinate.
1540
1541 \sa toVector3DAffine(), toVector2D(), toPoint()
1542*/
1543
1544/*!
1545 \fn QVector3D QVector4D::toVector3DAffine() const
1546
1547 Returns the 3D vector form of this 4D vector, dividing the x, y, and
1548 z coordinates by the w coordinate. Returns a null vector if w is zero.
1549
1550 \sa toVector3D(), toVector2DAffine(), toPoint()
1551*/
1552
1553#endif
1554
1555/*!
1556 \fn QPoint QVector4D::toPoint() const
1557
1558 Returns the QPoint form of this 4D vector. The z and w coordinates are
1559 dropped. The x and y coordinates are rounded to nearest integers.
1560
1561 \sa toPointF(), toVector2D()
1562*/
1563
1564/*!
1565 \fn QPointF QVector4D::toPointF() const
1566
1567 Returns the QPointF form of this 4D vector. The z and w coordinates
1568 are dropped.
1569
1570 \sa toPoint(), toVector2D()
1571*/
1572
1573/*!
1574 Returns the 4D vector as a QVariant.
1575*/
1576QVector4D::operator QVariant() const
1577{
1578 return QVariant::fromValue(*this);
1579}
1580
1581#ifndef QT_NO_DEBUG_STREAM
1582
1583QDebug operator<<(QDebug dbg, QVector4D vector)
1584{
1585 QDebugStateSaver saver(dbg);
1586 dbg.nospace() << "QVector4D("
1587 << vector.x() << ", " << vector.y() << ", "
1588 << vector.z() << ", " << vector.w() << ')';
1589 return dbg;
1590}
1591
1592#endif
1593
1594#ifndef QT_NO_DATASTREAM
1595
1596/*!
1597 \fn QDataStream &operator<<(QDataStream &stream, QVector4D vector)
1598 \relates QVector4D
1599
1600 Writes the given \a vector to the given \a stream and returns a
1601 reference to the stream.
1602
1603 \sa {Serializing Qt Data Types}
1604*/
1605
1606QDataStream &operator<<(QDataStream &stream, QVector4D vector)
1607{
1608 stream << vector.x() << vector.y()
1609 << vector.z() << vector.w();
1610 return stream;
1611}
1612
1613/*!
1614 \fn QDataStream &operator>>(QDataStream &stream, QVector4D &vector)
1615 \relates QVector4D
1616
1617 Reads a 4D vector from the given \a stream into the given \a vector
1618 and returns a reference to the stream.
1619
1620 \sa {Serializing Qt Data Types}
1621*/
1622
1623QDataStream &operator>>(QDataStream &stream, QVector4D &vector)
1624{
1625 float x, y, z, w;
1626 stream >> x;
1627 stream >> y;
1628 stream >> z;
1629 stream >> w;
1630 vector.setX(x);
1631 vector.setY(y);
1632 vector.setZ(z);
1633 vector.setW(w);
1634 return stream;
1635}
1636
1637#endif // QT_NO_DATASTREAM
1638
1639#endif // QT_NO_VECTOR4D
1640
1641QT_END_NAMESPACE
The QVector2D class represents a vector or vertex in 2D space.
Definition qvectornd.h:32
constexpr float y() const noexcept
Returns the y coordinate of this point.
Definition qvectornd.h:503
constexpr float x() const noexcept
Returns the x coordinate of this point.
Definition qvectornd.h:502
constexpr void setY(float y) noexcept
Sets the y coordinate of this point to the given finite y coordinate.
Definition qvectornd.h:506
constexpr void setX(float x) noexcept
Sets the x coordinate of this point to the given finite x coordinate.
Definition qvectornd.h:505
The QVector3D class represents a vector or vertex in 3D space.
Definition qvectornd.h:172
constexpr void setX(float x) noexcept
Sets the x coordinate of this point to the given finite x coordinate.
Definition qvectornd.h:675
constexpr void setY(float y) noexcept
Sets the y coordinate of this point to the given finite y coordinate.
Definition qvectornd.h:676
constexpr float y() const noexcept
Returns the y coordinate of this point.
Definition qvectornd.h:672
constexpr float x() const noexcept
Returns the x coordinate of this point.
Definition qvectornd.h:671
constexpr void setZ(float z) noexcept
Sets the z coordinate of this point to the given finite z coordinate.
Definition qvectornd.h:677
constexpr float z() const noexcept
Returns the z coordinate of this point.
Definition qvectornd.h:673
The QVector4D class represents a vector or vertex in 4D space.
Definition qvectornd.h:331
constexpr void setZ(float z) noexcept
Sets the z coordinate of this point to the given finite z coordinate.
Definition qvectornd.h:886
constexpr float x() const noexcept
Returns the x coordinate of this point.
Definition qvectornd.h:879
constexpr void setY(float y) noexcept
Sets the y coordinate of this point to the given finite y coordinate.
Definition qvectornd.h:885
constexpr float w() const noexcept
Returns the w coordinate of this point.
Definition qvectornd.h:882
constexpr void setX(float x) noexcept
Sets the x coordinate of this point to the given finite x coordinate.
Definition qvectornd.h:884
constexpr QVector4D & operator/=(float divisor)
Divides this vector's coordinates by the given divisor, and returns a reference to this vector.
Definition qvectornd.h:966
constexpr QVector4D(QVector3D vector, float wpos) noexcept
Constructs a 4D vector from the specified 3D vector.
Definition qvectornd.h:871
constexpr float y() const noexcept
Returns the y coordinate of this point.
Definition qvectornd.h:880
constexpr QVector3D toVector3D() const noexcept
Returns the 3D vector form of this 4D vector, dropping the w coordinate.
Definition qvectornd.h:1012
constexpr float z() const noexcept
Returns the z coordinate of this point.
Definition qvectornd.h:881
constexpr void setW(float w) noexcept
Sets the w coordinate of this point to the given finite w coordinate.
Definition qvectornd.h:887
QDataStream & operator<<(QDataStream &stream, QVector2D vector)
QDataStream & operator<<(QDataStream &stream, QVector3D vector)
QDataStream & operator>>(QDataStream &stream, QVector2D &vector)
QDataStream & operator<<(QDataStream &stream, QVector4D vector)
QDebug operator<<(QDebug dbg, QVector2D vector)
bool qFuzzyCompare(QVector4D v1, QVector4D v2) noexcept
bool qFuzzyCompare(QVector3D v1, QVector3D v2) noexcept
QDebug operator<<(QDebug dbg, QVector4D vector)
QDebug operator<<(QDebug dbg, QVector3D vector)
QDataStream & operator>>(QDataStream &stream, QVector3D &vector)
QDataStream & operator>>(QDataStream &stream, QVector4D &vector)
bool qFuzzyCompare(QVector2D v1, QVector2D v2) noexcept