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
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
10
QT_BEGIN_NAMESPACE
11
12
QDoubleVector2D::QDoubleVector2D(
const
QDoubleVector3D &vector) :
13
xp(vector.xp), yp(vector.yp)
14
{
15
}
16
17
double
QDoubleVector2D::length()
const
18
{
19
return
qSqrt(xp * xp + yp * yp);
20
}
21
22
QDoubleVector2D QDoubleVector2D::normalized()
const
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
35
void
QDoubleVector2D::normalize()
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
49
QDoubleVector3D QDoubleVector2D::toVector3D()
const
50
{
51
return
QDoubleVector3D(xp, yp, 0.0);
52
}
53
54
#
ifndef
QT_NO_DEBUG_STREAM
55
56
QDebug
operator
<<(QDebug dbg,
const
QDoubleVector2D &vector)
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
67
QDataStream
&
operator
<<(QDataStream &stream,
const
QDoubleVector2D &vector)
68
{
69
stream <<
double
(vector.x()) <<
double
(vector.y());
70
return
stream;
71
}
72
73
QDataStream
&
operator
>>(QDataStream &stream, QDoubleVector2D &vector)
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
85
QT_END_NAMESPACE
QPlatformGraphicsBufferHelper
\inmodule QtGui
operator<<
QDebug operator<<(QDebug dbg, const QFileInfo &fi)
Definition
qfileinfo.cpp:1807
operator<<
QDataStream & operator<<(QDataStream &stream, const QImage &image)
[0]
Definition
qimage.cpp:4006
operator>>
QDataStream & operator>>(QDataStream &stream, QImage &image)
Definition
qimage.cpp:4032
qtpositioning
src
positioning
qdoublevector2d.cpp
Generated on
for Qt by
1.14.0