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
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
6#include <QtCore/qdatastream.h>
7#include <QtCore/qdebug.h>
8#include <QtCore/qmath.h>
9
11
12QDoubleVector2D::QDoubleVector2D(const QDoubleVector3D &vector) :
13 xp(vector.xp), yp(vector.yp)
14{
15}
16
17double QDoubleVector2D::length() const
18{
19 return qHypot(xp, yp);
20}
21
22QDoubleVector2D QDoubleVector2D::normalized() const
23{
24 const double len = length();
25 if (qFuzzyIsNull(len - 1.0))
26 return *this;
27 else if (!qFuzzyIsNull(len))
28 return *this / len;
29 else
30 return QDoubleVector2D();
31}
32
33void QDoubleVector2D::normalize()
34{
35 double len = length();
36 if (qFuzzyIsNull(len - 1.0) || qFuzzyIsNull(len))
37 return;
38
39 xp /= len;
40 yp /= len;
41}
42
43QDoubleVector3D QDoubleVector2D::toVector3D() const
44{
45 return QDoubleVector3D(xp, yp, 0.0);
46}
47
48#ifndef QT_NO_DEBUG_STREAM
49
50QDebug operator<<(QDebug dbg, const QDoubleVector2D &vector)
51{
52 QDebugStateSaver saver(dbg);
53 dbg.nospace() << "QDoubleVector2D(" << vector.x() << ", " << vector.y() << ')';
54 return dbg;
55}
56
57#endif
58
59#ifndef QT_NO_DATASTREAM
60
61QDataStream &operator<<(QDataStream &stream, const QDoubleVector2D &vector)
62{
63 stream << double(vector.x()) << double(vector.y());
64 return stream;
65}
66
67QDataStream &operator>>(QDataStream &stream, QDoubleVector2D &vector)
68{
69 double x, y;
70 stream >> x;
71 stream >> y;
72 vector.setX(double(x));
73 vector.setY(double(y));
74 return stream;
75}
76
77#endif // QT_NO_DATASTREAM
78
79QT_END_NAMESPACE
Combined button and popup list for selecting options.
QDebug operator<<(QDebug dbg, const QFileInfo &fi)
QDataStream & operator<<(QDataStream &stream, const QImage &image)
[0]
Definition qimage.cpp:4009
QDataStream & operator>>(QDataStream &stream, QImage &image)
Definition qimage.cpp:4035