Marble

TileCoordsPyramid.cpp
1// SPDX-License-Identifier: LGPL-2.1-or-later
2
3#include "TileCoordsPyramid.h"
4
5#include <MarbleDebug.h>
6#include <QList>
7#include <QRect>
8
9#include <algorithm>
10
11namespace Marble
12{
13
14class Q_DECL_HIDDEN TileCoordsPyramid::Private
15{
16public:
17 Private(int const topLevel, int const bottomLevel);
18
19 int m_topLevel;
20 int m_bottomLevel;
21 QRect m_bottomLevelCoords;
22 QList<int> m_validLevels;
23};
24
25TileCoordsPyramid::Private::Private(int const topLevel, int const bottomLevel)
26 : m_topLevel(topLevel)
27 , m_bottomLevel(bottomLevel)
28{
29 Q_ASSERT(m_topLevel <= m_bottomLevel);
30}
31
32TileCoordsPyramid::TileCoordsPyramid(int const topLevel, int const bottomLevel)
33 : d(new Private(topLevel, bottomLevel))
34{
35}
36
37TileCoordsPyramid::TileCoordsPyramid(TileCoordsPyramid const &other)
38 : d(new Private(*other.d))
39{
40}
41
42TileCoordsPyramid::TileCoordsPyramid()
43 : d(new Private(0, 0))
44{
45}
46
47TileCoordsPyramid &TileCoordsPyramid::operator=(TileCoordsPyramid const &rhs)
48{
49 TileCoordsPyramid temp(rhs);
50 swap(temp);
51 return *this;
52}
53
54TileCoordsPyramid::~TileCoordsPyramid()
55{
56 delete d;
57}
58
59int TileCoordsPyramid::topLevel() const
60{
61 return d->m_topLevel;
62}
63
64int TileCoordsPyramid::bottomLevel() const
65{
66 return d->m_bottomLevel;
67}
68
69void TileCoordsPyramid::setBottomLevelCoords(QRect const &coords)
70{
71 d->m_bottomLevelCoords = coords;
72}
73
74QRect TileCoordsPyramid::coords(int const level) const
75{
76 Q_ASSERT(d->m_topLevel <= level && level <= d->m_bottomLevel);
77 int bottomX1, bottomY1, bottomX2, bottomY2;
78 d->m_bottomLevelCoords.getCoords(&bottomX1, &bottomY1, &bottomX2, &bottomY2);
79 int const deltaLevel = d->m_bottomLevel - level;
80 int const x1 = bottomX1 >> deltaLevel;
81 int const y1 = bottomY1 >> deltaLevel;
82 int const x2 = bottomX2 >> deltaLevel;
83 int const y2 = bottomY2 >> deltaLevel;
84 QRect result;
85 result.setCoords(x1, y1, x2, y2);
86 return result;
87}
88
89void TileCoordsPyramid::setValidTileLevels(const QList<int> validLevels)
90{
91 d->m_validLevels = validLevels;
92}
93
94QList<int> TileCoordsPyramid::validTileLevels()
95{
96 return d->m_validLevels;
97}
98
99qint64 TileCoordsPyramid::tilesCount() const
100{
101 qint64 result = 0;
102 for (int level = d->m_topLevel; level <= d->m_bottomLevel; ++level) {
103 if (!d->m_validLevels.isEmpty() && !d->m_validLevels.contains(level))
104 continue;
105
106 QRect const levelCoords = coords(level);
107 // w*h can exceed 32 bit range, so force 64 bit calculation; see bug 342397
108 result += qint64(levelCoords.width()) * levelCoords.height();
109 }
110 return result;
111}
112
113void TileCoordsPyramid::swap(TileCoordsPyramid &other)
114{
115 std::swap(d, other.d);
116}
117
118}
QStringView level(QStringView ifopt)
Binds a QML item to a specific geodetic location in screen coordinates.
int height() const const
void setCoords(int x1, int y1, int x2, int y2)
int width() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:15:46 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.