Marble

GeoSceneEquirectTileProjection.cpp
1/*
2 SPDX-FileCopyrightText: 2016 Friedrich W. H. Kossebau <kossebau@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "GeoSceneEquirectTileProjection.h"
8
9#include <GeoDataLatLonBox.h>
10
11namespace Marble
12{
13
15
16GeoSceneEquirectTileProjection::~GeoSceneEquirectTileProjection() = default;
17
18GeoSceneAbstractTileProjection::Type GeoSceneEquirectTileProjection::type() const
19{
20 return Equirectangular;
21}
22
23static inline unsigned int lowerBoundTileIndex(qreal baseTileIndex)
24{
25 const qreal floorBaseTileIndex = floor(baseTileIndex);
26 auto tileIndex = static_cast<unsigned int>(floorBaseTileIndex);
27 return (baseTileIndex == floorBaseTileIndex) ? tileIndex - 1 : tileIndex;
28}
29
30static inline unsigned int upperBoundTileIndex(qreal baseTileIndex)
31{
32 return (unsigned int)floor(baseTileIndex);
33}
34
35static inline qreal baseTileXFromLon(qreal lon, unsigned int tileCount)
36{
37 return 0.5 * (lon / M_PI + 1.0) * tileCount;
38}
39
40static inline qreal baseTileYFromLat(qreal lat, unsigned int tileCount)
41{
42 return (0.5 - lat / M_PI) * tileCount;
43}
44
45// on tile borders selects the tile to the east
46static inline unsigned int eastBoundTileXFromLon(qreal lon, unsigned int tileCount)
47{
48 // special casing tile-map end
49 if (lon == M_PI) {
50 return 0;
51 }
52 return upperBoundTileIndex(baseTileXFromLon(lon, tileCount));
53}
54
55// on tile borders selects the tile to the west
56static inline unsigned int westBoundTileXFromLon(qreal lon, unsigned int tileCount)
57{
58 // special casing tile-map end
59 if (lon == -M_PI) {
60 return tileCount - 1;
61 }
62 return lowerBoundTileIndex(baseTileXFromLon(lon, tileCount));
63}
64
65// on tile borders selects the tile to the south
66static inline unsigned int southBoundTileYFromLat(qreal lat, unsigned int tileCount)
67{
68 // special casing tile-map end
69 if (lat == -M_PI * 0.5) {
70 return 0;
71 }
72 return upperBoundTileIndex(baseTileYFromLat(lat, tileCount));
73}
74
75// on tile borders selects the tile to the north
76static inline unsigned int northBoundTileYFromLat(qreal lat, unsigned int tileCount)
77{
78 // special casing tile-map end
79 if (lat == M_PI * 0.5) {
80 return tileCount - 1;
81 }
82 return lowerBoundTileIndex(baseTileYFromLat(lat, tileCount));
83}
84
86{
87 const unsigned int xTileCount = (1 << zoomLevel) * levelZeroColumns();
88
89 const int westX = eastBoundTileXFromLon(latLonBox.west(), xTileCount);
90 const int eastX = westBoundTileXFromLon(latLonBox.east(), xTileCount);
91
92 const unsigned int yTileCount = (1 << zoomLevel) * levelZeroRows();
93
94 const int northY = southBoundTileYFromLat(latLonBox.north(), yTileCount);
95 const int southY = northBoundTileYFromLat(latLonBox.south(), yTileCount);
96
97 return QRect(QPoint(westX, northY), QPoint(eastX, southY));
98}
99
101{
102 const qreal radiusX = (1 << zoomLevel) * levelZeroColumns() / 2.0;
103 const qreal radiusY = (1 << zoomLevel) * levelZeroRows() / 2.0;
104
105 const qreal west = (x - radiusX) / radiusX * M_PI;
106 const qreal north = (radiusY - y) / radiusY * M_PI / 2.0;
107
108 const qreal east = ((x + 1) - radiusX) / radiusX * M_PI;
109 const qreal south = (radiusY - (y + 1)) / radiusY * M_PI / 2.0;
110
111 return {north, south, east, west};
112}
113
114}
A class that defines a 2D bounding box for geographic data.
qreal north(GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian) const
Get the northern boundary of the bounding box.
qreal east(GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian) const
Get the eastern boundary of the bounding box.
qreal west(GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian) const
Get the western boundary of the bounding box.
qreal south(GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian) const
Get the southern boundary of the bounding box.
GeoSceneEquirectTileProjection()
Construct a new GeoSceneEquirectTileProjection.
GeoDataLatLonBox geoCoordinates(int zoomLevel, int x, int y) const override
QRect tileIndexes(const GeoDataLatLonBox &latLonBox, int zoomLevel) const override
GeoSceneAbstractTileProjection::Type type() const override
Binds a QML item to a specific geodetic location in screen coordinates.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:04:14 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.