File indexing completed on 2022-10-04 14:00:27

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2012 Thibaut Gridel <tgridel@free.fr>
0004 
0005 
0006 #include <QMetaType>
0007 #include "TileId.h"
0008 #include "GeoDataCoordinates.h"
0009 #include "TestUtils.h"
0010 
0011 namespace Marble
0012 {
0013 
0014 class TileIdTest : public QObject
0015 {
0016     Q_OBJECT
0017 
0018 private Q_SLOTS:
0019     void testFromCoordinates_data();
0020     void testFromCoordinates();
0021 
0022 };
0023 
0024 
0025 void TileIdTest::testFromCoordinates_data()
0026 {
0027     QTest::addColumn<qreal>( "lon" );
0028     QTest::addColumn<qreal>( "lat" );
0029     QTest::addColumn<int>( "zoom" );
0030     QTest::addColumn<int>( "x" );
0031     QTest::addColumn<int>( "y" );
0032 
0033     for ( int zoom = 1; zoom < 19; ++zoom) {
0034         int last = (2 << (zoom-1)) -1;
0035         int quarter = qRound(last/4.0);
0036         int mid = qRound(last/2.0);
0037         int three = mid + quarter;
0038 
0039         addRow() << qreal(-180.0) << qreal(0.0) << zoom << 0 << mid;
0040         addRow() <<  qreal(-90.0) << qreal(0.0) << zoom << quarter << mid;
0041         addRow() <<    qreal(0.0) << qreal(0.0) << zoom << mid << mid;
0042         addRow() <<   qreal(90.0) << qreal(0.0) << zoom << three << mid;
0043         addRow() <<  qreal(180.0) << qreal(0.0) << zoom << last << mid;
0044 
0045         addRow() << qreal(-180.0) << qreal(-89.9999) << zoom << 0 << last;
0046         addRow() <<  qreal(-90.0) << qreal(-89.9999) << zoom << quarter << last;
0047         addRow() <<    qreal(0.0) << qreal(-89.9999) << zoom << mid << last;
0048         addRow() <<   qreal(90.0) << qreal(-89.9999) << zoom << three << last;
0049         addRow() <<  qreal(180.0) << qreal(-89.9999) << zoom << last << last;
0050 
0051         addRow() << qreal(-180.0) << qreal(89.9999) << zoom << 0 << 0;
0052         addRow() <<  qreal(-90.0) << qreal(89.9999) << zoom << quarter << 0;
0053         addRow() <<    qreal(0.0) << qreal(89.9999) << zoom << mid << 0;
0054         addRow() <<   qreal(90.0) << qreal(89.9999) << zoom << three << 0;
0055         addRow() <<  qreal(180.0) << qreal(89.9999) << zoom << last << 0;
0056 
0057         addRow() << qreal(-180.0) << qreal(-179.9999) << zoom << 0 << mid;
0058         addRow() <<  qreal(-90.0) << qreal(-179.9999) << zoom << quarter << mid;
0059         addRow() <<    qreal(0.0) << qreal(-179.9999) << zoom << mid << mid;
0060         addRow() <<   qreal(90.0) << qreal(-179.9999) << zoom << three << mid;
0061         addRow() <<  qreal(180.0) << qreal(-179.9999) << zoom << last << mid;
0062 
0063         addRow() << qreal(-180.0) << qreal(179.9999) << zoom << 0 << mid-1;
0064         addRow() <<  qreal(-90.0) << qreal(179.9999) << zoom << quarter << mid-1;
0065         addRow() <<    qreal(0.0) << qreal(179.9999) << zoom << mid << mid-1;
0066         addRow() <<   qreal(90.0) << qreal(179.9999) << zoom << three << mid-1;
0067         addRow() <<  qreal(180.0) << qreal(179.9999) << zoom << last << mid-1;
0068     }
0069 }
0070 
0071 void TileIdTest::testFromCoordinates()
0072 {
0073     QFETCH( qreal, lon );
0074     QFETCH( qreal, lat );
0075     QFETCH( int, zoom);
0076     QFETCH( int, x);
0077     QFETCH( int, y);
0078 
0079     const TileId tile = TileId::fromCoordinates(GeoDataCoordinates( lon , lat, 0, GeoDataCoordinates::Degree), zoom );
0080 
0081     QCOMPARE( tile.x(), x );
0082     QCOMPARE( tile.y(), y );
0083 }
0084 
0085 }
0086 
0087 QTEST_MAIN( Marble::TileIdTest )
0088 
0089 #include "TileIdTest.moc"