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.h
Go to the documentation of this file.
1// Copyright (C) 2020 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#ifndef QVECTORND_H
7#define QVECTORND_H
8
9#include <QtGui/qtguiglobal.h>
10
11#include <QtCore/qhashfunctions.h>
12#include <QtCore/qpoint.h>
13#include <QtCore/qrect.h>
14#include <QtCore/qmath.h>
15
16#include <QtCore/q20type_traits.h>
17#include <QtCore/q23utility.h>
18
19QT_BEGIN_NAMESPACE
20
21// QT_ENABLE_P0846_SEMANTICS_FOR(get) // from qpoint.h
22
23#define QVECTORND_IS_HASHABLE
24
25class QVector2D;
26class QVector3D;
27class QVector4D;
28class QMatrix4x4;
29class QVariant;
30
31/***************************** QVector2D *****************************/
32
33#ifndef QT_NO_VECTOR2D
34
36{
37public:
38 constexpr QVector2D() noexcept;
39 explicit QVector2D(Qt::Initialization) noexcept {}
40 constexpr QVector2D(float xpos, float ypos) noexcept;
41 constexpr explicit QVector2D(QPoint point) noexcept;
42 constexpr explicit QVector2D(QPointF point) noexcept;
43#ifndef QT_NO_VECTOR3D
44 constexpr explicit QVector2D(QVector3D vector) noexcept;
45#endif
46#ifndef QT_NO_VECTOR4D
47 constexpr explicit QVector2D(QVector4D vector) noexcept;
48#endif
49
50 constexpr bool isNull() const noexcept;
51
52 constexpr float x() const noexcept;
53 constexpr float y() const noexcept;
54
55 constexpr void setX(float x) noexcept;
56 constexpr void setY(float y) noexcept;
57
58 constexpr float &operator[](int i);
59 constexpr float operator[](int i) const;
60
61 [[nodiscard]] float length() const noexcept;
62 [[nodiscard]] constexpr float lengthSquared() const noexcept;
63
64 [[nodiscard]] QVector2D normalized() const noexcept;
65 void normalize() noexcept;
66
67 [[nodiscard]] float distanceToPoint(QVector2D point) const noexcept;
68 [[nodiscard]] float distanceToLine(QVector2D point, QVector2D direction) const noexcept;
69
70 constexpr QVector2D &operator+=(QVector2D vector) noexcept;
71 constexpr QVector2D &operator-=(QVector2D vector) noexcept;
72 constexpr QVector2D &operator*=(float factor) noexcept;
73 constexpr QVector2D &operator*=(QVector2D vector) noexcept;
74 constexpr QVector2D &operator/=(float divisor);
75 constexpr QVector2D &operator/=(QVector2D vector);
76
77 [[nodiscard]] static constexpr float dotProduct(QVector2D v1, QVector2D v2) noexcept;
78
79QT_WARNING_PUSH
80QT_WARNING_DISABLE_FLOAT_COMPARE
81 constexpr friend inline bool operator==(QVector2D v1, QVector2D v2) noexcept
82 {
83 return v1.v[0] == v2.v[0] && v1.v[1] == v2.v[1];
84 }
85
86 constexpr friend inline bool operator!=(QVector2D v1, QVector2D v2) noexcept
87 {
88 return v1.v[0] != v2.v[0] || v1.v[1] != v2.v[1];
89 }
91 constexpr friend size_t qHash(QVector2D key, size_t seed = 0) noexcept
92 {
93 return qHashMulti(seed, key.x(), key.y());
94 }
95
96 constexpr friend inline QVector2D operator+(QVector2D v1, QVector2D v2) noexcept
97 {
98 return QVector2D(v1.v[0] + v2.v[0], v1.v[1] + v2.v[1]);
99 }
100
101 constexpr friend inline QVector2D operator-(QVector2D v1, QVector2D v2) noexcept
102 {
103 return QVector2D(v1.v[0] - v2.v[0], v1.v[1] - v2.v[1]);
104 }
105
106 constexpr friend inline QVector2D operator*(float factor, QVector2D vector) noexcept
107 {
108 return QVector2D(vector.v[0] * factor, vector.v[1] * factor);
109 }
110
111 constexpr friend inline QVector2D operator*(QVector2D vector, float factor) noexcept
112 {
113 return QVector2D(vector.v[0] * factor, vector.v[1] * factor);
114 }
115
116 constexpr friend inline QVector2D operator*(QVector2D v1, QVector2D v2) noexcept
117 {
118 return QVector2D(v1.v[0] * v2.v[0], v1.v[1] * v2.v[1]);
119 }
120
121 constexpr friend inline QVector2D operator-(QVector2D vector) noexcept
122 {
123 return QVector2D(-vector.v[0], -vector.v[1]);
124 }
125
126 constexpr friend inline QVector2D operator/(QVector2D vector, float divisor)
127 {
128 Q_ASSERT(divisor < 0 || divisor > 0);
129 return QVector2D(vector.v[0] / divisor, vector.v[1] / divisor);
130 }
131
133 {
134 Q_ASSERT(divisor.v[0] < 0 || divisor.v[0] > 0);
135 Q_ASSERT(divisor.v[1] < 0 || divisor.v[1] > 0);
136 return QVector2D(vector.v[0] / divisor.v[0], vector.v[1] / divisor.v[1]);
137 }
138
139 friend Q_GUI_EXPORT bool qFuzzyCompare(QVector2D v1, QVector2D v2) noexcept;
140
141#ifndef QT_NO_VECTOR3D
142 constexpr QVector3D toVector3D() const noexcept;
143#endif
144#ifndef QT_NO_VECTOR4D
145 constexpr QVector4D toVector4D() const noexcept;
146#endif
147
148 constexpr QPoint toPoint() const noexcept;
149 constexpr QPointF toPointF() const noexcept;
150
152
153private:
154 float v[2];
155
156 friend class QVector3D;
157 friend class QVector4D;
158
159 template <std::size_t I,
160 typename V,
161 std::enable_if_t<(I < 2), bool> = true,
163 friend constexpr decltype(auto) get(V &&vec) noexcept
164 {
165 return q23::forward_like<V>(vec.v[I]);
166 }
167};
168
170
171#endif // QT_NO_VECTOR2D
172
173
174
175/***************************** QVector3D *****************************/
176
177#ifndef QT_NO_VECTOR3D
178
180{
181public:
182 constexpr QVector3D() noexcept;
183 explicit QVector3D(Qt::Initialization) noexcept {}
184 constexpr QVector3D(float xpos, float ypos, float zpos) noexcept : v{xpos, ypos, zpos} {}
185
186 constexpr explicit QVector3D(QPoint point) noexcept;
187 constexpr explicit QVector3D(QPointF point) noexcept;
188#ifndef QT_NO_VECTOR2D
189 constexpr explicit QVector3D(QVector2D vector) noexcept;
190 constexpr QVector3D(QVector2D vector, float zpos) noexcept;
191#endif
192#ifndef QT_NO_VECTOR4D
193 constexpr explicit QVector3D(QVector4D vector) noexcept;
194#endif
195
196 constexpr bool isNull() const noexcept;
197
198 constexpr float x() const noexcept;
199 constexpr float y() const noexcept;
200 constexpr float z() const noexcept;
201
202 constexpr void setX(float x) noexcept;
203 constexpr void setY(float y) noexcept;
204 constexpr void setZ(float z) noexcept;
205
206 constexpr float &operator[](int i);
207 constexpr float operator[](int i) const;
208
209 [[nodiscard]] float length() const noexcept;
210 [[nodiscard]] constexpr float lengthSquared() const noexcept;
211
212 [[nodiscard]] QVector3D normalized() const noexcept;
213 void normalize() noexcept;
214
215 constexpr QVector3D &operator+=(QVector3D vector) noexcept;
216 constexpr QVector3D &operator-=(QVector3D vector) noexcept;
217 constexpr QVector3D &operator*=(float factor) noexcept;
218 constexpr QVector3D &operator*=(QVector3D vector) noexcept;
219 constexpr QVector3D &operator/=(float divisor);
220 constexpr QVector3D &operator/=(QVector3D vector);
221
222 [[nodiscard]] static constexpr float dotProduct(QVector3D v1, QVector3D v2) noexcept;
223 [[nodiscard]] static constexpr QVector3D crossProduct(QVector3D v1, QVector3D v2) noexcept;
224
225 [[nodiscard]] static QVector3D normal(QVector3D v1, QVector3D v2) noexcept;
226 [[nodiscard]] static QVector3D normal(QVector3D v1, QVector3D v2, QVector3D v3) noexcept;
227
230
231QT_WARNING_PUSH
232QT_WARNING_DISABLE_FLOAT_COMPARE
233 constexpr friend inline bool operator==(QVector3D v1, QVector3D v2) noexcept
234 {
235 return v1.v[0] == v2.v[0] && v1.v[1] == v2.v[1] && v1.v[2] == v2.v[2];
236 }
237
238 constexpr friend inline bool operator!=(QVector3D v1, QVector3D v2) noexcept
239 {
240 return v1.v[0] != v2.v[0] || v1.v[1] != v2.v[1] || v1.v[2] != v2.v[2];
241 }
243 constexpr friend size_t qHash(QVector3D key, size_t seed = 0) noexcept
244 {
245 return qHashMulti(seed, key.x(), key.y(), key.z());
246 }
247 float distanceToPoint(QVector3D point) const noexcept;
248 constexpr float distanceToPlane(QVector3D plane, QVector3D normal) const noexcept;
249 float distanceToPlane(QVector3D plane1, QVector3D plane2, QVector3D plane3) const noexcept;
250 float distanceToLine(QVector3D point, QVector3D direction) const noexcept;
251
252
253 constexpr friend inline QVector3D operator+(QVector3D v1, QVector3D v2) noexcept
254 {
255 return QVector3D(v1.v[0] + v2.v[0], v1.v[1] + v2.v[1], v1.v[2] + v2.v[2]);
256 }
257
258 constexpr friend inline QVector3D operator-(QVector3D v1, QVector3D v2) noexcept
259 {
260 return QVector3D(v1.v[0] - v2.v[0], v1.v[1] - v2.v[1], v1.v[2] - v2.v[2]);
261 }
262
263 constexpr friend inline QVector3D operator*(float factor, QVector3D vector) noexcept
264 {
265 return QVector3D(vector.v[0] * factor, vector.v[1] * factor, vector.v[2] * factor);
266 }
267
268 constexpr friend inline QVector3D operator*(QVector3D vector, float factor) noexcept
269 {
270 return QVector3D(vector.v[0] * factor, vector.v[1] * factor, vector.v[2] * factor);
271 }
272
273 constexpr friend inline QVector3D operator*(QVector3D v1, QVector3D v2) noexcept
274 {
275 return QVector3D(v1.v[0] * v2.v[0], v1.v[1] * v2.v[1], v1.v[2] * v2.v[2]);
276 }
277
278 constexpr friend inline QVector3D operator-(QVector3D vector) noexcept
279 {
280 return QVector3D(-vector.v[0], -vector.v[1], -vector.v[2]);
281 }
282
283 constexpr friend inline QVector3D operator/(QVector3D vector, float divisor)
284 {
285 Q_ASSERT(divisor < 0 || divisor > 0);
286 return QVector3D(vector.v[0] / divisor, vector.v[1] / divisor, vector.v[2] / divisor);
287 }
288
289 constexpr friend inline QVector3D operator/(QVector3D vector, QVector3D divisor)
290 {
291 Q_ASSERT(divisor.v[0] > 0 || divisor.v[0] < 0);
292 Q_ASSERT(divisor.v[1] > 0 || divisor.v[1] < 0);
293 Q_ASSERT(divisor.v[2] > 0 || divisor.v[2] < 0);
294 return QVector3D(vector.v[0] / divisor.v[0], vector.v[1] / divisor.v[1],
295 vector.v[2] / divisor.v[2]);
296 }
297
298 friend Q_GUI_EXPORT bool qFuzzyCompare(QVector3D v1, QVector3D v2) noexcept;
299
300#ifndef QT_NO_VECTOR2D
301 constexpr QVector2D toVector2D() const noexcept;
302#endif
303#ifndef QT_NO_VECTOR4D
304 constexpr QVector4D toVector4D() const noexcept;
305#endif
306
307 constexpr QPoint toPoint() const noexcept;
308 constexpr QPointF toPointF() const noexcept;
309
311
312private:
313 float v[3];
314
315 friend class QVector2D;
316 friend class QVector4D;
317#ifndef QT_NO_MATRIX4X4
318 friend QVector3D operator*(const QVector3D& vector, const QMatrix4x4& matrix);
319 friend QVector3D operator*(const QMatrix4x4& matrix, const QVector3D& vector);
320#endif
321
322 template <std::size_t I,
323 typename V,
324 std::enable_if_t<(I < 3), bool> = true,
326 friend constexpr decltype(auto) get(V &&vec) noexcept
327 {
328 return q23::forward_like<V>(vec.v[I]);
329 }
330};
331
333
334#endif // QT_NO_VECTOR3D
335
336
337
338/***************************** QVector4D *****************************/
339
340#ifndef QT_NO_VECTOR4D
341
343{
344public:
345 constexpr QVector4D() noexcept;
346 explicit QVector4D(Qt::Initialization) noexcept {}
347 constexpr QVector4D(float xpos, float ypos, float zpos, float wpos) noexcept;
348 constexpr explicit QVector4D(QPoint point) noexcept;
349 constexpr explicit QVector4D(QPointF point) noexcept;
350#ifndef QT_NO_VECTOR2D
351 constexpr explicit QVector4D(QVector2D vector) noexcept;
352 constexpr QVector4D(QVector2D vector, float zpos, float wpos) noexcept;
353#endif
354#ifndef QT_NO_VECTOR3D
355 constexpr explicit QVector4D(QVector3D vector) noexcept;
356 constexpr QVector4D(QVector3D vector, float wpos) noexcept;
357#endif
358
359 constexpr bool isNull() const noexcept;
360
361 constexpr float x() const noexcept;
362 constexpr float y() const noexcept;
363 constexpr float z() const noexcept;
364 constexpr float w() const noexcept;
365
366 constexpr void setX(float x) noexcept;
367 constexpr void setY(float y) noexcept;
368 constexpr void setZ(float z) noexcept;
369 constexpr void setW(float w) noexcept;
370
371 constexpr float &operator[](int i);
372 constexpr float operator[](int i) const;
373
374 [[nodiscard]] float length() const noexcept;
375 [[nodiscard]] constexpr float lengthSquared() const noexcept;
376
377 [[nodiscard]] QVector4D normalized() const noexcept;
378 void normalize() noexcept;
379
380 constexpr QVector4D &operator+=(QVector4D vector) noexcept;
381 constexpr QVector4D &operator-=(QVector4D vector) noexcept;
382 constexpr QVector4D &operator*=(float factor) noexcept;
383 constexpr QVector4D &operator*=(QVector4D vector) noexcept;
384 constexpr QVector4D &operator/=(float divisor);
385 constexpr inline QVector4D &operator/=(QVector4D vector);
386
387 [[nodiscard]] static constexpr float dotProduct(QVector4D v1, QVector4D v2) noexcept;
388
389QT_WARNING_PUSH
390QT_WARNING_DISABLE_FLOAT_COMPARE
391 constexpr friend inline bool operator==(QVector4D v1, QVector4D v2) noexcept
392 {
393 return v1.v[0] == v2.v[0] && v1.v[1] == v2.v[1] && v1.v[2] == v2.v[2] && v1.v[3] == v2.v[3];
394 }
395
396 constexpr friend inline bool operator!=(QVector4D v1, QVector4D v2) noexcept
397 {
398 return v1.v[0] != v2.v[0] || v1.v[1] != v2.v[1] || v1.v[2] != v2.v[2] || v1.v[3] != v2.v[3];
399 }
401 constexpr friend size_t qHash(QVector4D key, size_t seed = 0) noexcept
402 {
403 return qHashMulti(seed, key.x(), key.y(), key.z(), key.w());
404 }
405
406 constexpr friend inline QVector4D operator+(QVector4D v1, QVector4D v2) noexcept
407 {
408 return QVector4D(v1.v[0] + v2.v[0], v1.v[1] + v2.v[1], v1.v[2] + v2.v[2], v1.v[3] + v2.v[3]);
409 }
410
411 constexpr friend inline QVector4D operator-(QVector4D v1, QVector4D v2) noexcept
412 {
413 return QVector4D(v1.v[0] - v2.v[0], v1.v[1] - v2.v[1], v1.v[2] - v2.v[2], v1.v[3] - v2.v[3]);
414 }
415
416 constexpr friend inline QVector4D operator*(float factor, QVector4D vector) noexcept
417 {
418 return QVector4D(vector.v[0] * factor, vector.v[1] * factor, vector.v[2] * factor, vector.v[3] * factor);
419 }
420
421 constexpr friend inline QVector4D operator*(QVector4D vector, float factor) noexcept
422 {
423 return QVector4D(vector.v[0] * factor, vector.v[1] * factor, vector.v[2] * factor, vector.v[3] * factor);
424 }
425
426 constexpr friend inline QVector4D operator*(QVector4D v1, QVector4D v2) noexcept
427 {
428 return QVector4D(v1.v[0] * v2.v[0], v1.v[1] * v2.v[1], v1.v[2] * v2.v[2], v1.v[3] * v2.v[3]);
429 }
430
431 constexpr friend inline QVector4D operator-(QVector4D vector) noexcept
432 {
433 return QVector4D(-vector.v[0], -vector.v[1], -vector.v[2], -vector.v[3]);
434 }
435
436 constexpr friend inline QVector4D operator/(QVector4D vector, float divisor)
437 {
438 Q_ASSERT(divisor < 0 || divisor > 0);
439 return QVector4D(vector.v[0] / divisor, vector.v[1] / divisor, vector.v[2] / divisor, vector.v[3] / divisor);
440 }
441
443 {
444 Q_ASSERT(divisor.v[0] > 0 || divisor.v[0] < 0);
445 Q_ASSERT(divisor.v[1] > 0 || divisor.v[1] < 0);
446 Q_ASSERT(divisor.v[2] > 0 || divisor.v[2] < 0);
447 Q_ASSERT(divisor.v[3] > 0 || divisor.v[3] < 0);
448 return QVector4D(vector.v[0] / divisor.v[0], vector.v[1] / divisor.v[1],
449 vector.v[2] / divisor.v[2], vector.v[3] / divisor.v[3]);
450 }
451
452 friend Q_GUI_EXPORT bool qFuzzyCompare(QVector4D v1, QVector4D v2) noexcept;
453
454#ifndef QT_NO_VECTOR2D
455 constexpr QVector2D toVector2D() const noexcept;
456 constexpr QVector2D toVector2DAffine() const noexcept;
457#endif
458#ifndef QT_NO_VECTOR3D
459 constexpr QVector3D toVector3D() const noexcept;
460 constexpr QVector3D toVector3DAffine() const noexcept;
461#endif
462
463 constexpr QPoint toPoint() const noexcept;
464 constexpr QPointF toPointF() const noexcept;
465
467
468private:
469 float v[4];
470
471 friend class QVector2D;
472 friend class QVector3D;
473 friend class QMatrix4x4;
474#ifndef QT_NO_MATRIX4X4
475 friend QVector4D operator*(const QVector4D& vector, const QMatrix4x4& matrix);
476 friend QVector4D operator*(const QMatrix4x4& matrix, const QVector4D& vector);
477#endif
478
479 template <std::size_t I,
480 typename V,
481 std::enable_if_t<(I < 4), bool> = true,
483 friend constexpr decltype(auto) get(V &&vec) noexcept
484 {
485 return q23::forward_like<V>(vec.v[I]);
486 }
487};
488
490
491#endif // QT_NO_VECTOR4D
492
493
494
495/***************************** QVector2D *****************************/
496
497#ifndef QT_NO_VECTOR2D
498
499constexpr inline QVector2D::QVector2D() noexcept : v{0.0f, 0.0f} {}
500
501constexpr inline QVector2D::QVector2D(float xpos, float ypos) noexcept : v{xpos, ypos} {}
502
503constexpr inline QVector2D::QVector2D(QPoint point) noexcept : v{float(point.x()), float(point.y())} {}
504
505constexpr inline QVector2D::QVector2D(QPointF point) noexcept : v{float(point.x()), float(point.y())} {}
506
507#ifndef QT_NO_VECTOR3D
508constexpr inline QVector2D::QVector2D(QVector3D vector) noexcept : v{vector[0], vector[1]} {}
509#endif
510#ifndef QT_NO_VECTOR4D
511constexpr inline QVector2D::QVector2D(QVector4D vector) noexcept : v{vector[0], vector[1]} {}
512#endif
513
514constexpr inline bool QVector2D::isNull() const noexcept
515{
516 return qIsNull(v[0]) && qIsNull(v[1]);
517}
518
519constexpr inline float QVector2D::x() const noexcept { return v[0]; }
520constexpr inline float QVector2D::y() const noexcept { return v[1]; }
521
522constexpr inline void QVector2D::setX(float aX) noexcept { v[0] = aX; }
523constexpr inline void QVector2D::setY(float aY) noexcept { v[1] = aY; }
524
525constexpr inline float &QVector2D::operator[](int i)
526{
527 Q_ASSERT(uint(i) < 2u);
528 return v[i];
529}
530
531constexpr inline float QVector2D::operator[](int i) const
532{
533 Q_ASSERT(uint(i) < 2u);
534 return v[i];
535}
536
537inline float QVector2D::length() const noexcept
538{
539 return qHypot(v[0], v[1]);
540}
541
542constexpr inline float QVector2D::lengthSquared() const noexcept
543{
544 return v[0] * v[0] + v[1] * v[1];
545}
546
547inline QVector2D QVector2D::normalized() const noexcept
548{
549 const float len = length();
550 return qFuzzyIsNull(len - 1.0f) ? *this : qFuzzyIsNull(len) ? QVector2D()
551 : QVector2D(v[0] / len, v[1] / len);
552}
553
554inline void QVector2D::normalize() noexcept
555{
556 const float len = length();
557 if (qFuzzyIsNull(len - 1.0f) || qFuzzyIsNull(len))
558 return;
559
560 v[0] /= len;
561 v[1] /= len;
562}
563
564inline float QVector2D::distanceToPoint(QVector2D point) const noexcept
565{
566 return (*this - point).length();
567}
568
569inline float QVector2D::distanceToLine(QVector2D point, QVector2D direction) const noexcept
570{
571 if (direction.isNull())
572 return (*this - point).length();
573 QVector2D p = point + dotProduct(*this - point, direction) * direction;
574 return (*this - p).length();
575}
576
577constexpr inline QVector2D &QVector2D::operator+=(QVector2D vector) noexcept
578{
579 v[0] += vector.v[0];
580 v[1] += vector.v[1];
581 return *this;
582}
583
584constexpr inline QVector2D &QVector2D::operator-=(QVector2D vector) noexcept
585{
586 v[0] -= vector.v[0];
587 v[1] -= vector.v[1];
588 return *this;
589}
590
591constexpr inline QVector2D &QVector2D::operator*=(float factor) noexcept
592{
593 v[0] *= factor;
594 v[1] *= factor;
595 return *this;
596}
597
598constexpr inline QVector2D &QVector2D::operator*=(QVector2D vector) noexcept
599{
600 v[0] *= vector.v[0];
601 v[1] *= vector.v[1];
602 return *this;
603}
604
605constexpr inline QVector2D &QVector2D::operator/=(float divisor)
606{
607 Q_ASSERT(divisor < 0 || divisor > 0);
608 v[0] /= divisor;
609 v[1] /= divisor;
610 return *this;
611}
612
613constexpr inline QVector2D &QVector2D::operator/=(QVector2D vector)
614{
615 Q_ASSERT(vector.v[0] > 0 || vector.v[0] < 0);
616 Q_ASSERT(vector.v[1] > 0 || vector.v[1] < 0);
617 v[0] /= vector.v[0];
618 v[1] /= vector.v[1];
619 return *this;
620}
621
622constexpr inline float QVector2D::dotProduct(QVector2D v1, QVector2D v2) noexcept
623{
624 return v1.v[0] * v2.v[0] + v1.v[1] * v2.v[1];
625}
626
627#ifndef QT_NO_VECTOR3D
628constexpr inline QVector3D QVector2D::toVector3D() const noexcept
629{
630 return QVector3D(v[0], v[1], 0.0f);
631}
632#endif
633#ifndef QT_NO_VECTOR4D
634constexpr inline QVector4D QVector2D::toVector4D() const noexcept
635{
636 return QVector4D(v[0], v[1], 0.0f, 0.0f);
637}
638#endif
639
640
641constexpr inline QPoint QVector2D::toPoint() const noexcept
642{
643 return QPoint(qRound(v[0]), qRound(v[1]));
644}
645
646constexpr inline QPointF QVector2D::toPointF() const noexcept
647{
648 return QPointF(qreal(v[0]), qreal(v[1]));
649}
650
651#ifndef QT_NO_DEBUG_STREAM
652Q_GUI_EXPORT QDebug operator<<(QDebug dbg, QVector2D vector);
653#endif
654
655#ifndef QT_NO_DATASTREAM
656Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, QVector2D );
657Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QVector2D &);
658#endif
659
660#endif // QT_NO_VECTOR2D
661
662
663
664/***************************** QVector3D *****************************/
665
666#ifndef QT_NO_VECTOR3D
667
668constexpr inline QVector3D::QVector3D() noexcept : v{0.0f, 0.0f, 0.0f} {}
669
670constexpr inline QVector3D::QVector3D(QPoint point) noexcept : v{float(point.x()), float(point.y()), 0.0f} {}
671
672constexpr inline QVector3D::QVector3D(QPointF point) noexcept : v{float(point.x()), float(point.y()), 0.0f} {}
673
674#ifndef QT_NO_VECTOR2D
675constexpr inline QVector3D::QVector3D(QVector2D vector) noexcept : v{vector[0], vector[1], 0.0f} {}
676constexpr inline QVector3D::QVector3D(QVector2D vector, float zpos) noexcept : v{vector[0], vector[1], zpos} {}
677#endif
678
679#ifndef QT_NO_VECTOR4D
680constexpr inline QVector3D::QVector3D(QVector4D vector) noexcept : v{vector[0], vector[1], vector[2]} {}
681#endif
682
683constexpr inline bool QVector3D::isNull() const noexcept
684{
685 return qIsNull(v[0]) && qIsNull(v[1]) && qIsNull(v[2]);
686}
687
688constexpr inline float QVector3D::x() const noexcept { return v[0]; }
689constexpr inline float QVector3D::y() const noexcept { return v[1]; }
690constexpr inline float QVector3D::z() const noexcept { return v[2]; }
691
692constexpr inline void QVector3D::setX(float aX) noexcept { v[0] = aX; }
693constexpr inline void QVector3D::setY(float aY) noexcept { v[1] = aY; }
694constexpr inline void QVector3D::setZ(float aZ) noexcept { v[2] = aZ; }
695
696constexpr inline float &QVector3D::operator[](int i)
697{
698 Q_ASSERT(uint(i) < 3u);
699 return v[i];
700}
701
702constexpr inline float QVector3D::operator[](int i) const
703{
704 Q_ASSERT(uint(i) < 3u);
705 return v[i];
706}
707
708inline float QVector3D::length() const noexcept
709{
710 return qHypot(v[0], v[1], v[2]);
711}
712
713inline QVector3D QVector3D::normalized() const noexcept
714{
715 const float len = length();
716 return qFuzzyIsNull(len - 1.0f) ? *this : qFuzzyIsNull(len) ? QVector3D()
717 : QVector3D(v[0] / len, v[1] / len, v[2] / len);
718}
719
720inline void QVector3D::normalize() noexcept
721{
722 const float len = length();
723 if (qFuzzyIsNull(len - 1.0f) || qFuzzyIsNull(len))
724 return;
725
726 v[0] /= len;
727 v[1] /= len;
728 v[2] /= len;
729}
730
731constexpr inline float QVector3D::lengthSquared() const noexcept
732{
733 return v[0] * v[0] + v[1] * v[1] + v[2] * v[2];
734}
735
736constexpr inline QVector3D &QVector3D::operator+=(QVector3D vector) noexcept
737{
738 v[0] += vector.v[0];
739 v[1] += vector.v[1];
740 v[2] += vector.v[2];
741 return *this;
742}
743
744constexpr inline QVector3D &QVector3D::operator-=(QVector3D vector) noexcept
745{
746 v[0] -= vector.v[0];
747 v[1] -= vector.v[1];
748 v[2] -= vector.v[2];
749 return *this;
750}
751
752constexpr inline QVector3D &QVector3D::operator*=(float factor) noexcept
753{
754 v[0] *= factor;
755 v[1] *= factor;
756 v[2] *= factor;
757 return *this;
758}
759
760constexpr inline QVector3D &QVector3D::operator*=(QVector3D vector) noexcept
761{
762 v[0] *= vector.v[0];
763 v[1] *= vector.v[1];
764 v[2] *= vector.v[2];
765 return *this;
766}
767
768constexpr inline QVector3D &QVector3D::operator/=(float divisor)
769{
770 Q_ASSERT(divisor < 0 || divisor > 0);
771 v[0] /= divisor;
772 v[1] /= divisor;
773 v[2] /= divisor;
774 return *this;
775}
776
777constexpr inline QVector3D &QVector3D::operator/=(QVector3D vector)
778{
779 Q_ASSERT(vector.v[0] > 0 || vector.v[0] < 0);
780 Q_ASSERT(vector.v[1] > 0 || vector.v[1] < 0);
781 Q_ASSERT(vector.v[2] > 0 || vector.v[2] < 0);
782 v[0] /= vector.v[0];
783 v[1] /= vector.v[1];
784 v[2] /= vector.v[2];
785 return *this;
786}
787
788constexpr inline float QVector3D::dotProduct(QVector3D v1, QVector3D v2) noexcept
789{
790 return v1.v[0] * v2.v[0] + v1.v[1] * v2.v[1] + v1.v[2] * v2.v[2];
791}
792
793constexpr inline QVector3D QVector3D::crossProduct(QVector3D v1, QVector3D v2) noexcept
794{
795 return QVector3D(v1.v[1] * v2.v[2] - v1.v[2] * v2.v[1],
796 v1.v[2] * v2.v[0] - v1.v[0] * v2.v[2],
797 v1.v[0] * v2.v[1] - v1.v[1] * v2.v[0]);
798}
799
801{
803}
804
806{
807 return crossProduct((v2 - v1), (v3 - v1)).normalized();
808}
809
810inline float QVector3D::distanceToPoint(QVector3D point) const noexcept
811{
812 return (*this - point).length();
813}
814
815constexpr inline float QVector3D::distanceToPlane(QVector3D plane, QVector3D normal) const noexcept
816{
817 return dotProduct(*this - plane, normal);
818}
819
820inline float QVector3D::distanceToPlane(QVector3D plane1, QVector3D plane2, QVector3D plane3) const noexcept
821{
822 QVector3D n = normal(plane2 - plane1, plane3 - plane1);
823 return dotProduct(*this - plane1, n);
824}
825
826inline float QVector3D::distanceToLine(QVector3D point, QVector3D direction) const noexcept
827{
828 if (direction.isNull())
829 return (*this - point).length();
830 QVector3D p = point + dotProduct(*this - point, direction) * direction;
831 return (*this - p).length();
832}
833
834#ifndef QT_NO_VECTOR2D
835constexpr inline QVector2D QVector3D::toVector2D() const noexcept
836{
837 return QVector2D(v[0], v[1]);
838}
839#endif
840#ifndef QT_NO_VECTOR4D
841constexpr inline QVector4D QVector3D::toVector4D() const noexcept
842{
843 return QVector4D(v[0], v[1], v[2], 0.0f);
844}
845#endif
846
847constexpr inline QPoint QVector3D::toPoint() const noexcept
848{
849 return QPoint(qRound(v[0]), qRound(v[1]));
850}
851
852constexpr inline QPointF QVector3D::toPointF() const noexcept
853{
854 return QPointF(qreal(v[0]), qreal(v[1]));
855}
856
857#ifndef QT_NO_DEBUG_STREAM
858Q_GUI_EXPORT QDebug operator<<(QDebug dbg, QVector3D vector);
859#endif
860
861#ifndef QT_NO_DATASTREAM
862Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, QVector3D );
863Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QVector3D &);
864#endif
865
866#endif // QT_NO_VECTOR3D
867
868
869
870/***************************** QVector4D *****************************/
871
872#ifndef QT_NO_VECTOR4D
873
874constexpr inline QVector4D::QVector4D() noexcept : v{0.0f, 0.0f, 0.0f, 0.0f} {}
875
876constexpr inline QVector4D::QVector4D(float xpos, float ypos, float zpos, float wpos) noexcept : v{xpos, ypos, zpos, wpos} {}
877
878constexpr inline QVector4D::QVector4D(QPoint point) noexcept : v{float(point.x()), float(point.y()), 0.0f, 0.0f} {}
879
880constexpr inline QVector4D::QVector4D(QPointF point) noexcept : v{float(point.x()), float(point.y()), 0.0f, 0.0f} {}
881
882#ifndef QT_NO_VECTOR2D
883constexpr QVector4D::QVector4D(QVector2D vector) noexcept : v{vector[0], vector[1], 0.0f, 0.0f} {}
884constexpr QVector4D::QVector4D(QVector2D vector, float zpos, float wpos) noexcept : v{vector[0], vector[1], zpos, wpos} {}
885#endif
886#ifndef QT_NO_VECTOR3D
887constexpr QVector4D::QVector4D(QVector3D vector) noexcept : v{vector[0], vector[1], vector[2], 0.0f} {}
888constexpr QVector4D::QVector4D(QVector3D vector, float wpos) noexcept : v{vector[0], vector[1], vector[2], wpos} {}
889#endif
890
891constexpr inline bool QVector4D::isNull() const noexcept
892{
893 return qIsNull(v[0]) && qIsNull(v[1]) && qIsNull(v[2]) && qIsNull(v[3]);
894}
895
896constexpr inline float QVector4D::x() const noexcept { return v[0]; }
897constexpr inline float QVector4D::y() const noexcept { return v[1]; }
898constexpr inline float QVector4D::z() const noexcept { return v[2]; }
899constexpr inline float QVector4D::w() const noexcept { return v[3]; }
900
901constexpr inline void QVector4D::setX(float aX) noexcept { v[0] = aX; }
902constexpr inline void QVector4D::setY(float aY) noexcept { v[1] = aY; }
903constexpr inline void QVector4D::setZ(float aZ) noexcept { v[2] = aZ; }
904constexpr inline void QVector4D::setW(float aW) noexcept { v[3] = aW; }
905
906constexpr inline float &QVector4D::operator[](int i)
907{
908 Q_ASSERT(uint(i) < 4u);
909 return v[i];
910}
911
912constexpr inline float QVector4D::operator[](int i) const
913{
914 Q_ASSERT(uint(i) < 4u);
915 return v[i];
916}
917
918inline float QVector4D::length() const noexcept
919{
920 return qHypot(v[0], v[1], v[2], v[3]);
921}
922
923constexpr inline float QVector4D::lengthSquared() const noexcept
924{
925 return v[0] * v[0] + v[1] * v[1] + v[2] * v[2] + v[3] * v[3];
926}
927
928inline QVector4D QVector4D::normalized() const noexcept
929{
930 const float len = length();
931 return qFuzzyIsNull(len - 1.0f) ? *this : qFuzzyIsNull(len) ? QVector4D()
932 : QVector4D(v[0] / len, v[1] / len, v[2] / len, v[3] / len);
933}
934
935inline void QVector4D::normalize() noexcept
936{
937 const float len = length();
938 if (qFuzzyIsNull(len - 1.0f) || qFuzzyIsNull(len))
939 return;
940
941 v[0] /= len;
942 v[1] /= len;
943 v[2] /= len;
944 v[3] /= len;
945}
946
947constexpr inline QVector4D &QVector4D::operator+=(QVector4D vector) noexcept
948{
949 v[0] += vector.v[0];
950 v[1] += vector.v[1];
951 v[2] += vector.v[2];
952 v[3] += vector.v[3];
953 return *this;
954}
955
956constexpr inline QVector4D &QVector4D::operator-=(QVector4D vector) noexcept
957{
958 v[0] -= vector.v[0];
959 v[1] -= vector.v[1];
960 v[2] -= vector.v[2];
961 v[3] -= vector.v[3];
962 return *this;
963}
964
965constexpr inline QVector4D &QVector4D::operator*=(float factor) noexcept
966{
967 v[0] *= factor;
968 v[1] *= factor;
969 v[2] *= factor;
970 v[3] *= factor;
971 return *this;
972}
973
974constexpr inline QVector4D &QVector4D::operator*=(QVector4D vector) noexcept
975{
976 v[0] *= vector.v[0];
977 v[1] *= vector.v[1];
978 v[2] *= vector.v[2];
979 v[3] *= vector.v[3];
980 return *this;
981}
982
983constexpr inline QVector4D &QVector4D::operator/=(float divisor)
984{
985 Q_ASSERT(divisor < 0 || divisor > 0);
986 v[0] /= divisor;
987 v[1] /= divisor;
988 v[2] /= divisor;
989 v[3] /= divisor;
990 return *this;
991}
992
993constexpr inline QVector4D &QVector4D::operator/=(QVector4D vector)
994{
995 Q_ASSERT(vector.v[0] > 0 || vector.v[0] < 0);
996 Q_ASSERT(vector.v[1] > 0 || vector.v[1] < 0);
997 Q_ASSERT(vector.v[2] > 0 || vector.v[2] < 0);
998 Q_ASSERT(vector.v[3] > 0 || vector.v[3] < 0);
999 v[0] /= vector.v[0];
1000 v[1] /= vector.v[1];
1001 v[2] /= vector.v[2];
1002 v[3] /= vector.v[3];
1003 return *this;
1004}
1005
1006constexpr float QVector4D::dotProduct(QVector4D v1, QVector4D v2) noexcept
1007{
1008 return v1.v[0] * v2.v[0] + v1.v[1] * v2.v[1] + v1.v[2] * v2.v[2] + v1.v[3] * v2.v[3];
1009}
1010
1011#ifndef QT_NO_VECTOR2D
1012
1013constexpr inline QVector2D QVector4D::toVector2D() const noexcept
1014{
1015 return QVector2D(v[0], v[1]);
1016}
1017
1018constexpr inline QVector2D QVector4D::toVector2DAffine() const noexcept
1019{
1020 if (qIsNull(v[3]))
1021 return QVector2D();
1022 return QVector2D(v[0] / v[3], v[1] / v[3]);
1023}
1024
1025#endif // QT_NO_VECTOR2D
1026
1027#ifndef QT_NO_VECTOR3D
1028
1029constexpr inline QVector3D QVector4D::toVector3D() const noexcept
1030{
1031 return QVector3D(v[0], v[1], v[2]);
1032}
1033
1034constexpr QVector3D QVector4D::toVector3DAffine() const noexcept
1035{
1036 if (qIsNull(v[3]))
1037 return QVector3D();
1038 return QVector3D(v[0] / v[3], v[1] / v[3], v[2] / v[3]);
1039}
1040
1041#endif // QT_NO_VECTOR3D
1042
1043constexpr inline QPoint QVector4D::toPoint() const noexcept
1044{
1045 return QPoint(qRound(v[0]), qRound(v[1]));
1046}
1047
1048constexpr inline QPointF QVector4D::toPointF() const noexcept
1049{
1050 return QPointF(qreal(v[0]), qreal(v[1]));
1051}
1052
1053#ifndef QT_NO_DEBUG_STREAM
1054Q_GUI_EXPORT QDebug operator<<(QDebug dbg, QVector4D vector);
1055#endif
1056
1057#ifndef QT_NO_DATASTREAM
1058Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, QVector4D );
1059Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QVector4D &);
1060#endif
1061
1062#endif // QT_NO_VECTOR4D
1063
1064
1065QT_END_NAMESPACE
1066
1067/***************************** Tuple protocol *****************************/
1068
1069namespace std {
1070#ifndef QT_NO_VECTOR2D
1071 template <>
1073 template <>
1074 class tuple_element<0, QT_PREPEND_NAMESPACE(QVector2D)> { public: using type = float; };
1075 template <>
1076 class tuple_element<1, QT_PREPEND_NAMESPACE(QVector2D)> { public: using type = float; };
1077#endif // QT_NO_VECTOR2D
1078
1079#ifndef QT_NO_VECTOR3D
1080 template <>
1082 template <>
1083 class tuple_element<0, QT_PREPEND_NAMESPACE(QVector3D)> { public: using type = float; };
1084 template <>
1085 class tuple_element<1, QT_PREPEND_NAMESPACE(QVector3D)> { public: using type = float; };
1086 template <>
1087 class tuple_element<2, QT_PREPEND_NAMESPACE(QVector3D)> { public: using type = float; };
1088#endif // QT_NO_VECTOR3D
1089
1090#ifndef QT_NO_VECTOR4D
1091 template <>
1093 template <>
1094 class tuple_element<0, QT_PREPEND_NAMESPACE(QVector4D)> { public: using type = float; };
1095 template <>
1096 class tuple_element<1, QT_PREPEND_NAMESPACE(QVector4D)> { public: using type = float; };
1097 template <>
1098 class tuple_element<2, QT_PREPEND_NAMESPACE(QVector4D)> { public: using type = float; };
1099 template <>
1100 class tuple_element<3, QT_PREPEND_NAMESPACE(QVector4D)> { public: using type = float; };
1101#endif // QT_NO_VECTOR4D
1102}
1103
1104#endif // QVECTORND_H
\inmodule QtCore\reentrant
Definition qdatastream.h:50
The QVector2D class represents a vector or vertex in 2D space.
Definition qvectornd.h:36
float length() const noexcept
Returns the length of the vector from the origin.
Definition qvectornd.h:537
constexpr float y() const noexcept
Returns the y coordinate of this point.
Definition qvectornd.h:520
constexpr QVector2D(QPoint point) noexcept
Constructs a vector with x and y coordinates from a 2D point.
Definition qvectornd.h:503
constexpr float & operator[](int i)
Definition qvectornd.h:525
QVector2D normalized() const noexcept
Returns the normalized unit vector form of this vector.
Definition qvectornd.h:547
constexpr float lengthSquared() const noexcept
Returns the squared length of the vector from the origin.
Definition qvectornd.h:542
constexpr QVector3D toVector3D() const noexcept
Returns the 3D form of this 2D vector, with the z coordinate set to zero.
Definition qvectornd.h:628
constexpr QVector2D & operator*=(float factor) noexcept
Multiplies this vector's coordinates by the given finite factor and returns a reference to this vecto...
Definition qvectornd.h:591
constexpr QVector2D & operator+=(QVector2D vector) noexcept
Adds the given vector to this vector and returns a reference to this vector.
Definition qvectornd.h:577
constexpr float x() const noexcept
Returns the x coordinate of this point.
Definition qvectornd.h:519
constexpr QVector2D(QVector4D vector) noexcept
Constructs a vector with x and y coordinates from a 3D vector.
Definition qvectornd.h:511
static constexpr float dotProduct(QVector2D v1, QVector2D v2) noexcept
Returns the dot product of v1 and v2.
Definition qvectornd.h:622
constexpr QVector2D & operator*=(QVector2D vector) noexcept
Multiplies each component of this vector by the corresponding component of vector and returns a refer...
Definition qvectornd.h:598
constexpr QVector2D & operator/=(float divisor)
Divides this vector's coordinates by the given divisor and returns a reference to this vector.
Definition qvectornd.h:605
float distanceToPoint(QVector2D point) const noexcept
Definition qvectornd.h:564
constexpr QVector2D() noexcept
Constructs a null vector, i.e.
Definition qvectornd.h:499
constexpr QVector2D & operator-=(QVector2D vector) noexcept
Subtracts the given vector from this vector and returns a reference to this vector.
Definition qvectornd.h:584
constexpr float operator[](int i) const
Definition qvectornd.h:531
constexpr void setY(float y) noexcept
Sets the y coordinate of this point to the given finite y coordinate.
Definition qvectornd.h:523
constexpr QPointF toPointF() const noexcept
Returns the QPointF form of this 2D vector.
Definition qvectornd.h:646
constexpr QVector2D(QVector3D vector) noexcept
Constructs a vector with x and y coordinates from a 3D vector.
Definition qvectornd.h:508
constexpr void setX(float x) noexcept
Sets the x coordinate of this point to the given finite x coordinate.
Definition qvectornd.h:522
constexpr QPoint toPoint() const noexcept
Returns the QPoint form of this 2D vector.
Definition qvectornd.h:641
constexpr QVector4D toVector4D() const noexcept
Returns the 4D form of this 2D vector, with the z and w coordinates set to zero.
Definition qvectornd.h:634
void normalize() noexcept
Normalizes the current vector in place.
Definition qvectornd.h:554
float distanceToLine(QVector2D point, QVector2D direction) const noexcept
Definition qvectornd.h:569
constexpr bool isNull() const noexcept
Returns true if the x and y coordinates are set to 0.0, otherwise returns false.
Definition qvectornd.h:514
constexpr QVector2D & operator/=(QVector2D vector)
Definition qvectornd.h:613
The QVector3D class represents a vector or vertex in 3D space.
Definition qvectornd.h:180
constexpr void setX(float x) noexcept
Sets the x coordinate of this point to the given finite x coordinate.
Definition qvectornd.h:692
float distanceToLine(QVector3D point, QVector3D direction) const noexcept
Returns the distance that this vertex is from a line defined by point and the unit vector direction.
Definition qvectornd.h:826
constexpr bool isNull() const noexcept
Returns true if the x, y, and z coordinates are set to 0.0, otherwise returns false.
Definition qvectornd.h:683
constexpr QVector3D & operator*=(float factor) noexcept
Multiplies this vector's coordinates by the given finite factor and returns a reference to this vecto...
Definition qvectornd.h:752
constexpr float distanceToPlane(QVector3D plane, QVector3D normal) const noexcept
Returns the distance from this vertex to a plane defined by the vertex plane and a normal unit vector...
Definition qvectornd.h:815
static QVector3D normal(QVector3D v1, QVector3D v2) noexcept
Returns the unit normal vector of a plane spanned by vectors v1 and v2, which must not be parallel to...
Definition qvectornd.h:800
float length() const noexcept
Returns the length of the vector from the origin.
Definition qvectornd.h:708
constexpr friend QVector3D operator*(QVector3D v1, QVector3D v2) noexcept
//!
Definition qvectornd.h:273
constexpr friend QVector3D operator+(QVector3D v1, QVector3D v2) noexcept
//!
Definition qvectornd.h:253
QVector3D normalized() const noexcept
Returns the normalized unit vector form of this vector.
Definition qvectornd.h:713
constexpr float lengthSquared() const noexcept
Returns the squared length of the vector from the origin.
Definition qvectornd.h:731
constexpr friend QVector3D operator*(QVector3D vector, float factor) noexcept
//!
Definition qvectornd.h:268
constexpr void setY(float y) noexcept
Sets the y coordinate of this point to the given finite y coordinate.
Definition qvectornd.h:693
static QVector3D normal(QVector3D v1, QVector3D v2, QVector3D v3) noexcept
Returns the unit normal vector of a plane spanned by vectors v2 - v1 and v3 - v1, which must not be p...
Definition qvectornd.h:805
friend QVector3D operator*(const QVector3D &vector, const QMatrix4x4 &matrix)
constexpr float & operator[](int i)
Definition qvectornd.h:696
constexpr QPoint toPoint() const noexcept
Returns the QPoint form of this 3D vector.
Definition qvectornd.h:847
constexpr QPointF toPointF() const noexcept
Returns the QPointF form of this 3D vector.
Definition qvectornd.h:852
constexpr QVector3D & operator-=(QVector3D vector) noexcept
Subtracts the given vector from this vector and returns a reference to this vector.
Definition qvectornd.h:744
constexpr friend QVector3D operator-(QVector3D vector) noexcept
//!
Definition qvectornd.h:278
constexpr QVector3D(QVector4D vector) noexcept
Constructs a 3D vector from the specified 4D vector.
Definition qvectornd.h:680
constexpr float y() const noexcept
Returns the y coordinate of this point.
Definition qvectornd.h:689
constexpr QVector2D toVector2D() const noexcept
Returns the 2D vector form of this 3D vector, dropping the z coordinate.
Definition qvectornd.h:835
constexpr float operator[](int i) const
Definition qvectornd.h:702
constexpr friend QVector3D operator/(QVector3D vector, float divisor)
//!
Definition qvectornd.h:283
constexpr friend QVector3D operator/(QVector3D vector, QVector3D divisor)
//!
Definition qvectornd.h:289
constexpr QVector4D toVector4D() const noexcept
Returns the 4D form of this 3D vector, with the w coordinate set to zero.
Definition qvectornd.h:841
constexpr QVector3D(QPointF point) noexcept
Constructs a vector with x and y coordinates from a 2D point, and a z coordinate of 0.
Definition qvectornd.h:672
constexpr float x() const noexcept
Returns the x coordinate of this point.
Definition qvectornd.h:688
constexpr QVector3D(QVector2D vector, float zpos) noexcept
Constructs a 3D vector from the specified 2D vector.
Definition qvectornd.h:676
constexpr QVector3D & operator*=(QVector3D vector) noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qvectornd.h:760
constexpr void setZ(float z) noexcept
Sets the z coordinate of this point to the given finite z coordinate.
Definition qvectornd.h:694
constexpr QVector3D & operator/=(QVector3D vector)
Definition qvectornd.h:777
friend QVector3D operator*(const QMatrix4x4 &matrix, const QVector3D &vector)
constexpr QVector3D & operator/=(float divisor)
Divides this vector's coordinates by the given divisor, and returns a reference to this vector.
Definition qvectornd.h:768
static constexpr float dotProduct(QVector3D v1, QVector3D v2) noexcept
Returns the dot product of v1 and v2.
Definition qvectornd.h:788
float distanceToPlane(QVector3D plane1, QVector3D plane2, QVector3D plane3) const noexcept
Returns the distance from this vertex to a plane defined by the vertices plane1, plane2 and plane3.
Definition qvectornd.h:820
constexpr QVector3D() noexcept
Constructs a null vector, i.e.
Definition qvectornd.h:668
constexpr QVector3D & operator+=(QVector3D vector) noexcept
Adds the given vector to this vector and returns a reference to this vector.
Definition qvectornd.h:736
static constexpr QVector3D crossProduct(QVector3D v1, QVector3D v2) noexcept
Returns the cross-product of vectors v1 and v2, which is normal to the plane spanned by v1 and v2.
Definition qvectornd.h:793
constexpr QVector3D(QVector2D vector) noexcept
Constructs a 3D vector from the specified 2D vector.
Definition qvectornd.h:675
constexpr friend QVector3D operator*(float factor, QVector3D vector) noexcept
//!
Definition qvectornd.h:263
void normalize() noexcept
Normalizes the current vector in place.
Definition qvectornd.h:720
constexpr friend QVector3D operator-(QVector3D v1, QVector3D v2) noexcept
//!
Definition qvectornd.h:258
constexpr float z() const noexcept
Returns the z coordinate of this point.
Definition qvectornd.h:690
The QVector4D class represents a vector or vertex in 4D space.
Definition qvectornd.h:343
constexpr QVector4D & operator-=(QVector4D vector) noexcept
Subtracts the given vector from this vector and returns a reference to this vector.
Definition qvectornd.h:956
constexpr QVector4D(QVector2D vector) noexcept
Constructs a 4D vector from the specified 2D vector.
Definition qvectornd.h:883
constexpr void setZ(float z) noexcept
Sets the z coordinate of this point to the given finite z coordinate.
Definition qvectornd.h:903
QVector4D normalized() const noexcept
Returns the normalized unit vector form of this vector.
Definition qvectornd.h:928
constexpr float lengthSquared() const noexcept
Returns the squared length of the vector from the origin.
Definition qvectornd.h:923
constexpr QVector4D & operator*=(float factor) noexcept
Multiplies this vector's coordinates by the given finite factor, and returns a reference to this vect...
Definition qvectornd.h:965
constexpr bool isNull() const noexcept
Returns true if the x, y, z, and w coordinates are set to 0.0, otherwise returns false.
Definition qvectornd.h:891
constexpr float x() const noexcept
Returns the x coordinate of this point.
Definition qvectornd.h:896
float length() const noexcept
Returns the length of the vector from the origin.
Definition qvectornd.h:918
constexpr void setY(float y) noexcept
Sets the y coordinate of this point to the given finite y coordinate.
Definition qvectornd.h:902
constexpr float w() const noexcept
Returns the w coordinate of this point.
Definition qvectornd.h:899
friend QVector4D operator*(const QVector4D &vector, const QMatrix4x4 &matrix)
Definition qmatrix4x4.h:747
constexpr QVector4D(QPoint point) noexcept
Constructs a vector with x and y coordinates from a 2D point, and z and w coordinates of 0.
Definition qvectornd.h:878
constexpr QVector2D toVector2D() const noexcept
Returns the 2D vector form of this 4D vector, dropping the z and w coordinates.
Definition qvectornd.h:1013
constexpr QVector2D toVector2DAffine() const noexcept
Returns the 2D vector form of this 4D vector, dividing the x and y coordinates by the w coordinate an...
Definition qvectornd.h:1018
constexpr void setX(float x) noexcept
Sets the x coordinate of this point to the given finite x coordinate.
Definition qvectornd.h:901
constexpr QVector4D & operator/=(QVector4D vector)
Definition qvectornd.h:993
friend QVector4D operator*(const QMatrix4x4 &matrix, const QVector4D &vector)
Definition qmatrix4x4.h:769
constexpr QVector4D(QVector3D vector) noexcept
Constructs a 4D vector from the specified 3D vector.
Definition qvectornd.h:887
constexpr QVector4D & operator+=(QVector4D vector) noexcept
Adds the given vector to this vector and returns a reference to this vector.
Definition qvectornd.h:947
void normalize() noexcept
Normalizes the current vector in place.
Definition qvectornd.h:935
constexpr QVector4D & operator/=(float divisor)
Divides this vector's coordinates by the given divisor, and returns a reference to this vector.
Definition qvectornd.h:983
constexpr float operator[](int i) const
Definition qvectornd.h:912
constexpr QVector4D(QVector3D vector, float wpos) noexcept
Constructs a 4D vector from the specified 3D vector.
Definition qvectornd.h:888
constexpr QVector4D & operator*=(QVector4D vector) noexcept
Multiplies each component of this vector by the corresponding component of vector and returns a refer...
Definition qvectornd.h:974
constexpr float y() const noexcept
Returns the y coordinate of this point.
Definition qvectornd.h:897
constexpr QPointF toPointF() const noexcept
Returns the QPointF form of this 4D vector.
Definition qvectornd.h:1048
constexpr QVector4D(QVector2D vector, float zpos, float wpos) noexcept
Constructs a 4D vector from the specified 2D vector.
Definition qvectornd.h:884
static constexpr float dotProduct(QVector4D v1, QVector4D v2) noexcept
Returns the dot product of v1 and v2.
Definition qvectornd.h:1006
constexpr float & operator[](int i)
Definition qvectornd.h:906
constexpr QPoint toPoint() const noexcept
Returns the QPoint form of this 4D vector.
Definition qvectornd.h:1043
constexpr QVector3D toVector3D() const noexcept
Returns the 3D vector form of this 4D vector, dropping the w coordinate.
Definition qvectornd.h:1029
constexpr QVector4D() noexcept
Constructs a null vector, i.e.
Definition qvectornd.h:874
constexpr float z() const noexcept
Returns the z coordinate of this point.
Definition qvectornd.h:898
constexpr void setW(float w) noexcept
Sets the w coordinate of this point to the given finite w coordinate.
Definition qvectornd.h:904
constexpr QVector3D toVector3DAffine() const noexcept
Returns the 3D vector form of this 4D vector, dividing the x, y, and z coordinates by the w coordinat...
Definition qvectornd.h:1034
Q_CORE_EXPORT QDebug operator<<(QDebug debug, QDir::Filters filters)
Definition qdir.cpp:2582
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
Q_DECLARE_TYPEINFO(QVector3D, Q_PRIMITIVE_TYPE)
Q_DECLARE_TYPEINFO(QVector4D, Q_PRIMITIVE_TYPE)
Q_DECLARE_TYPEINFO(QVector2D, Q_PRIMITIVE_TYPE)