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