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