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

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2014 Bernhard Beschow <bbeschow@cs.tu-berlin.de>
0004 //
0005 
0006 #include "GnomonicProjection.h"
0007 #include "ViewportParams.h"
0008 #include "TestUtils.h"
0009 
0010 namespace Marble
0011 {
0012 
0013 class GnomonicProjectionTest : public QObject
0014 {
0015     Q_OBJECT
0016 
0017 private Q_SLOTS:
0018     void screenCoordinatesOfCenter_data();
0019     void screenCoordinatesOfCenter();
0020 };
0021 
0022 void GnomonicProjectionTest::screenCoordinatesOfCenter_data()
0023 {
0024     ViewportParams gnomonic;
0025     gnomonic.setProjection( Gnomonic );
0026 
0027     QTest::addColumn<QPoint>( "screenCoordinates" );
0028     QTest::addColumn<GeoDataCoordinates>( "expected" );
0029 
0030     addRow() << QPoint( 5, 15 ) << GeoDataCoordinates( -45, 72.5536, 0, GeoDataCoordinates::Degree );
0031     addRow() << QPoint( 15, 5 ) << GeoDataCoordinates( 135, 72.5536, 0, GeoDataCoordinates::Degree );
0032 }
0033 
0034 void GnomonicProjectionTest::screenCoordinatesOfCenter()
0035 {
0036     QFETCH( QPoint, screenCoordinates );
0037     QFETCH( GeoDataCoordinates, expected );
0038 
0039     ViewportParams viewport;
0040     viewport.setProjection( Gnomonic );
0041     viewport.setRadius( 180 / 4 ); // for easy mapping of lon <-> x
0042     viewport.setSize( QSize( 20, 20 ) );
0043     viewport.centerOn( 0 * DEG2RAD, 90 * DEG2RAD );
0044 
0045     {
0046         qreal lon, lat;
0047         const bool retval = viewport.geoCoordinates( screenCoordinates.x(), screenCoordinates.y(), lon, lat, GeoDataCoordinates::Degree );
0048 
0049         QVERIFY( retval ); // we want valid coordinates
0050         QCOMPARE( lon, expected.longitude( GeoDataCoordinates::Degree ) );
0051         QFUZZYCOMPARE( lat, expected.latitude( GeoDataCoordinates::Degree ), 0.0001 );
0052     }
0053 }
0054 
0055 }
0056 
0057 QTEST_MAIN( Marble::GnomonicProjectionTest )
0058 
0059 #include "GnomonicProjectionTest.moc"