1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtPositioning module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QDOUBLEVECTOR2D_P_H
41#define QDOUBLEVECTOR2D_P_H
42
43//
44// W A R N I N G
45// -------------
46//
47// This file is not part of the Qt API. It exists purely as an
48// implementation detail. This header file may change from version to
49// version without notice, or even be removed.
50//
51// We mean it.
52//
53
54#ifdef QT_BUILD_LOCATION_LIB
55#include <QVector2D>
56#endif
57
58#include "qpositioningglobal_p.h"
59#include <QtCore/qmetatype.h>
60#include <QPointF>
61
62QT_BEGIN_NAMESPACE
63
64class QDoubleVector3D;
65
66class Q_POSITIONING_PRIVATE_EXPORT QDoubleVector2D
67{
68public:
69 Q_DECL_CONSTEXPR inline QDoubleVector2D();
70 Q_DECL_CONSTEXPR inline QDoubleVector2D(double xpos, double ypos);
71 Q_DECL_CONSTEXPR explicit inline QDoubleVector2D(const QPointF &p);
72 explicit QDoubleVector2D(const QDoubleVector3D &vector);
73
74 Q_DECL_CONSTEXPR inline double manhattanLength() const;
75 inline bool isNull() const;
76 inline bool isFinite() const;
77
78 Q_DECL_CONSTEXPR inline double x() const;
79 Q_DECL_CONSTEXPR inline double y() const;
80
81 inline void setX(double x);
82 inline void setY(double y);
83
84 double length() const;
85 Q_DECL_CONSTEXPR inline double lengthSquared() const;
86
87 QDoubleVector2D normalized() const;
88 void normalize();
89
90 inline QDoubleVector2D &operator+=(const QDoubleVector2D &vector);
91 inline QDoubleVector2D &operator-=(const QDoubleVector2D &vector);
92 inline QDoubleVector2D &operator*=(double factor);
93 inline QDoubleVector2D &operator*=(const QDoubleVector2D &vector);
94 inline QDoubleVector2D &operator/=(double divisor);
95 inline QDoubleVector2D &operator/=(const QDoubleVector2D &vector);
96
97 Q_DECL_CONSTEXPR static inline double dotProduct(const QDoubleVector2D &v1, const QDoubleVector2D &v2)
98 { return v1.xp * v2.xp + v1.yp * v2.yp; }
99
100
101 friend Q_DECL_CONSTEXPR inline bool operator==(const QDoubleVector2D &v1, const QDoubleVector2D &v2);
102 friend Q_DECL_CONSTEXPR inline bool operator!=(const QDoubleVector2D &v1, const QDoubleVector2D &v2);
103 friend Q_DECL_CONSTEXPR inline const QDoubleVector2D operator+(const QDoubleVector2D &v1, const QDoubleVector2D &v2);
104 friend Q_DECL_CONSTEXPR inline const QDoubleVector2D operator-(const QDoubleVector2D &v1, const QDoubleVector2D &v2);
105 friend Q_DECL_CONSTEXPR inline const QDoubleVector2D operator*(double factor, const QDoubleVector2D &vector);
106 friend Q_DECL_CONSTEXPR inline const QDoubleVector2D operator*(const QDoubleVector2D &vector, double factor);
107 friend Q_DECL_CONSTEXPR inline const QDoubleVector2D operator*(const QDoubleVector2D &v1, const QDoubleVector2D &v2);
108 friend Q_DECL_CONSTEXPR inline const QDoubleVector2D operator-(const QDoubleVector2D &vector);
109 friend Q_DECL_CONSTEXPR inline const QDoubleVector2D operator/(const QDoubleVector2D &vector, double divisor);
110
111 friend Q_DECL_CONSTEXPR inline bool qFuzzyCompare(const QDoubleVector2D &v1, const QDoubleVector2D &v2);
112
113 QDoubleVector3D toVector3D() const;
114 Q_DECL_CONSTEXPR inline QPointF toPointF() const;
115
116private:
117 double xp, yp;
118
119 friend class QDoubleVector3D;
120};
121
122Q_DECLARE_TYPEINFO(QDoubleVector2D, Q_MOVABLE_TYPE);
123
124Q_DECL_CONSTEXPR inline QDoubleVector2D::QDoubleVector2D() : xp(0.0), yp(0.0) {}
125
126Q_DECL_CONSTEXPR inline QDoubleVector2D::QDoubleVector2D(double xpos, double ypos) : xp(xpos), yp(ypos) {}
127
128Q_DECL_CONSTEXPR inline QDoubleVector2D::QDoubleVector2D(const QPointF &p) : xp(p.x()), yp(p.y()) { }
129
130Q_DECL_CONSTEXPR inline double QDoubleVector2D::manhattanLength() const
131{
132 return qAbs(t: x())+qAbs(t: y());
133}
134
135inline bool QDoubleVector2D::isNull() const
136{
137 return qIsNull(d: xp) && qIsNull(d: yp);
138}
139
140inline bool QDoubleVector2D::isFinite() const
141{
142 return qIsFinite(d: xp) && qIsFinite(d: yp);
143}
144
145Q_DECL_CONSTEXPR inline double QDoubleVector2D::x() const { return xp; }
146Q_DECL_CONSTEXPR inline double QDoubleVector2D::y() const { return yp; }
147
148inline void QDoubleVector2D::setX(double aX) { xp = aX; }
149inline void QDoubleVector2D::setY(double aY) { yp = aY; }
150
151Q_DECL_CONSTEXPR inline double QDoubleVector2D::lengthSquared() const
152{ return xp * xp + yp * yp; }
153
154inline QDoubleVector2D &QDoubleVector2D::operator+=(const QDoubleVector2D &vector)
155{
156 xp += vector.xp;
157 yp += vector.yp;
158 return *this;
159}
160
161inline QDoubleVector2D &QDoubleVector2D::operator-=(const QDoubleVector2D &vector)
162{
163 xp -= vector.xp;
164 yp -= vector.yp;
165 return *this;
166}
167
168inline QDoubleVector2D &QDoubleVector2D::operator*=(double factor)
169{
170 xp *= factor;
171 yp *= factor;
172 return *this;
173}
174
175inline QDoubleVector2D &QDoubleVector2D::operator*=(const QDoubleVector2D &vector)
176{
177 xp *= vector.xp;
178 yp *= vector.yp;
179 return *this;
180}
181
182inline QDoubleVector2D &QDoubleVector2D::operator/=(double divisor)
183{
184 xp /= divisor;
185 yp /= divisor;
186 return *this;
187}
188
189inline QDoubleVector2D &QDoubleVector2D::operator/=(const QDoubleVector2D &vector)
190{
191 xp /= vector.xp;
192 yp /= vector.yp;
193 return *this;
194}
195
196Q_DECL_CONSTEXPR inline bool operator==(const QDoubleVector2D &v1, const QDoubleVector2D &v2)
197{
198 return v1.xp == v2.xp && v1.yp == v2.yp;
199}
200
201Q_DECL_CONSTEXPR inline bool operator!=(const QDoubleVector2D &v1, const QDoubleVector2D &v2)
202{
203 return v1.xp != v2.xp || v1.yp != v2.yp;
204}
205
206Q_DECL_CONSTEXPR inline const QDoubleVector2D operator+(const QDoubleVector2D &v1, const QDoubleVector2D &v2)
207{
208 return QDoubleVector2D(v1.xp + v2.xp, v1.yp + v2.yp);
209}
210
211Q_DECL_CONSTEXPR inline const QDoubleVector2D operator-(const QDoubleVector2D &v1, const QDoubleVector2D &v2)
212{
213 return QDoubleVector2D(v1.xp - v2.xp, v1.yp - v2.yp);
214}
215
216Q_DECL_CONSTEXPR inline const QDoubleVector2D operator*(double factor, const QDoubleVector2D &vector)
217{
218 return QDoubleVector2D(vector.xp * factor, vector.yp * factor);
219}
220
221Q_DECL_CONSTEXPR inline const QDoubleVector2D operator*(const QDoubleVector2D &vector, double factor)
222{
223 return QDoubleVector2D(vector.xp * factor, vector.yp * factor);
224}
225
226Q_DECL_CONSTEXPR inline const QDoubleVector2D operator*(const QDoubleVector2D &v1, const QDoubleVector2D &v2)
227{
228 return QDoubleVector2D(v1.xp * v2.xp, v1.yp * v2.yp);
229}
230
231Q_DECL_CONSTEXPR inline const QDoubleVector2D operator-(const QDoubleVector2D &vector)
232{
233 return QDoubleVector2D(-vector.xp, -vector.yp);
234}
235
236Q_DECL_CONSTEXPR inline const QDoubleVector2D operator/(const QDoubleVector2D &vector, double divisor)
237{
238 return QDoubleVector2D(vector.xp / divisor, vector.yp / divisor);
239}
240
241Q_DECL_CONSTEXPR inline bool qFuzzyCompare(const QDoubleVector2D &v1, const QDoubleVector2D &v2)
242{
243 return qFuzzyCompare(p1: v1.xp, p2: v2.xp) && qFuzzyCompare(p1: v1.yp, p2: v2.yp);
244}
245
246Q_DECL_CONSTEXPR inline QPointF QDoubleVector2D::toPointF() const
247{
248 return QPointF(qreal(xp), qreal(yp));
249}
250
251#ifndef QT_NO_DEBUG_STREAM
252Q_POSITIONING_EXPORT QDebug operator<<(QDebug dbg, const QDoubleVector2D &vector);
253#endif
254
255#ifndef QT_NO_DATASTREAM
256Q_POSITIONING_EXPORT QDataStream &operator<<(QDataStream &, const QDoubleVector2D &);
257Q_POSITIONING_EXPORT QDataStream &operator>>(QDataStream &, QDoubleVector2D &);
258#endif
259
260QT_END_NAMESPACE
261
262#endif
263

source code of qtlocation/src/positioning/qdoublevector2d_p.h