File: TestTileProjection.cpp

package info (click to toggle)
marble 4%3A25.08.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 159,996 kB
  • sloc: cpp: 191,890; xml: 39,908; ansic: 7,204; python: 2,190; sh: 1,187; makefile: 235; perl: 218; ruby: 97; java: 66
file content (359 lines) | stat: -rw-r--r-- 17,344 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
/*
    SPDX-FileCopyrightText: 2016 Friedrich W. H. Kossebau <kossebau@kde.org>

    SPDX-License-Identifier: LGPL-2.0-or-later
*/

#include "TestUtils.h"

#include <GeoDataLatLonBox.h>
#include <GeoSceneEquirectTileProjection.h>
#include <GeoSceneMercatorTileProjection.h>
#include <TileId.h>

namespace Marble
{

class TileProjectionTest : public QObject
{
    Q_OBJECT

private Q_SLOTS:
    void testTypeEquirect();
    void testTypeMercator();

    void testLevelZeroColumnsRowsEquirect();
    void testLevelZeroColumnsRowsMercator();

    void testTileIndexesEquirect_data();
    void testTileIndexesEquirect();
    void testTileIndexesMercator_data();
    void testTileIndexesMercator();

    void testGeoCoordinatesEquirect_data();
    void testGeoCoordinatesEquirect();
    void testGeoCoordinatesMercator_data();
    void testGeoCoordinatesMercator();

private:
    void testLevelZeroColumnsRows(GeoSceneAbstractTileProjection &projection);
};

void TileProjectionTest::testLevelZeroColumnsRows(GeoSceneAbstractTileProjection &projection)
{
    // test default
    QCOMPARE(projection.levelZeroColumns(), 1);
    QCOMPARE(projection.levelZeroRows(), 1);

    // test setting a different value
    const int levelZeroColumns = 4;
    const int levelZeroRows = 6;

    projection.setLevelZeroColumns(levelZeroColumns);
    projection.setLevelZeroRows(levelZeroRows);

    QCOMPARE(projection.levelZeroColumns(), levelZeroColumns);
    QCOMPARE(projection.levelZeroRows(), levelZeroRows);
}

void TileProjectionTest::testLevelZeroColumnsRowsEquirect()
{
    GeoSceneEquirectTileProjection projection;
    testLevelZeroColumnsRows(projection);
}

void TileProjectionTest::testLevelZeroColumnsRowsMercator()
{
    GeoSceneMercatorTileProjection projection;
    testLevelZeroColumnsRows(projection);
}

void TileProjectionTest::testTypeEquirect()
{
    GeoSceneEquirectTileProjection projection;
    QCOMPARE(projection.type(), GeoSceneAbstractTileProjection::Equirectangular);
}

void TileProjectionTest::testTypeMercator()
{
    GeoSceneMercatorTileProjection projection;
    QCOMPARE(projection.type(), GeoSceneAbstractTileProjection::Mercator);
}

void TileProjectionTest::testTileIndexesEquirect_data()
{
    QTest::addColumn<qreal>("westLon");
    QTest::addColumn<qreal>("northLat");
    QTest::addColumn<qreal>("eastLon");
    QTest::addColumn<qreal>("southLat");
    QTest::addColumn<int>("zoomLevel");
    QTest::addColumn<int>("expectedTileXWest");
    QTest::addColumn<int>("expectedTileYNorth");
    QTest::addColumn<int>("expectedTileXEast");
    QTest::addColumn<int>("expectedTileYSouth");

    // zoomlevel zero: 1 tile
    // bounds matching the tile map
    addRow() << qreal(-M_PI) << qreal(+M_PI * 0.5) << qreal(+M_PI) << qreal(-M_PI * 0.5) << 0 << 0 << 0 << 0 << 0;
    // bounds inside the 1 tile
    addRow() << qreal(-M_PI * 0.5) << qreal(+M_PI * 0.25) << qreal(+M_PI * 0.5) << qreal(-M_PI * 0.25) << 0 << 0 << 0 << 0 << 0;
    // bounds west and north on tile map borders, with normal border values
    addRow() << qreal(-M_PI) << qreal(+M_PI * 0.5) << qreal(+M_PI * 0.5) << qreal(-M_PI * 0.25) << 0 << 0 << 0 << 0 << 0;
    // bounds west and north on tile map borders, with border values from other map border sides
    addRow() << qreal(+M_PI) << qreal(-M_PI * 0.5) << qreal(+M_PI * 0.5) << qreal(-M_PI * 0.25) << 0 << 0 << 0 << 0 << 0;

    // zoomlevel 1: 2 tiles per dimension
    // bounds matching the tile map
    addRow() << qreal(-M_PI) << qreal(+M_PI * 0.5) << qreal(+M_PI) << qreal(-M_PI * 0.5) << 1 << 0 << 0 << 1 << 1;
    // bounds inside the 4 tiles
    addRow() << qreal(-M_PI * 0.5) << qreal(+M_PI * 0.25) << qreal(+M_PI * 0.5) << qreal(-M_PI * 0.25) << 1 << 0 << 0 << 1 << 1;
    // bounds matching the most north-west tile, with normal border values
    addRow() << qreal(-M_PI) << qreal(+M_PI * 0.5) << qreal(0) << qreal(0) << 1 << 0 << 0 << 0 << 0;
    // bounds matching the most north-west tile, with border values from other map border sides
    addRow() << qreal(+M_PI) << qreal(-M_PI * 0.5) << qreal(0) << qreal(0) << 1 << 0 << 0 << 0 << 0;
    // bounds matching the most south-east tile, with normal border values
    addRow() << qreal(0) << qreal(0) << qreal(+M_PI) << qreal(-M_PI * 0.5) << 1 << 1 << 1 << 1 << 1;
    // bounds matching the most south-east tile, with border values from other map border sides
    addRow() << qreal(0) << qreal(0) << qreal(-M_PI) << qreal(+M_PI * 0.5) << 1 << 1 << 1 << 1 << 1;

    // zoomlevel 9: 2^8==512 tiles per dimension
    // bounds matching the tile map
    addRow() << qreal(-M_PI) << qreal(+M_PI * 0.5) << qreal(+M_PI) << qreal(-M_PI * 0.5) << 9 << 0 << 0 << 511 << 511;
    // bounds inside the outer tiles
    addRow() << qreal(-M_PI * (511 / 512.0)) << qreal(+M_PI * 0.5 * (511 / 512.0)) << qreal(+M_PI * (511 / 512.0)) << qreal(-M_PI * 0.5 * (511 / 512.0)) << 9
             << 0 << 0 << 511 << 511;
    // bounds matching the most north-west tile, with normal border values
    addRow() << qreal(-M_PI) << qreal(+M_PI * 0.5) << qreal(-M_PI * (255 / 256.0)) << qreal(+M_PI * 0.5 * (255 / 256.0)) << 9 << 0 << 0 << 0 << 0;
    // bounds matching the most north-west tile, with border values from other map border sides
    addRow() << qreal(+M_PI) << qreal(-M_PI * 0.5) << qreal(-M_PI * (255 / 256.0)) << qreal(+M_PI * 0.5 * (255 / 256.0)) << 9 << 0 << 0 << 0 << 0;
    // bounds matching the most south-east tile, with normal border values
    addRow() << qreal(+M_PI * (255 / 256.0)) << qreal(-M_PI * 0.5 * (255 / 256.0)) << qreal(+M_PI) << qreal(-M_PI * 0.5) << 9 << 511 << 511 << 511 << 511;
    // bounds matching the most south-east tile, with border values from other map border sides
    addRow() << qreal(+M_PI * (255 / 256.0)) << qreal(-M_PI * 0.5 * (255 / 256.0)) << qreal(-M_PI) << qreal(+M_PI * 0.5) << 9 << 511 << 511 << 511 << 511;
}

void TileProjectionTest::testTileIndexesEquirect()
{
    QFETCH(qreal, westLon);
    QFETCH(qreal, northLat);
    QFETCH(qreal, eastLon);
    QFETCH(qreal, southLat);
    QFETCH(int, zoomLevel);
    QFETCH(int, expectedTileXWest);
    QFETCH(int, expectedTileYNorth);
    QFETCH(int, expectedTileXEast);
    QFETCH(int, expectedTileYSouth);

    GeoDataLatLonBox latLonBox(northLat, southLat, eastLon, westLon);

    const GeoSceneEquirectTileProjection projection;

    const QRect rect = projection.tileIndexes(latLonBox, zoomLevel);

    QCOMPARE(rect.left(), expectedTileXWest);
    QCOMPARE(rect.top(), expectedTileYNorth);
    QCOMPARE(rect.right(), expectedTileXEast);
    QCOMPARE(rect.bottom(), expectedTileYSouth);
}

void TileProjectionTest::testTileIndexesMercator_data()
{
    QTest::addColumn<qreal>("westLon");
    QTest::addColumn<qreal>("northLat");
    QTest::addColumn<qreal>("eastLon");
    QTest::addColumn<qreal>("southLat");
    QTest::addColumn<int>("zoomLevel");
    QTest::addColumn<int>("expectedTileXWest");
    QTest::addColumn<int>("expectedTileYNorth");
    QTest::addColumn<int>("expectedTileXEast");
    QTest::addColumn<int>("expectedTileYSouth");

    // zoomlevel zero: 1 tile
    // bounds matching the tile map up to 90 degree latitude
    addRow() << qreal(-M_PI) << qreal(+M_PI * 0.5) << qreal(+M_PI) << qreal(-M_PI * 0.5) << 0 << 0 << 0 << 0 << 0;
    // bounds matching the tile map with 85 degree latitude limit
    addRow() << qreal(-M_PI) << qreal(85.0 * DEG2RAD) << qreal(+M_PI) << qreal(-85.0 * DEG2RAD) << 0 << 0 << 0 << 0 << 0;
    // bounds inside the 1 tile
    addRow() << qreal(-M_PI * 0.5) << qreal(+M_PI * 0.25) << qreal(+M_PI * 0.5) << qreal(-M_PI * 0.25) << 0 << 0 << 0 << 0 << 0;
    // bounds west and north on tile map borders, with normal border values
    addRow() << qreal(-M_PI) << qreal(+M_PI * 0.5) << qreal(+M_PI * 0.5) << qreal(-M_PI * 0.25) << 0 << 0 << 0 << 0 << 0;
    // bounds west and north on tile map borders, with border values from other map border sides
    addRow() << qreal(+M_PI) << qreal(-M_PI * 0.5) << qreal(+M_PI * 0.5) << qreal(-M_PI * 0.25) << 0 << 0 << 0 << 0 << 0;

    // zoomlevel 1: 2 tiles per dimension
    // bounds matching the tile map up to 90 degree latitude
    addRow() << qreal(-M_PI) << qreal(+M_PI * 0.5) << qreal(+M_PI) << qreal(-M_PI * 0.5) << 1 << 0 << 0 << 1 << 1;
    // bounds matching the tile map with 85 degree latitude limit
    addRow() << qreal(-M_PI) << qreal(85.0 * DEG2RAD) << qreal(+M_PI) << qreal(-85.0 * DEG2RAD) << 1 << 0 << 0 << 1 << 1;
    // bounds inside the 4 tiles
    addRow() << qreal(-M_PI * 0.5) << qreal(+M_PI * 0.25) << qreal(+M_PI * 0.5) << qreal(-M_PI * 0.25) << 1 << 0 << 0 << 1 << 1;
    // bounds matching the most north-west tile, with normal border values
    addRow() << qreal(-M_PI) << qreal(+M_PI * 0.5) << qreal(0) << qreal(0) << 1 << 0 << 0 << 0 << 0;
    // bounds matching the most north-west tile, with border values from other map border sides
    addRow() << qreal(+M_PI) << qreal(-M_PI * 0.5) << qreal(0) << qreal(0) << 1 << 0 << 0 << 0 << 0;
    // bounds matching the most south-east tile, with normal border values
    addRow() << qreal(0) << qreal(0) << qreal(+M_PI) << qreal(-M_PI * 0.5) << 1 << 1 << 1 << 1 << 1;
    // bounds matching the most south-east tile, with border values from other map border sides
    addRow() << qreal(0) << qreal(0) << qreal(-M_PI) << qreal(+M_PI * 0.5) << 1 << 1 << 1 << 1 << 1;

    // zoomlevel 9: 2^8==512 tiles per dimension
    // GeoSceneMercatorTileProjection bounds latitude value at +/- 85.0 degree (so not at 85.05113),
    // which results in some tiles missed at the outer sides.
    // bounds matching the tile map up to 90 degree latitude
    addRow() << qreal(-M_PI) << qreal(+M_PI * 0.5) << qreal(+M_PI) << qreal(-M_PI * 0.5) << 9 << 0 << 5 << 511 << 506;
    // bounds matching the tile map with 85 degree latitude limit
    addRow() << qreal(-M_PI) << qreal(85.0 * DEG2RAD) << qreal(+M_PI) << qreal(-85.0 * DEG2RAD) << 9 << 0 << 5 << 511 << 506;
    // bounds inside the outer tiles
    addRow() << qreal(-M_PI * (511 / 512.0)) << qreal(+M_PI * 0.5 * (511 / 512.0)) << qreal(+M_PI * (511 / 512.0)) << qreal(-M_PI * 0.5 * (511 / 512.0)) << 9
             << 0 << 5 << 511 << 506;
    // bounds matching the most north-west tile, with normal border values
    addRow() << qreal(-M_PI) << qreal(+M_PI * 0.5) << qreal(-M_PI * (255 / 256.0)) << qreal(+M_PI * 0.5 * (255 / 256.0)) << 9 << 0 << 5 << 0 << 5;
    // bounds matching the most north-west tile, with border values from other map border sides
    addRow() << qreal(+M_PI) << qreal(-M_PI * 0.5) << qreal(-M_PI * (255 / 256.0)) << qreal(+M_PI * 0.5 * (255 / 256.0)) << 9 << 0 << 5 << 0 << 5;
    // bounds matching the most south-east tile, with normal border values
    addRow() << qreal(+M_PI * (255 / 256.0)) << qreal(-M_PI * 0.5 * (255 / 256.0)) << qreal(+M_PI) << qreal(-M_PI * 0.5) << 9 << 511 << 506 << 511 << 506;
    // bounds matching the most south-east tile, with border values from other map border sides
    addRow() << qreal(+M_PI * (255 / 256.0)) << qreal(-M_PI * 0.5 * (255 / 256.0)) << qreal(-M_PI) << qreal(+M_PI * 0.5) << 9 << 511 << 506 << 511 << 506;
}

void TileProjectionTest::testTileIndexesMercator()
{
    QFETCH(qreal, westLon);
    QFETCH(qreal, northLat);
    QFETCH(qreal, eastLon);
    QFETCH(qreal, southLat);
    QFETCH(int, zoomLevel);
    QFETCH(int, expectedTileXWest);
    QFETCH(int, expectedTileYNorth);
    QFETCH(int, expectedTileXEast);
    QFETCH(int, expectedTileYSouth);

    GeoDataLatLonBox latLonBox(northLat, southLat, eastLon, westLon);

    const GeoSceneMercatorTileProjection projection;

    const QRect rect = projection.tileIndexes(latLonBox, zoomLevel);

    QCOMPARE(rect.left(), expectedTileXWest);
    QCOMPARE(rect.top(), expectedTileYNorth);
    QCOMPARE(rect.right(), expectedTileXEast);
    QCOMPARE(rect.bottom(), expectedTileYSouth);
}

void TileProjectionTest::testGeoCoordinatesEquirect_data()
{
    QTest::addColumn<int>("tileX");
    QTest::addColumn<int>("tileY");
    QTest::addColumn<int>("zoomLevel");
    QTest::addColumn<qreal>("expectedWesternTileEdgeLon");
    QTest::addColumn<qreal>("expectedNorthernTileEdgeLat");
    QTest::addColumn<qreal>("expectedEasternTileEdgeLon");
    QTest::addColumn<qreal>("expectedSouthernTileEdgeLat");

    // zoomlevel zero: 1 tile
    addRow() << 0 << 0 << 0 << qreal(-M_PI) << qreal(+M_PI * 0.5) << qreal(+M_PI) << qreal(-M_PI * 0.5);

    // zoomlevel 1: 2 tiles per dimension
    addRow() << 0 << 0 << 1 << qreal(-M_PI) << qreal(+M_PI * 0.5) << qreal(0) << qreal(0);
    addRow() << 0 << 1 << 1 << qreal(-M_PI) << qreal(0) << qreal(0) << qreal(-M_PI * 0.5);
    addRow() << 1 << 0 << 1 << qreal(0) << qreal(+M_PI * 0.5) << qreal(+M_PI) << qreal(0);
    addRow() << 1 << 1 << 1 << qreal(0) << qreal(0) << qreal(+M_PI) << qreal(-M_PI * 0.5);

    // zoomlevel 9: 2^8==512 tiles per dimension
    addRow() << 0 << 0 << 9 << qreal(-M_PI) << qreal(+M_PI * 0.5) << qreal(-M_PI * (255 / 256.0)) << qreal(+M_PI * 0.5 * (255 / 256.0));
    addRow() << 0 << 256 << 9 << qreal(-M_PI) << qreal(0) << qreal(-M_PI * (255 / 256.0)) << qreal(-M_PI * 0.5 * (1 / 256.0));
    addRow() << 256 << 0 << 9 << qreal(0) << qreal(+M_PI * 0.5) << qreal(M_PI * (1 / 256.0)) << qreal(+M_PI * 0.5 * (255 / 256.0));
    addRow() << 511 << 511 << 9 << qreal(M_PI * (255 / 256.0)) << qreal(-M_PI * 0.5 * (255 / 256.0)) << qreal(+M_PI) << qreal(-M_PI * 0.5);
}

void TileProjectionTest::testGeoCoordinatesEquirect()
{
    QFETCH(int, tileX);
    QFETCH(int, tileY);
    QFETCH(int, zoomLevel);
    QFETCH(qreal, expectedWesternTileEdgeLon);
    QFETCH(qreal, expectedNorthernTileEdgeLat);
    QFETCH(qreal, expectedEasternTileEdgeLon);
    QFETCH(qreal, expectedSouthernTileEdgeLat);

    const GeoSceneEquirectTileProjection projection;

    // method variants with GeoDataLatLonBox
    const GeoDataLatLonBox latLonBox = projection.geoCoordinates(zoomLevel, tileX, tileY);

    QCOMPARE(latLonBox.west(), expectedWesternTileEdgeLon);
    QCOMPARE(latLonBox.north(), expectedNorthernTileEdgeLat);
    QCOMPARE(latLonBox.east(), expectedEasternTileEdgeLon);
    QCOMPARE(latLonBox.south(), expectedSouthernTileEdgeLat);

    TileId tileId(QStringLiteral("testmap"), zoomLevel, tileX, tileY);
    const GeoDataLatLonBox latLonBox2 = projection.geoCoordinates(tileId);

    QCOMPARE(latLonBox2.west(), expectedWesternTileEdgeLon);
    QCOMPARE(latLonBox2.north(), expectedNorthernTileEdgeLat);
    QCOMPARE(latLonBox2.east(), expectedEasternTileEdgeLon);
    QCOMPARE(latLonBox2.south(), expectedSouthernTileEdgeLat);
}

void TileProjectionTest::testGeoCoordinatesMercator_data()
{
    QTest::addColumn<int>("tileX");
    QTest::addColumn<int>("tileY");
    QTest::addColumn<int>("zoomLevel");
    QTest::addColumn<qreal>("expectedWesternTileEdgeLon");
    QTest::addColumn<qreal>("expectedNorthernTileEdgeLat");
    QTest::addColumn<qreal>("expectedEasternTileEdgeLon");
    QTest::addColumn<qreal>("expectedSouthernTileEdgeLat");

    const qreal absMaxLat = DEG2RAD * 85.05113;

    // zoomlevel zero: 1 tile
    addRow() << 0 << 0 << 0 << qreal(-M_PI) << qreal(+absMaxLat) << qreal(+M_PI) << qreal(-absMaxLat);

    // zoomlevel 1: 2 tiles per dimension
    addRow() << 0 << 0 << 1 << qreal(-M_PI) << qreal(+absMaxLat) << qreal(0) << qreal(0);
    addRow() << 0 << 1 << 1 << qreal(-M_PI) << qreal(0) << qreal(0) << qreal(-absMaxLat);
    addRow() << 1 << 0 << 1 << qreal(0) << qreal(+absMaxLat) << qreal(+M_PI) << qreal(0);
    addRow() << 1 << 1 << 1 << qreal(0) << qreal(0) << qreal(+M_PI) << qreal(-absMaxLat);

    // zoomlevel 9: 2^8==512 tiles per dimension
    addRow() << 0 << 0 << 9 << qreal(-M_PI) << qreal(+absMaxLat) << qreal(-M_PI * (255 / 256.0)) << qreal(+1.48336);
    addRow() << 0 << 256 << 9 << qreal(-M_PI) << qreal(0) << qreal(-M_PI * (255 / 256.0)) << qreal(-0.0122715);
    addRow() << 256 << 0 << 9 << qreal(0) << qreal(+absMaxLat) << qreal(M_PI * (1 / 256.0)) << qreal(+1.48336);
    addRow() << 511 << 511 << 9 << qreal(M_PI * (255 / 256.0)) << qreal(-1.48336) << qreal(+M_PI) << qreal(-absMaxLat);
}

void TileProjectionTest::testGeoCoordinatesMercator()
{
    QFETCH(int, tileX);
    QFETCH(int, tileY);
    QFETCH(int, zoomLevel);
    QFETCH(qreal, expectedWesternTileEdgeLon);
    QFETCH(qreal, expectedNorthernTileEdgeLat);
    QFETCH(qreal, expectedEasternTileEdgeLon);
    QFETCH(qreal, expectedSouthernTileEdgeLat);

    const GeoSceneMercatorTileProjection projection;

    // method variants with GeoDataLatLonBox
    const GeoDataLatLonBox latLonBox = projection.geoCoordinates(zoomLevel, tileX, tileY);

    QCOMPARE(latLonBox.west(), expectedWesternTileEdgeLon);
    QFUZZYCOMPARE(latLonBox.north(), expectedNorthernTileEdgeLat, 0.00001);
    QCOMPARE(latLonBox.east(), expectedEasternTileEdgeLon);
    QFUZZYCOMPARE(latLonBox.south(), expectedSouthernTileEdgeLat, 0.00001);

    TileId tileId(QStringLiteral("testmap"), zoomLevel, tileX, tileY);
    const GeoDataLatLonBox latLonBox2 = projection.geoCoordinates(tileId);

    QCOMPARE(latLonBox2.west(), expectedWesternTileEdgeLon);
    QFUZZYCOMPARE(latLonBox2.north(), expectedNorthernTileEdgeLat, 0.00001);
    QCOMPARE(latLonBox2.east(), expectedEasternTileEdgeLon);
    QFUZZYCOMPARE(latLonBox2.south(), expectedSouthernTileEdgeLat, 0.00001);
}

} // namespace Marble

QTEST_MAIN(Marble::TileProjectionTest)

#include "TestTileProjection.moc"