File indexing completed on 2024-04-14 14:16:35

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 
0003 // SPDX-FileCopyrightText: 2009 Bastian Holst <bastianholst@gmx.de>
0004 // SPDX-FileCopyrightText: 2010 Cezar Mocan <mocancezar@gmail.com>
0005 // SPDX-FileCopyrightText: 2012 Bernhard Beschow <bbeschow@cs.tu-berlin.de>
0006 
0007 #include "GeoDataCoordinates.h"
0008 #include "GeoDataFolder.h"
0009 #include "GeoDataLineString.h"
0010 #include "GeoDataLinearRing.h"
0011 #include "GeoDataLatLonAltBox.h"
0012 #include "GeoDataLatLonBox.h"
0013 #include "GeoDataPlacemark.h"
0014 
0015 #include <QTest>
0016 #include <QBuffer>
0017 
0018 using namespace Marble;
0019 
0020 class TestGeoDataLatLonAltBox : public QObject
0021 {
0022     Q_OBJECT
0023 
0024 private Q_SLOTS:
0025     void testDefaultConstruction();
0026     void testCopyConstruction_data();
0027     void testCopyConstruction();
0028     void testConstructionFromLatLonBox_data();
0029     void testConstructionFromLatLonBox();
0030     void testAssignment_data();
0031     void testAssignment();
0032     void testContstructionFromCoordinates_data();
0033     void testContstructionFromCoordinates();
0034     void testAltitude_data();
0035     void testAltitude();
0036     void testSetNorthRadian_data();
0037     void testSetNorthRadian();
0038     void testSetSouthRadian_data();
0039     void testSetSouthRadian();
0040     void testContains();
0041     void testIntersects_data();
0042     void testIntersects();
0043     void testCrossesDateline_data();
0044     void testCrossesDateline();
0045     void testCenter_data();
0046     void testCenter();
0047     void testUnited_data();
0048     void testUnited();
0049 
0050     void testFromLineString_data();
0051     void testFromLineString();
0052     void testToString_data();
0053     void testToString();
0054     void testPack_data();
0055     void testPack();
0056     void testContainerBox_data();
0057     void testContainerBox();
0058     void testScale_data();
0059     void testScale();
0060 };
0061 
0062 void TestGeoDataLatLonAltBox::testDefaultConstruction()
0063 {
0064     GeoDataLatLonBox const latLonBox;
0065 
0066     QCOMPARE( latLonBox.north(), 0.0 );
0067     QCOMPARE( latLonBox.south(), 0.0 );
0068     QCOMPARE( latLonBox.east(), 0.0 );
0069     QCOMPARE( latLonBox.west(), 0.0 );
0070     QCOMPARE( latLonBox.rotation(), 0.0 );
0071     QCOMPARE( latLonBox.width(), 0.0 );
0072     QCOMPARE( latLonBox.height(), 0.0 );
0073     QVERIFY( !latLonBox.crossesDateLine() );
0074     QCOMPARE( latLonBox.center(), GeoDataCoordinates( 0, 0 ) );
0075     QVERIFY( latLonBox.isNull() );
0076     QVERIFY( latLonBox.isEmpty() );
0077 
0078     QVERIFY( (latLonBox|latLonBox).isNull() );
0079     QVERIFY( (latLonBox|latLonBox).isEmpty() );
0080     QVERIFY( !latLonBox.intersects( latLonBox ) );
0081 
0082 
0083     GeoDataLatLonAltBox const latLonAltBox;
0084 
0085     QCOMPARE( latLonAltBox.north(), 0.0 );
0086     QCOMPARE( latLonAltBox.south(), 0.0 );
0087     QCOMPARE( latLonAltBox.east(), 0.0 );
0088     QCOMPARE( latLonAltBox.west(), 0.0 );
0089     QCOMPARE( latLonAltBox.rotation(), 0.0 );
0090     QCOMPARE( latLonAltBox.width(), 0.0 );
0091     QCOMPARE( latLonAltBox.height(), 0.0 );
0092     QVERIFY( !latLonAltBox.crossesDateLine() );
0093     QCOMPARE( latLonAltBox.center(), GeoDataCoordinates( 0, 0, 0 ) );
0094     QVERIFY( latLonAltBox.isNull() );
0095     QVERIFY( latLonAltBox.isEmpty() );
0096     QCOMPARE( latLonAltBox.minAltitude(), 0.0 );
0097     QCOMPARE( latLonAltBox.maxAltitude(), 0.0 );
0098     QCOMPARE( latLonAltBox.altitudeMode(), ClampToGround );
0099 
0100     QVERIFY( (latLonAltBox|latLonAltBox).isNull() );
0101     QVERIFY( (latLonAltBox|latLonAltBox).isEmpty() );
0102     QVERIFY( !latLonAltBox.intersects( latLonAltBox ) );
0103 }
0104 
0105 void TestGeoDataLatLonAltBox::testCopyConstruction_data()
0106 {
0107     QTest::addColumn<GeoDataLatLonAltBox>("expected");
0108 
0109     QTest::newRow("null") << GeoDataLatLonAltBox();
0110 }
0111 
0112 void TestGeoDataLatLonAltBox::testCopyConstruction()
0113 {
0114     QFETCH(GeoDataLatLonAltBox, expected);
0115 
0116     GeoDataLatLonAltBox const result(expected);
0117 
0118     QCOMPARE(result, expected);
0119 }
0120 
0121 void TestGeoDataLatLonAltBox::testConstructionFromLatLonBox_data()
0122 {
0123     QTest::addColumn<GeoDataLatLonBox>("latLonBox");
0124     QTest::addColumn<qreal>("minAltitude");
0125     QTest::addColumn<qreal>("maxAltitude");
0126 
0127     QTest::newRow("deg") << GeoDataLatLonBox(15.0, 180.0, 90.0, 118.0, GeoDataCoordinates::Degree) << qreal(143.0) << qreal(356.0);
0128     QTest::newRow("rad") << GeoDataLatLonBox(1.0, 2.2, 1.8, 1.4, GeoDataCoordinates::Radian) << qreal(112.0) << qreal(120.0);
0129 }
0130 
0131 void TestGeoDataLatLonAltBox::testConstructionFromLatLonBox()
0132 {
0133     QFETCH(GeoDataLatLonBox, latLonBox);
0134     QFETCH(qreal, minAltitude);
0135     QFETCH(qreal, maxAltitude);
0136 
0137     GeoDataLatLonAltBox const box(latLonBox, minAltitude, maxAltitude);
0138 
0139     QCOMPARE(box.west(), latLonBox.west());
0140     QCOMPARE(box.east(), latLonBox.east());
0141     QCOMPARE(box.north(), latLonBox.north());
0142     QCOMPARE(box.south(), latLonBox.south());
0143     QCOMPARE(box.rotation(), latLonBox.rotation());
0144     QCOMPARE(box.minAltitude(), minAltitude);
0145     QCOMPARE(box.maxAltitude(), maxAltitude);
0146 }
0147 
0148 void TestGeoDataLatLonAltBox::testAssignment_data()
0149 {
0150     QTest::addColumn<GeoDataLatLonAltBox>("expected");
0151 
0152     QTest::newRow("deg") << GeoDataLatLonAltBox(GeoDataLatLonBox( 15.0, 180.0, 90.0, 118.0, GeoDataCoordinates::Degree), 143.0, 356.0);
0153     QTest::newRow("rad") << GeoDataLatLonAltBox(GeoDataLatLonBox( 1.0, 2.2, 1.8, 1.4, GeoDataCoordinates::Radian ), 112.0, 120.0);
0154 }
0155 
0156 void TestGeoDataLatLonAltBox::testAssignment()
0157 {
0158     QFETCH(GeoDataLatLonAltBox, expected);
0159 
0160     GeoDataLatLonAltBox other = expected;
0161 
0162     QCOMPARE( expected, other );
0163 }
0164 
0165 void TestGeoDataLatLonAltBox::testContstructionFromCoordinates_data()
0166 {
0167     QTest::addColumn<GeoDataCoordinates>("coordinates");
0168 
0169     QTest::newRow("deg") << GeoDataCoordinates(90.0, 15.0, 10.0, GeoDataCoordinates::Degree);
0170     QTest::newRow("rad") << GeoDataCoordinates(1.8, 1.0, 61.0, GeoDataCoordinates::Radian);
0171 }
0172 
0173 void TestGeoDataLatLonAltBox::testContstructionFromCoordinates()
0174 {
0175     QFETCH(GeoDataCoordinates, coordinates);
0176 
0177     GeoDataLatLonAltBox const box(coordinates);
0178 
0179     QCOMPARE(box.east(), coordinates.longitude());
0180     QCOMPARE(box.west(), coordinates.longitude());
0181     QCOMPARE(box.north(), coordinates.latitude());
0182     QCOMPARE(box.south(), coordinates.latitude());
0183     QCOMPARE(box.minAltitude(), coordinates.altitude());
0184     QCOMPARE(box.maxAltitude(), coordinates.altitude());
0185 }
0186 
0187 void TestGeoDataLatLonAltBox::testAltitude_data() 
0188 {
0189     QTest::addColumn<qreal>("alt");
0190 
0191     QTest::newRow("Altitude 1") << qreal(27.2);
0192     QTest::newRow("Altitude 2") << qreal(0.22);
0193 }
0194 
0195 void TestGeoDataLatLonAltBox::testAltitude() 
0196 {
0197     QFETCH(qreal, alt);
0198 
0199     GeoDataLatLonAltBox box;
0200     box.setMinAltitude(alt);
0201     QCOMPARE(box.minAltitude(), alt);
0202 
0203     box.setMaxAltitude(alt);
0204     QCOMPARE(box.maxAltitude(), alt);
0205 }
0206 
0207 void TestGeoDataLatLonAltBox::testSetNorthRadian_data()
0208 {
0209     QTest::addColumn<GeoDataLatLonAltBox>("box");
0210     QTest::addColumn<qreal>("north");
0211 
0212     QTest::newRow("deg") << GeoDataLatLonAltBox(GeoDataLatLonBox( 15.0, 180.0, 90.0, 118.0, GeoDataCoordinates::Degree), 143.0, 356.0) << qreal(0.1);
0213     QTest::newRow("rad") << GeoDataLatLonAltBox(GeoDataLatLonBox( 1.0, 2.2, 1.8, 1.4, GeoDataCoordinates::Radian ), 112.0, 120.0) << qreal(0.1);
0214 }
0215 
0216 void TestGeoDataLatLonAltBox::testSetNorthRadian()
0217 {
0218     QFETCH(GeoDataLatLonAltBox, box);
0219     QFETCH(qreal, north);
0220 
0221     box.setNorth( north );
0222 
0223     QCOMPARE( box.north(), north );
0224 }
0225 
0226 void TestGeoDataLatLonAltBox::testSetSouthRadian_data()
0227 {
0228     QTest::addColumn<GeoDataLatLonAltBox>("box");
0229     QTest::addColumn<qreal>("south");
0230 
0231     QTest::newRow("deg") << GeoDataLatLonAltBox(GeoDataLatLonBox( 15.0, 180.0, 90.0, 118.0, GeoDataCoordinates::Degree), 143.0, 356.0) << qreal(1.4);
0232     QTest::newRow("rad") << GeoDataLatLonAltBox(GeoDataLatLonBox( 1.0, 2.2, 1.8, 1.4, GeoDataCoordinates::Radian ), 112.0, 120.0) << qreal(1.4);
0233 }
0234 
0235 void TestGeoDataLatLonAltBox::testSetSouthRadian()
0236 {
0237     QFETCH(GeoDataLatLonAltBox, box);
0238     QFETCH(qreal, south);
0239 
0240     box.setSouth( south );
0241 
0242     QCOMPARE( box.south(), south );
0243 }
0244 
0245 void TestGeoDataLatLonAltBox::testContains()
0246 {
0247     GeoDataLatLonAltBox const largeBox = GeoDataLatLonAltBox::fromLineString( GeoDataLineString()
0248             << GeoDataCoordinates( -20.0, +10.0, 15.0, GeoDataCoordinates::Degree )
0249             << GeoDataCoordinates( +20.0, -10.0, 25.0, GeoDataCoordinates::Degree ) );
0250     GeoDataLatLonAltBox const smallBox = GeoDataLatLonAltBox::fromLineString( GeoDataLineString()
0251             << GeoDataCoordinates( -2.0, +1.0, 18.0, GeoDataCoordinates::Degree )
0252             << GeoDataCoordinates( +2.0, -1.0, 22.0, GeoDataCoordinates::Degree ) );
0253 
0254     QVERIFY( largeBox.contains( GeoDataCoordinates( 5.0, 5.0, 20.0, GeoDataCoordinates::Degree ) ) );
0255     QVERIFY( largeBox.contains( smallBox ) );
0256     QVERIFY( largeBox.contains( largeBox ) );
0257     QVERIFY( !smallBox.contains( largeBox ) );
0258     QVERIFY(  smallBox.contains( GeoDataCoordinates(    0.0,   0.0, 20.0, GeoDataCoordinates::Degree ) ) );
0259     QVERIFY( !largeBox.contains( GeoDataCoordinates(   5.0,   5.0, 30.0, GeoDataCoordinates::Degree ) ) );
0260     QVERIFY( !largeBox.contains( GeoDataCoordinates(   5.0,   5.0, 10.0, GeoDataCoordinates::Degree ) ) );
0261     QVERIFY( !largeBox.contains( GeoDataCoordinates(  35.0,   5.0, 20.0, GeoDataCoordinates::Degree ) ) );
0262     QVERIFY( !largeBox.contains( GeoDataCoordinates( -35.0,   5.0, 20.0, GeoDataCoordinates::Degree ) ) );
0263     QVERIFY( !largeBox.contains( GeoDataCoordinates(   5.0,  35.0, 20.0, GeoDataCoordinates::Degree ) ) );
0264     QVERIFY( !largeBox.contains( GeoDataCoordinates(   5.0, -35.0, 20.0, GeoDataCoordinates::Degree ) ) );
0265 }
0266 
0267 void TestGeoDataLatLonAltBox::testIntersects_data()
0268 {
0269     QTest::addColumn<GeoDataLatLonBox>( "latLonBox1" );
0270     QTest::addColumn<qreal>( "box1minAltitude" );
0271     QTest::addColumn<qreal>( "box1maxAltitude" );
0272     QTest::addColumn<GeoDataLatLonBox>( "latLonBox2" );
0273     QTest::addColumn<qreal>( "box2minAltitude" );
0274     QTest::addColumn<qreal>( "box2maxAltitude" );
0275     QTest::addColumn<bool>( "intersects" );
0276 
0277     QTest::newRow( "empty1" ) << GeoDataLatLonBox( 0.5, 0.4, 0.3, 0.2 ) << qreal(0.0) << qreal(0.0)
0278                               << GeoDataLatLonBox() << qreal(0.0) << qreal(0.0)
0279                               << false;
0280     QTest::newRow( "empty2" ) << GeoDataLatLonBox() << qreal(0.0) << qreal(0.0)
0281                               << GeoDataLatLonBox( 0.5, 0.4, 0.3, 0.2 ) << qreal(0.0) << qreal(0.0)
0282                               << false;
0283     QTest::newRow( "same" ) << GeoDataLatLonBox( 56.0, 40.0, 11.0, 0.0, GeoDataCoordinates::Degree ) << qreal(10.0) << qreal(12.0)
0284                             << GeoDataLatLonBox( 56.0, 40.0, 11.0, 0.0, GeoDataCoordinates::Degree ) << qreal(10.0) << qreal(12.0)
0285                             << true;
0286     QTest::newRow( "dateLineFalse" ) << GeoDataLatLonBox( 30.0, -30.0,  170.0, -170.0, GeoDataCoordinates::Degree ) << qreal(0.0) << qreal(0.0)
0287                                      << GeoDataLatLonBox( 30.0, -30.0, -171.0,  171.0, GeoDataCoordinates::Degree ) << qreal(0.0) << qreal(0.0)
0288                                      << false;
0289     QTest::newRow( "dateLineTrue" ) << GeoDataLatLonBox( 20.0,   0.0,  171.0, -171.0, GeoDataCoordinates::Degree ) << qreal(0.0) << qreal(0.0)
0290                                     << GeoDataLatLonBox( 30.0, -30.0, -170.0,  170.0, GeoDataCoordinates::Degree ) << qreal(0.0) << qreal(0.0)
0291                                     << true;
0292 }
0293 
0294 void TestGeoDataLatLonAltBox::testIntersects()
0295 {
0296     QFETCH( GeoDataLatLonBox, latLonBox1 );
0297     QFETCH( qreal, box1minAltitude );
0298     QFETCH( qreal, box1maxAltitude );
0299     QFETCH( GeoDataLatLonBox, latLonBox2 );
0300     QFETCH( qreal, box2minAltitude );
0301     QFETCH( qreal, box2maxAltitude );
0302     QFETCH( bool, intersects );
0303 
0304     const GeoDataLatLonAltBox box1( latLonBox1, box1minAltitude, box1maxAltitude );
0305     const GeoDataLatLonAltBox box2( latLonBox2, box2minAltitude, box2maxAltitude );
0306 
0307     QCOMPARE( box1.intersects( box2 ), intersects );
0308 }
0309 
0310 void TestGeoDataLatLonAltBox::testCrossesDateline_data()
0311 {
0312     QTest::addColumn<GeoDataLatLonBox>("box");
0313     QTest::addColumn<bool>("expected");
0314 
0315     QTest::newRow("all") << GeoDataLatLonBox(90, -90, 179.999, -180, GeoDataCoordinates::Degree) << false;
0316 
0317     QTest::newRow("left")  << GeoDataLatLonBox(90, -90,   0, -180, GeoDataCoordinates::Degree) << false;
0318     QTest::newRow("front") << GeoDataLatLonBox(90, -90,  90,  -90, GeoDataCoordinates::Degree) << false;
0319     QTest::newRow("right") << GeoDataLatLonBox(90, -90, 180,    0, GeoDataCoordinates::Degree) << false;
0320     QTest::newRow("back")  << GeoDataLatLonBox(90, -90, -90,   90, GeoDataCoordinates::Degree) << true;
0321 }
0322 
0323 void TestGeoDataLatLonAltBox::testCrossesDateline()
0324 {
0325     QFETCH(GeoDataLatLonBox, box);
0326     QFETCH(bool, expected);
0327 
0328     bool const result = box.crossesDateLine();
0329 
0330     QCOMPARE(result, expected);
0331 }
0332 
0333 void TestGeoDataLatLonAltBox::testCenter_data()
0334 {
0335     QTest::addColumn<GeoDataLatLonBox>( "box" );
0336     QTest::addColumn<GeoDataCoordinates>( "center" );
0337 
0338     QTest::newRow( "N-E" ) << GeoDataLatLonBox( 60.0, 40.0, 30.0, 10.0, GeoDataCoordinates::Degree )
0339                            << GeoDataCoordinates( 20.0, 50.0, 0, GeoDataCoordinates::Degree );
0340 
0341     QTest::newRow( "N-GW" ) << GeoDataLatLonBox( 60.0, 40.0, 10.0, -30.0, GeoDataCoordinates::Degree )
0342                             << GeoDataCoordinates( -10.0, 50.0, 0, GeoDataCoordinates::Degree );
0343 
0344     QTest::newRow( "N-W" ) << GeoDataLatLonBox( 60.0, 40.0, -10.0, -30.0, GeoDataCoordinates::Degree )
0345                            << GeoDataCoordinates( -20.0, 50.0, 0, GeoDataCoordinates::Degree );
0346 
0347     QTest::newRow( "NS-W" ) << GeoDataLatLonBox( 30.0, -30.0, -10.0, -30.0, GeoDataCoordinates::Degree )
0348                             << GeoDataCoordinates( -20.0, 0.0, 0, GeoDataCoordinates::Degree );
0349 
0350     QTest::newRow( "N-IDL" ) << GeoDataLatLonBox( 30.0, -30.0, -150.0, 170.0, GeoDataCoordinates::Degree )
0351                              << GeoDataCoordinates( -170.0, 0.0, 0, GeoDataCoordinates::Degree );
0352 }
0353 
0354 void TestGeoDataLatLonAltBox::testCenter()
0355 {
0356     QFETCH( GeoDataLatLonBox, box );
0357     QFETCH( GeoDataCoordinates, center );
0358 
0359     QCOMPARE( box.center().latitude(), center.latitude() );
0360     QCOMPARE( box.center().longitude(), center.longitude() );
0361 }
0362 
0363 void TestGeoDataLatLonAltBox::testUnited_data()
0364 {
0365     QTest::addColumn<GeoDataLatLonBox>( "box1" );
0366     QTest::addColumn<GeoDataLatLonBox>( "box2" );
0367     QTest::addColumn<GeoDataLatLonBox>( "expected" );
0368 
0369     QTest::newRow( "emptyRight" ) << GeoDataLatLonBox( 0.5, 0.4, 0.3, 0.2 )
0370                                   << GeoDataLatLonBox()
0371                                   << GeoDataLatLonBox( 0.5, 0.4, 0.3, 0.2 );
0372 
0373     QTest::newRow( "emptyLeft" ) << GeoDataLatLonBox()
0374                                  << GeoDataLatLonBox( 0.5, 0.4, 0.3, 0.2 )
0375                                  << GeoDataLatLonBox( 0.5, 0.4, 0.3, 0.2 );
0376 
0377     QTest::newRow( "same" ) << GeoDataLatLonBox( 56.0, 40.0, 11.0, 0.0, GeoDataCoordinates::Degree )
0378                             << GeoDataLatLonBox( 56.0, 40.0, 11.0, 0.0, GeoDataCoordinates::Degree )
0379                             << GeoDataLatLonBox( 56.0, 40.0, 11.0, 0.0, GeoDataCoordinates::Degree );
0380 
0381     // 2 boxes in West, result stays west
0382     QTest::newRow( "bigWest" ) << GeoDataLatLonBox( 30.0, -30.0,  -10.0,  -30.0, GeoDataCoordinates::Degree )
0383                                << GeoDataLatLonBox( 30.0, -30.0, -150.0, -170.0, GeoDataCoordinates::Degree )
0384                                << GeoDataLatLonBox( 30.0, -30.0,  -10.0, -170.0, GeoDataCoordinates::Degree );
0385 
0386     // 2 boxes each side of greenwich, result crosses greenwich
0387     QTest::newRow( "aroundGreenwich" ) << GeoDataLatLonBox( 30.0, -30.0, -10.0, -30.0, GeoDataCoordinates::Degree )
0388                                        << GeoDataLatLonBox( 30.0, -30.0,  30.0,  10.0, GeoDataCoordinates::Degree )
0389                                        << GeoDataLatLonBox( 30.0, -30.0,  30.0, -30.0, GeoDataCoordinates::Degree );
0390 
0391     // 2 boxes crossing greenwich, result crosses greenwich
0392     QTest::newRow( "aroundGreenwich" ) << GeoDataLatLonBox( 30.0, -30.0, 10.0, -30.0, GeoDataCoordinates::Degree )
0393                                        << GeoDataLatLonBox( 30.0, -30.0, 30.0, -10.0, GeoDataCoordinates::Degree )
0394                                        << GeoDataLatLonBox( 30.0, -30.0, 30.0, -30.0, GeoDataCoordinates::Degree );
0395 
0396     // 2 boxes each side of IDL, result crosses IDL as smaller box
0397     QTest::newRow( "aroundIDL" ) << GeoDataLatLonBox( 30.0, -30.0, -150.0, -170.0, GeoDataCoordinates::Degree )
0398                                  << GeoDataLatLonBox( 30.0, -30.0,  170.0,  150.0, GeoDataCoordinates::Degree )
0399                                  << GeoDataLatLonBox( 30.0, -30.0, -150.0,  150.0, GeoDataCoordinates::Degree );
0400 
0401     // reciprocical, so independent of side
0402     QTest::newRow( "aroundIDL2" ) << GeoDataLatLonBox( 30.0, -30.0,  170.0,  150.0, GeoDataCoordinates::Degree )
0403                                   << GeoDataLatLonBox( 30.0, -30.0, -150.0, -170.0, GeoDataCoordinates::Degree )
0404                                   << GeoDataLatLonBox( 30.0, -30.0, -150.0,  150.0, GeoDataCoordinates::Degree );
0405 
0406     // 1 box crossing IDL, the 2 centers are close together, result crosses IDL
0407     QTest::newRow( "crossingIDLclose" ) << GeoDataLatLonBox( 30.0, -30.0, -130.0, -150.0, GeoDataCoordinates::Degree )
0408                                         << GeoDataLatLonBox( 30.0, -30.0, -150.0,  170.0, GeoDataCoordinates::Degree )
0409                                         << GeoDataLatLonBox( 30.0, -30.0, -130.0,  170.0, GeoDataCoordinates::Degree );
0410 
0411     // reciprocical
0412     QTest::newRow( "crossingIDLclose2" ) << GeoDataLatLonBox( 30.0, -30.0, -160.0,  170.0, GeoDataCoordinates::Degree )
0413                                          << GeoDataLatLonBox( 30.0, -30.0, -140.0, -150.0, GeoDataCoordinates::Degree )
0414                                          << GeoDataLatLonBox( 30.0, -30.0, -140.0,  170.0, GeoDataCoordinates::Degree );
0415 
0416     // 1 box crossing IDL, the 2 centers are across IDL, result crosses IDL
0417     QTest::newRow( "crossingIDLfar" ) << GeoDataLatLonBox( 30.0, -30.0, -150.0, -170.0, GeoDataCoordinates::Degree )
0418                                       << GeoDataLatLonBox( 30.0, -30.0, -170.0,  150.0, GeoDataCoordinates::Degree )
0419                                       << GeoDataLatLonBox( 30.0, -30.0, -150.0,  150.0, GeoDataCoordinates::Degree );
0420 
0421     // reciprocical
0422     QTest::newRow( "crossingIDLfar2" ) << GeoDataLatLonBox( 30.0, -30.0, -170.0,  150.0, GeoDataCoordinates::Degree )
0423                                        << GeoDataLatLonBox( 30.0, -30.0, -150.0, -170.0, GeoDataCoordinates::Degree )
0424                                        << GeoDataLatLonBox( 30.0, -30.0, -150.0,  150.0, GeoDataCoordinates::Degree );
0425 
0426     // 2 box crossing IDL, the 2 centers are close together, result crosses IDL
0427     QTest::newRow( "crossingsIDLclose" ) << GeoDataLatLonBox( 30.0, -30.0, -140.0, 160.0, GeoDataCoordinates::Degree )
0428                                          << GeoDataLatLonBox( 30.0, -30.0, -160.0, 170.0, GeoDataCoordinates::Degree )
0429                                          << GeoDataLatLonBox( 30.0, -30.0, -140.0, 160.0, GeoDataCoordinates::Degree );
0430 
0431     // 2 box crossing IDL, the 2 centers are across IDL, result crosses IDL
0432     QTest::newRow( "crossingsIDLfar" ) << GeoDataLatLonBox( 30.0, -30.0, -150.0, -170.0, GeoDataCoordinates::Degree )
0433                                        << GeoDataLatLonBox( 30.0, -30.0, -170.0,  150.0, GeoDataCoordinates::Degree )
0434                                        << GeoDataLatLonBox( 30.0, -30.0, -150.0,  150.0, GeoDataCoordinates::Degree );
0435 
0436     QTest::newRow( "bug299959" ) << GeoDataLatLonBox( 90.0, -90.0, 180.0, -180.0, GeoDataCoordinates::Degree )
0437                                  << GeoDataLatLonBox( 18.0, -18.0,  30.0,   20.0, GeoDataCoordinates::Degree )
0438                                  << GeoDataLatLonBox( 90.0, -90.0, 180.0, -180.0, GeoDataCoordinates::Degree );
0439 }
0440 
0441 void TestGeoDataLatLonAltBox::testUnited()
0442 {
0443     QFETCH( GeoDataLatLonBox, box1 );
0444     QFETCH( GeoDataLatLonBox, box2 );
0445     QFETCH( GeoDataLatLonBox, expected );
0446 
0447     GeoDataLatLonBox const result = box1 | box2;
0448 
0449     QCOMPARE( result.north( GeoDataCoordinates::Degree ), expected.north( GeoDataCoordinates::Degree ) );
0450     QCOMPARE( result.south( GeoDataCoordinates::Degree ), expected.south( GeoDataCoordinates::Degree ) );
0451     QCOMPARE( result.west( GeoDataCoordinates::Degree ), expected.west( GeoDataCoordinates::Degree ) );
0452     QCOMPARE( result.east( GeoDataCoordinates::Degree ), expected.east( GeoDataCoordinates::Degree ) );
0453 }
0454 
0455 void TestGeoDataLatLonAltBox::testFromLineString_data() 
0456 {
0457     QTest::addColumn<GeoDataLineString>("string");
0458     QTest::addColumn<GeoDataLatLonBox>("expected");
0459 
0460     QTest::newRow("empty") << GeoDataLineString() << GeoDataLatLonBox(0, 0, 0, 0);
0461 
0462     QTest::newRow("bug 299527")
0463             << (GeoDataLineString()
0464                  << GeoDataCoordinates(   0, 0, 200, GeoDataCoordinates::Degree)
0465                  << GeoDataCoordinates( 180, 0, 200, GeoDataCoordinates::Degree)
0466                  << GeoDataCoordinates(-180, 0, 200, GeoDataCoordinates::Degree)
0467                  << GeoDataCoordinates(   0, 0, 200, GeoDataCoordinates::Degree))
0468             << GeoDataLatLonBox(90.0, 0.0, 180, -180, GeoDataCoordinates::Degree);
0469 
0470     QTest::newRow("around south pole")
0471             << (GeoDataLineString()
0472                  << GeoDataCoordinates(   0, -10, 200, GeoDataCoordinates::Degree)
0473                  << GeoDataCoordinates( 180, -10, 200, GeoDataCoordinates::Degree)
0474                  << GeoDataCoordinates(-180, -10, 200, GeoDataCoordinates::Degree)
0475                  << GeoDataCoordinates(   0, -10, 200, GeoDataCoordinates::Degree))
0476             << GeoDataLatLonBox(-10.0, -90.0, 180, -180, GeoDataCoordinates::Degree);
0477 }
0478 
0479 void TestGeoDataLatLonAltBox::testFromLineString() {
0480     QFETCH(GeoDataLineString, string);
0481     QFETCH(GeoDataLatLonBox, expected);
0482 
0483     GeoDataLatLonAltBox const result = GeoDataLatLonAltBox::fromLineString(string);
0484 
0485     QCOMPARE(result.north(), expected.north());
0486     QCOMPARE(result.south(), expected.south());
0487     QCOMPARE(result.east(), expected.east());
0488     QCOMPARE(result.west(), expected.west());
0489 }
0490 
0491 void TestGeoDataLatLonAltBox::testToString_data() {
0492     
0493 }
0494 
0495 void TestGeoDataLatLonAltBox::testToString() {
0496     
0497 }
0498 
0499 void TestGeoDataLatLonAltBox::testPack_data() {
0500     QTest::addColumn<GeoDataCoordinates>("coordinates");
0501 
0502     QTest::newRow("rad1") << GeoDataCoordinates( 1.0, 2.2, 1.8, GeoDataCoordinates::Radian );
0503     QTest::newRow("rad2") << GeoDataCoordinates( 0.2, 3.1, 2.9, GeoDataCoordinates::Radian );
0504 }
0505 
0506 void TestGeoDataLatLonAltBox::testPack() {
0507     QFETCH(GeoDataCoordinates, coordinates);
0508 
0509     GeoDataLatLonAltBox const original = GeoDataLatLonAltBox(coordinates);
0510 
0511     QBuffer buffer;
0512     bool const isOpenForWriting = buffer.open(QBuffer::WriteOnly);
0513 
0514     QVERIFY(isOpenForWriting);
0515 
0516     QDataStream out(&buffer);
0517     original.pack(out);
0518     buffer.close();
0519 
0520     bool const isOpenForReading = buffer.open(QBuffer::ReadOnly);
0521 
0522     QVERIFY(isOpenForReading);
0523 
0524     QDataStream in(&buffer);
0525 
0526     GeoDataLatLonAltBox unpacked;
0527     unpacked.unpack(in);
0528 
0529     buffer.close();
0530 
0531 #if 0
0532     QCOMPARE(unpacked.north(), original.north());
0533     QCOMPARE(unpacked.south(), original.south());
0534     QCOMPARE(unpacked.east(), original.east());
0535     QCOMPARE(unpacked.west(), original.west());
0536 #endif
0537 
0538     QCOMPARE(unpacked.maxAltitude(), original.maxAltitude());
0539     QCOMPARE(unpacked.minAltitude(), original.minAltitude());
0540     QCOMPARE(unpacked.altitudeMode(), original.altitudeMode());
0541 }
0542 
0543 void TestGeoDataLatLonAltBox::testContainerBox_data() {
0544     QTest::addColumn<qreal>("lon1");
0545     QTest::addColumn<qreal>("lat1");
0546     QTest::addColumn<qreal>("lon2");
0547     QTest::addColumn<qreal>("lat2");
0548     QTest::addColumn<qreal>("lon3");
0549     QTest::addColumn<qreal>("lat3");
0550 
0551     QTest::newRow("rad1") << qreal(2.4) << qreal(0.1) << qreal(1.0) << qreal(1.2) << qreal(-1.8) << qreal(-0.7) ;
0552     QTest::newRow("rad2") << qreal(-1.3) << qreal(-0.1) << qreal(0.2) << qreal(1.1) << qreal(2.9) << qreal(0.9) ;
0553 }
0554 
0555 void TestGeoDataLatLonAltBox::testContainerBox() {
0556     QFETCH(qreal, lon1);
0557     QFETCH(qreal, lat1);
0558     QFETCH(qreal, lon2);
0559     QFETCH(qreal, lat2);
0560     QFETCH(qreal, lon3);
0561     QFETCH(qreal, lat3);
0562 
0563     GeoDataPlacemark p1, p2, p3;
0564     p1.setCoordinate(lon1, lat1, GeoDataCoordinates::Degree);
0565     p2.setCoordinate(lon2, lat2, GeoDataCoordinates::Degree);
0566     p3.setCoordinate(lon3, lat3, GeoDataCoordinates::Degree);
0567     GeoDataFolder f1, f2;
0568     f1.append(new GeoDataPlacemark(p1));
0569     f2.append(new GeoDataPlacemark(p2));
0570     f2.append(new GeoDataPlacemark(p3));
0571     f1.append(new GeoDataFolder(f2));
0572     GeoDataLatLonAltBox box = f1.latLonAltBox();
0573 
0574     QCOMPARE(box.north(), qMax(qMax(lat1, lat2), lat3));
0575     QCOMPARE(box.east(), qMax(qMax(lon1, lon2), lon3));
0576     QCOMPARE(box.south(), qMin(qMin(lat1, lat2), lat3));
0577     QCOMPARE(box.west(), qMin(qMin(lon1, lon2), lon3));
0578 }
0579 
0580 void TestGeoDataLatLonAltBox::testScale_data()
0581 {
0582     QTest::addColumn<GeoDataLatLonBox>( "box" );
0583     QTest::addColumn<qreal>( "verticalScale" );
0584     QTest::addColumn<qreal>( "horizontalScale" );
0585     QTest::addColumn<GeoDataLatLonBox>( "expected" );
0586 
0587     QTest::newRow( "void" ) << GeoDataLatLonBox( 0.5, 0.4, 0.3, 0.2 )
0588                             << qreal(1.0)
0589                             << qreal(1.0)
0590                             << GeoDataLatLonBox( 0.5, 0.4, 0.3, 0.2 );
0591     QTest::newRow( "simple vertical" ) << GeoDataLatLonBox( 0.5, 0.4, 0.3, 0.2 )
0592                                        << qreal(1.5)
0593                                        << qreal(1.0)
0594                                        << GeoDataLatLonBox( 0.525, 0.375, 0.3, 0.2 );
0595     QTest::newRow( "simple horizontal" ) << GeoDataLatLonBox( 0.7, 0.6, 0.3, 0.2 )
0596                                          << qreal(1.0)
0597                                          << qreal(2.0)
0598                                          << GeoDataLatLonBox( 0.7, 0.6, 0.35, 0.15 );
0599     QTest::newRow( "crosses dateline" )  << GeoDataLatLonBox( 20.0,   0.0, -170.0, 170.0, GeoDataCoordinates::Degree )
0600                                          << qreal(2.0)
0601                                          << qreal(2.0)
0602                                          << GeoDataLatLonBox( 30.0, -10.0, -160.0, 160.0, GeoDataCoordinates::Degree );
0603 }
0604 
0605 void TestGeoDataLatLonAltBox::testScale()
0606 {
0607     QFETCH(GeoDataLatLonBox, box);
0608     QFETCH(qreal, verticalScale);
0609     QFETCH(qreal, horizontalScale);
0610     QFETCH(GeoDataLatLonBox, expected);
0611     GeoDataLatLonBox const scaled = box.scaled(verticalScale, horizontalScale);
0612     QCOMPARE(scaled.west(), expected.west());
0613     QCOMPARE(scaled.north(), expected.north());
0614     QCOMPARE(scaled.south(), expected.south());
0615     QCOMPARE(scaled.east(), expected.east());
0616     QCOMPARE(scaled.rotation(), expected.rotation());
0617     QCOMPARE(scaled.center(), expected.center());
0618 }
0619 
0620 QTEST_MAIN(TestGeoDataLatLonAltBox)
0621 #include "TestGeoDataLatLonAltBox.moc"
0622