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

0001 
0002 // SPDX-License-Identifier: LGPL-2.1-or-later
0003 //
0004 // SPDX-FileCopyrightText: 2013 Adrian Draghici <draghici.adrian.b@gmail.com>
0005 //
0006 
0007 
0008 #include "MarbleGlobal.h"
0009 #include "GeoDataLatLonBox.h"
0010 #include "TestUtils.h"
0011 
0012 namespace Marble
0013 {
0014 
0015 class TestToCircumscribedRectangle : public QObject
0016 {
0017     Q_OBJECT
0018 
0019 private Q_SLOTS:
0020     void testToCircumscribedRectangle_data();
0021     void testToCircumscribedRectangle();
0022 };
0023 
0024 void TestToCircumscribedRectangle::testToCircumscribedRectangle_data()
0025 {
0026     QTest::addColumn<qreal>( "north" );
0027     QTest::addColumn<qreal>( "south" );
0028     QTest::addColumn<qreal>( "east" );
0029     QTest::addColumn<qreal>( "west" );
0030     QTest::addColumn<qreal>( "rotation" );
0031 
0032     QTest::addColumn<qreal>( "expectedNorth" );
0033     QTest::addColumn<qreal>( "expectedSouth" );
0034     QTest::addColumn<qreal>( "expectedEast" );
0035     QTest::addColumn<qreal>( "expectedWest" );
0036 
0037     addRow() << 5.0 << -5.0 << 5.0 << -5.0 << 45.0 << 7.07107 << -7.07107 << 7.07107 << -7.07107;
0038     addRow() << 50.0 << 30.0 << 170.0 << 160.0 << 90.0 << 45.0 << 35.0 << 175.0 << 155.0;
0039     addRow() << 50.0 << 30.0 << 40.0 << 10.0 << 10.0 << 52.4528 << 27.5472 << 41.5086 << 8.4914;
0040     addRow() << 50.0 << 30.0 << -170.0 << 170.0 << 90.0 << 50.0 << 30.0 << -170.0 << 170.0;
0041     addRow() << 50.0 << 30.0 << 20.0 << -10.0 << 90.0 << 55.0 << 25.0 << 15.0 << -5.0;
0042 }
0043 
0044 void TestToCircumscribedRectangle::testToCircumscribedRectangle()
0045 {
0046     QFETCH( qreal, north );
0047     QFETCH( qreal, south );
0048     QFETCH( qreal, east );
0049     QFETCH( qreal, west );
0050     QFETCH( qreal, rotation );
0051 
0052     QFETCH( qreal, expectedNorth );
0053     QFETCH( qreal, expectedSouth );
0054     QFETCH( qreal, expectedEast );
0055     QFETCH( qreal, expectedWest );
0056 
0057     GeoDataLatLonBox box = GeoDataLatLonBox( north, south, east, west, GeoDataCoordinates::Degree );
0058     box.setRotation( rotation, GeoDataCoordinates::Degree );
0059 
0060     GeoDataLatLonBox circumscribedRectangle = box.toCircumscribedRectangle();
0061 
0062     QFUZZYCOMPARE( circumscribedRectangle.north()  * RAD2DEG, expectedNorth, 0.00001 );
0063     QFUZZYCOMPARE( circumscribedRectangle.south() * RAD2DEG, expectedSouth, 0.00001  );
0064     QFUZZYCOMPARE( circumscribedRectangle.east() * RAD2DEG, expectedEast, 0.00001  );
0065     QFUZZYCOMPARE( circumscribedRectangle.west() * RAD2DEG, expectedWest, 0.00001  );
0066 }
0067 
0068 }
0069 
0070 QTEST_MAIN( Marble::TestToCircumscribedRectangle )
0071 
0072 #include "TestToCircumscribedRectangle.moc"