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