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 QDOUBLEVECTOR3D_P_H
41#define QDOUBLEVECTOR3D_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 <QVector3D>
56#endif
57
58#include "qpositioningglobal_p.h"
59#include "qdoublevector2d_p.h"
60#include <QtCore/qmetatype.h>
61
62QT_BEGIN_NAMESPACE
63
64class Q_POSITIONING_PRIVATE_EXPORT QDoubleVector3D
65{
66public:
67 Q_DECL_CONSTEXPR inline QDoubleVector3D();
68 Q_DECL_CONSTEXPR inline QDoubleVector3D(double xpos, double ypos, double zpos);
69 Q_DECL_CONSTEXPR inline QDoubleVector3D(const QDoubleVector2D &vector);
70 Q_DECL_CONSTEXPR inline QDoubleVector3D(const QDoubleVector2D &vector, double zpos);
71
72 inline bool isNull() const;
73
74 Q_DECL_CONSTEXPR inline double x() const;
75 Q_DECL_CONSTEXPR inline double y() const;
76 Q_DECL_CONSTEXPR inline double z() const;
77
78 inline void setX(double x);
79 inline void setY(double y);
80 inline void setZ(double z);
81
82 inline double get(int i) const;
83 inline void set(int i, double value);
84
85 double length() const;
86 Q_DECL_CONSTEXPR inline double lengthSquared() const;
87
88 QDoubleVector3D normalized() const;
89 void normalize();
90
91 inline QDoubleVector3D &operator+=(const QDoubleVector3D &vector);
92 inline QDoubleVector3D &operator-=(const QDoubleVector3D &vector);
93 inline QDoubleVector3D &operator*=(double factor);
94 inline QDoubleVector3D &operator*=(const QDoubleVector3D &vector);
95 inline QDoubleVector3D &operator/=(double divisor);
96
97 Q_DECL_CONSTEXPR static inline double dotProduct(const QDoubleVector3D &v1, const QDoubleVector3D &v2)
98 { return v1.xp * v2.xp + v1.yp * v2.yp + v1.zp * v2.zp; }
99
100 Q_DECL_CONSTEXPR static inline QDoubleVector3D crossProduct(const QDoubleVector3D &v1, const QDoubleVector3D &v2)
101 { return QDoubleVector3D(v1.yp * v2.zp - v1.zp * v2.yp,
102 v1.zp * v2.xp - v1.xp * v2.zp,
103 v1.xp * v2.yp - v1.yp * v2.xp); }
104
105 static QDoubleVector3D normal(const QDoubleVector3D &v1, const QDoubleVector3D &v2);
106 static QDoubleVector3D normal
107 (const QDoubleVector3D &v1, const QDoubleVector3D &v2, const QDoubleVector3D &v3);
108
109 double distanceToPlane(const QDoubleVector3D &plane, const QDoubleVector3D &normal) const;
110 double distanceToPlane(const QDoubleVector3D &plane1, const QDoubleVector3D &plane2, const QDoubleVector3D &plane3) const;
111 double distanceToLine(const QDoubleVector3D &point, const QDoubleVector3D &direction) const;
112
113 friend Q_DECL_CONSTEXPR inline bool operator==(const QDoubleVector3D &v1, const QDoubleVector3D &v2);
114 friend Q_DECL_CONSTEXPR inline bool operator!=(const QDoubleVector3D &v1, const QDoubleVector3D &v2);
115 friend Q_DECL_CONSTEXPR inline const QDoubleVector3D operator+(const QDoubleVector3D &v1, const QDoubleVector3D &v2);
116 friend Q_DECL_CONSTEXPR inline const QDoubleVector3D operator-(const QDoubleVector3D &v1, const QDoubleVector3D &v2);
117 friend Q_DECL_CONSTEXPR inline const QDoubleVector3D operator*(double factor, const QDoubleVector3D &vector);
118 friend Q_DECL_CONSTEXPR inline const QDoubleVector3D operator*(const QDoubleVector3D &vector, double factor);
119 friend Q_DECL_CONSTEXPR inline const QDoubleVector3D operator*(const QDoubleVector3D &v1, const QDoubleVector3D &v2);
120 friend Q_DECL_CONSTEXPR inline const QDoubleVector3D operator-(const QDoubleVector3D &vector);
121 friend Q_DECL_CONSTEXPR inline const QDoubleVector3D operator/(const QDoubleVector3D &vector, double divisor);
122
123 friend Q_DECL_CONSTEXPR inline bool qFuzzyCompare(const QDoubleVector3D &v1, const QDoubleVector3D &v2);
124
125 Q_DECL_CONSTEXPR inline QDoubleVector2D toVector2D() const;
126
127private:
128 double xp, yp, zp;
129
130 friend class QDoubleVector2D;
131};
132
133Q_DECLARE_TYPEINFO(QDoubleVector3D, Q_MOVABLE_TYPE);
134
135Q_DECL_CONSTEXPR inline QDoubleVector3D::QDoubleVector3D() : xp(0.0), yp(0.0), zp(0.0) {}
136
137Q_DECL_CONSTEXPR inline QDoubleVector3D::QDoubleVector3D(double xpos, double ypos, double zpos) : xp(xpos), yp(ypos), zp(zpos) {}
138
139Q_DECL_CONSTEXPR inline QDoubleVector3D::QDoubleVector3D(const QDoubleVector2D &v)
140 : xp(v.xp), yp(v.yp), zp(0.0) {}
141
142Q_DECL_CONSTEXPR inline QDoubleVector3D::QDoubleVector3D(const QDoubleVector2D &v, double zpos)
143 : xp(v.xp), yp(v.yp), zp(zpos) {}
144
145inline bool QDoubleVector3D::isNull() const
146{
147 return qIsNull(d: xp) && qIsNull(d: yp) && qIsNull(d: zp);
148}
149
150Q_DECL_CONSTEXPR inline double QDoubleVector3D::x() const { return xp; }
151Q_DECL_CONSTEXPR inline double QDoubleVector3D::y() const { return yp; }
152Q_DECL_CONSTEXPR inline double QDoubleVector3D::z() const { return zp; }
153
154Q_DECL_CONSTEXPR inline double QDoubleVector3D::lengthSquared() const
155{ return xp * xp + yp * yp + zp * zp; }
156
157
158inline void QDoubleVector3D::setX(double aX) { xp = aX; }
159inline void QDoubleVector3D::setY(double aY) { yp = aY; }
160inline void QDoubleVector3D::setZ(double aZ) { zp = aZ; }
161
162inline double QDoubleVector3D::get(int i) const
163{
164 switch (i) {
165 case 0:
166 return xp;
167 case 1:
168 return yp;
169 case 2:
170 return zp;
171 default:
172 return 0.0;
173 }
174}
175
176inline void QDoubleVector3D::set(int i, double value)
177{
178 switch (i) {
179 case 0:
180 xp = value;
181 break;
182 case 1:
183 yp = value;
184 break;
185 case 2:
186 zp = value;
187 break;
188 default:
189 break;
190 }
191}
192
193inline QDoubleVector3D &QDoubleVector3D::operator+=(const QDoubleVector3D &vector)
194{
195 xp += vector.xp;
196 yp += vector.yp;
197 zp += vector.zp;
198 return *this;
199}
200
201inline QDoubleVector3D &QDoubleVector3D::operator-=(const QDoubleVector3D &vector)
202{
203 xp -= vector.xp;
204 yp -= vector.yp;
205 zp -= vector.zp;
206 return *this;
207}
208
209inline QDoubleVector3D &QDoubleVector3D::operator*=(double factor)
210{
211 xp *= factor;
212 yp *= factor;
213 zp *= factor;
214 return *this;
215}
216
217inline QDoubleVector3D &QDoubleVector3D::operator*=(const QDoubleVector3D &vector)
218{
219 xp *= vector.xp;
220 yp *= vector.yp;
221 zp *= vector.zp;
222 return *this;
223}
224
225inline QDoubleVector3D &QDoubleVector3D::operator/=(double divisor)
226{
227 xp /= divisor;
228 yp /= divisor;
229 zp /= divisor;
230 return *this;
231}
232
233Q_DECL_CONSTEXPR inline bool operator==(const QDoubleVector3D &v1, const QDoubleVector3D &v2)
234{
235 return v1.xp == v2.xp && v1.yp == v2.yp && v1.zp == v2.zp;
236}
237
238Q_DECL_CONSTEXPR inline bool operator!=(const QDoubleVector3D &v1, const QDoubleVector3D &v2)
239{
240 return v1.xp != v2.xp || v1.yp != v2.yp || v1.zp != v2.zp;
241}
242
243Q_DECL_CONSTEXPR inline const QDoubleVector3D operator+(const QDoubleVector3D &v1, const QDoubleVector3D &v2)
244{
245 return QDoubleVector3D(v1.xp + v2.xp, v1.yp + v2.yp, v1.zp + v2.zp);
246}
247
248Q_DECL_CONSTEXPR inline const QDoubleVector3D operator-(const QDoubleVector3D &v1, const QDoubleVector3D &v2)
249{
250 return QDoubleVector3D(v1.xp - v2.xp, v1.yp - v2.yp, v1.zp - v2.zp);
251}
252
253Q_DECL_CONSTEXPR inline const QDoubleVector3D operator*(double factor, const QDoubleVector3D &vector)
254{
255 return QDoubleVector3D(vector.xp * factor, vector.yp * factor, vector.zp * factor);
256}
257
258Q_DECL_CONSTEXPR inline const QDoubleVector3D operator*(const QDoubleVector3D &vector, double factor)
259{
260 return QDoubleVector3D(vector.xp * factor, vector.yp * factor, vector.zp * factor);
261}
262
263Q_DECL_CONSTEXPR inline const QDoubleVector3D operator*(const QDoubleVector3D &v1, const QDoubleVector3D &v2)
264{
265 return QDoubleVector3D(v1.xp * v2.xp, v1.yp * v2.yp, v1.zp * v2.zp);
266}
267
268Q_DECL_CONSTEXPR inline const QDoubleVector3D operator-(const QDoubleVector3D &vector)
269{
270 return QDoubleVector3D(-vector.xp, -vector.yp, -vector.zp);
271}
272
273Q_DECL_CONSTEXPR inline const QDoubleVector3D operator/(const QDoubleVector3D &vector, double divisor)
274{
275 return QDoubleVector3D(vector.xp / divisor, vector.yp / divisor, vector.zp / divisor);
276}
277
278Q_DECL_CONSTEXPR inline bool qFuzzyCompare(const QDoubleVector3D &v1, const QDoubleVector3D &v2)
279{
280 return qFuzzyCompare(p1: v1.xp, p2: v2.xp) &&
281 qFuzzyCompare(p1: v1.yp, p2: v2.yp) &&
282 qFuzzyCompare(p1: v1.zp, p2: v2.zp);
283}
284
285Q_DECL_CONSTEXPR inline QDoubleVector2D QDoubleVector3D::toVector2D() const
286{
287 return QDoubleVector2D(xp, yp);
288}
289
290
291#ifndef QT_NO_DEBUG_STREAM
292Q_POSITIONING_EXPORT QDebug operator<<(QDebug dbg, const QDoubleVector3D &vector);
293#endif
294
295#ifndef QT_NO_DATASTREAM
296Q_POSITIONING_EXPORT QDataStream &operator<<(QDataStream &, const QDoubleVector3D &);
297Q_POSITIONING_EXPORT QDataStream &operator>>(QDataStream &, QDoubleVector3D &);
298#endif
299
300QT_END_NAMESPACE
301
302#endif
303

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