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

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2009 Bastian Holst <bastianholst@gmx.de>
0004 //
0005 
0006 #include <QObject>
0007 
0008 #include "GeoDataCoordinates.h"
0009 #include "GeoDataLinearRing.h"
0010 #include "GeoDataLatLonAltBox.h"
0011 
0012 namespace Marble
0013 {
0014 
0015 class GeoDataLatLonAltBoxTest : public QObject
0016 {
0017     Q_OBJECT
0018 
0019  private Q_SLOTS:
0020     void fromLineStringTest();
0021 
0022  private:
0023     qreal randomLon();
0024     qreal randomLat();
0025 };
0026 
0027 
0028 void GeoDataLatLonAltBoxTest::fromLineStringTest()
0029 {
0030     qreal west = randomLon();
0031     qreal east = randomLon();
0032     qreal lat1 = randomLat();
0033     qreal lat2 = randomLat();
0034     GeoDataLatLonAltBox sourceBox;
0035 
0036     if ( lat1 >= lat2 ) {
0037         sourceBox = GeoDataLatLonBox( lat1, lat2, east, west, GeoDataCoordinates::Degree );
0038     }
0039     else {
0040         sourceBox = GeoDataLatLonBox( lat2, lat1, east, west, GeoDataCoordinates::Degree );
0041     }
0042 
0043     GeoDataLinearRing ring;
0044     // SouthWest
0045     ring << GeoDataCoordinates( sourceBox.west(), sourceBox.south() );
0046     // SouthEast
0047     ring << GeoDataCoordinates( sourceBox.east(), sourceBox.south() );
0048     // NorthEast
0049     ring << GeoDataCoordinates( sourceBox.east(), sourceBox.north() );
0050     // NorthWest
0051     ring << GeoDataCoordinates( sourceBox.west(), sourceBox.north() );
0052 
0053     QCOMPARE( GeoDataLatLonAltBox::fromLineString( ring ).toString(), sourceBox.toString() );
0054 
0055 }
0056 
0057 qreal GeoDataLatLonAltBoxTest::randomLon()
0058 {
0059     qreal lon = qrand();
0060     while ( lon < -180 ) {
0061         lon += 360;
0062     }
0063     while ( lon > 180 ) {
0064         lon -= 360;
0065     }
0066 
0067     return lon;
0068 }
0069 
0070 qreal GeoDataLatLonAltBoxTest::randomLat()
0071 {
0072     qreal lat = qrand();
0073     while ( lat < -90 ) {
0074         lat += 180;
0075     }
0076     while ( lat > 90 ) {
0077         lat -= 180;
0078     }
0079 
0080     return lat;
0081 }
0082 
0083 } // namespace Marble
0084 
0085 QTEST_MAIN( Marble::GeoDataLatLonAltBoxTest )
0086 
0087 #include "GeoDataLatLonAltBoxTest.moc"