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