Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qwebmercator.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#include "qwebmercator_p.h"
4
5#include "qgeocoordinate.h"
6
7#include <qnumeric.h>
8#include <qmath.h>
9
10#include "qdoublevector2d_p.h"
11
13
14// y-Coordinates of maps aproach +-infinity when latitudes approach +-90 and
15// they have to be limited to avoid numerical problems. Here the limit is
16// chosen such that only points below/above +-89.9999999999 deg latituide are
17// cut off, which corresponds to accuracy of qFuzzyCompare
18const static double yCutOff = 4.0;
19
21{
22 const double pi = M_PI;
23
24 double lon = coord.longitude() / 360.0 + 0.5;
25
26 double lat = coord.latitude();
27 lat = 0.5 - (std::log(std::tan((pi / 4.0) + (pi / 2.0) * lat / 180.0)) / pi) / 2.0;
28 lat = qBound(-yCutOff, lat, 1.0 + yCutOff);
29
30 return QDoubleVector2D(lon, lat);
31}
32
33double QWebMercator::realmod(const double a, const double b)
34{
35 quint64 div = static_cast<quint64>(a / b);
36 return a - static_cast<double>(div) * b;
37}
38
40{
41 const double pi = M_PI;
42
43 const double fx = mercator.x();
44 const double fy = mercator.y();
45
46 double lat;
47
48 if (fy <= -yCutOff)
49 lat = 90.0;
50 else if (fy >= 1.0 + yCutOff)
51 lat = -90.0;
52 else
53 lat = (180.0 / pi) * (2.0 * std::atan(std::exp(pi * (1.0 - 2.0 * fy))) - (pi / 2.0));
54
55 double lng;
56 if (fx >= 0) {
57 lng = realmod(fx, 1.0);
58 } else {
59 lng = realmod(1.0 - realmod(-1.0 * fx, 1.0), 1.0);
60 }
61
62 lng = lng * 360.0 - 180.0;
63
64 return QGeoCoordinate(lat, lng, 0.0);
65}
66
68{
71
72 double x;
73
74 if (0.5 < qAbs(e.x() - s.x())) {
75 // handle dateline crossing
76 double ex = e.x();
77 double sx = s.x();
78 if (ex < sx)
79 sx -= 1.0;
80 else if (sx < ex)
81 ex -= 1.0;
82
83 x = (1.0 - progress) * sx + progress * ex;
84
85 if (!qFuzzyIsNull(x) && (x < 0.0))
86 x += 1.0;
87
88 } else {
89 x = (1.0 - progress) * s.x() + progress * e.x();
90 }
91
92 double y = (1.0 - progress) * s.y() + progress * e.y();
93
95 result.setAltitude((1.0 - progress) * from.altitude() + progress * to.altitude());
96
97 return result;
98}
99
Q_DECL_CONSTEXPR double x() const
Q_DECL_CONSTEXPR double y() const
\inmodule QtPositioning
double altitude
This property holds the altitude in meters above sea level.
static QDoubleVector2D coordToMercator(const QGeoCoordinate &coord)
static QGeoCoordinate coordinateInterpolation(const QGeoCoordinate &from, const QGeoCoordinate &to, qreal progress)
static QGeoCoordinate mercatorToCoord(const QDoubleVector2D &mercator)
Combined button and popup list for selecting options.
bool qFuzzyIsNull(qfloat16 f) noexcept
Definition qfloat16.h:349
#define M_PI
Definition qmath.h:209
constexpr const T & qBound(const T &min, const T &val, const T &max)
Definition qminmax.h:44
constexpr T qAbs(const T &t)
Definition qnumeric.h:328
GLboolean GLboolean GLboolean b
GLint GLint GLint GLint GLint x
[0]
GLboolean GLboolean GLboolean GLboolean a
[7]
GLint y
GLdouble s
[6]
Definition qopenglext.h:235
GLuint coord
GLuint64EXT * result
[6]
unsigned long long quint64
Definition qtypes.h:61
double qreal
Definition qtypes.h:187
QT_BEGIN_NAMESPACE static const double yCutOff