Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qdoublevector2d.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qdoublevector2d_p.h"
5#include "qdoublevector3d_p.h"
6#include <QtCore/qdatastream.h>
7#include <QtCore/qdebug.h>
8#include <QtCore/qmath.h>
9
11
16
18{
19 return qSqrt(xp * xp + yp * yp);
20}
21
23{
24 // Need some extra precision if the length is very small.
25 double len = double(xp) * double(xp) +
26 double(yp) * double(yp);
27 if (qFuzzyIsNull(len - 1.0))
28 return *this;
29 else if (!qFuzzyIsNull(len))
30 return *this / (double)qSqrt(len);
31 else
32 return QDoubleVector2D();
33}
34
36{
37 // Need some extra precision if the length is very small.
38 double len = double(xp) * double(xp) +
39 double(yp) * double(yp);
40 if (qFuzzyIsNull(len - 1.0) || qFuzzyIsNull(len))
41 return;
42
43 len = qSqrt(len);
44
45 xp /= len;
46 yp /= len;
47}
48
50{
51 return QDoubleVector3D(xp, yp, 0.0);
52}
53
54#ifndef QT_NO_DEBUG_STREAM
55
57{
58 QDebugStateSaver saver(dbg);
59 dbg.nospace() << "QDoubleVector2D(" << vector.x() << ", " << vector.y() << ')';
60 return dbg;
61}
62
63#endif
64
65#ifndef QT_NO_DATASTREAM
66
68{
69 stream << double(vector.x()) << double(vector.y());
70 return stream;
71}
72
74{
75 double x, y;
76 stream >> x;
77 stream >> y;
78 vector.setX(double(x));
79 vector.setY(double(y));
80 return stream;
81}
82
83#endif // QT_NO_DATASTREAM
84
\inmodule QtCore\reentrant
Definition qdatastream.h:46
\inmodule QtCore
\inmodule QtCore
friend class QDoubleVector3D
QDoubleVector2D normalized() const
QDoubleVector3D toVector3D() const
Q_DECL_CONSTEXPR QDoubleVector2D()
double length() const
Combined button and popup list for selecting options.
QDataStream & operator>>(QDataStream &stream, QDoubleVector2D &vector)
QDebug operator<<(QDebug dbg, const QDoubleVector2D &vector)
EGLStreamKHR stream
bool qFuzzyIsNull(qfloat16 f) noexcept
Definition qfloat16.h:349
qfloat16 qSqrt(qfloat16 f)
Definition qfloat16.h:289
GLint GLint GLint GLint GLint x
[0]
GLint y
GLenum GLsizei len
QList< int > vector
[14]