summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorPaolo Angelelli <paolo.angelelli@qt.io>2016-08-05 22:21:12 +0200
committerPaolo Angelelli <paolo.angelelli@qt.io>2016-11-30 08:54:11 +0000
commitcd8880cc04b22610e835e6cc02cc16ac22ec9fae (patch)
tree37a5569c4eca55f70d5584f54fa2479dcf9dad3c /tests
parent0a552f285fdc3760d9755109ceef3b87392a308d (diff)
downloadqtlocation-cd8880cc04b22610e835e6cc02cc16ac22ec9fae.tar.gz
Add support for boundingGeoRectangle to QGeoShape
this patch introduces QGeoShape::boundingGeoRectangle, which returns a QGeoRectangle containing the latitudinal/longitudinal bounds of a geoshape. The bounding geo rectangle is projection independent, as it returns a georectangle containing the min/max latitudes/longitudes of the shape. Change-Id: Ie3a83ec41f87ea3753899d2278e664fe2469f778 Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qgeocircle/tst_qgeocircle.cpp38
-rw-r--r--tests/auto/qgeorectangle/tst_qgeorectangle.cpp25
2 files changed, 62 insertions, 1 deletions
diff --git a/tests/auto/qgeocircle/tst_qgeocircle.cpp b/tests/auto/qgeocircle/tst_qgeocircle.cpp
index 01fbed6b..6422a8aa 100644
--- a/tests/auto/qgeocircle/tst_qgeocircle.cpp
+++ b/tests/auto/qgeocircle/tst_qgeocircle.cpp
@@ -60,6 +60,9 @@ private slots:
void contains_data();
void contains();
+ void boundingGeoRectangle_data();
+ void boundingGeoRectangle();
+
void extendShape();
void extendShape_data();
@@ -281,7 +284,7 @@ void tst_QGeoCircle::contains_data()
QTest::addColumn<QGeoCoordinate>("probe");
QTest::addColumn<bool>("result");
- QTest::newRow("own centre") << QGeoCoordinate(1,1) << qreal(100.0) <<
+ QTest::newRow("own center") << QGeoCoordinate(1,1) << qreal(100.0) <<
QGeoCoordinate(1,1) << true;
QTest::newRow("over the hills") << QGeoCoordinate(1,1) << qreal(100.0) <<
QGeoCoordinate(30, 40) << false;
@@ -291,6 +294,7 @@ void tst_QGeoCircle::contains_data()
QGeoCoordinate(1.00077538, 0.99955527) << true;
QTest::newRow("at 1.01*radius") << QGeoCoordinate(1,1) << qreal(100.0) <<
QGeoCoordinate(1.00071413, 0.99943423) << false;
+ // TODO: add tests for edge circle cases: cross 1 pole, cross both poles
}
void tst_QGeoCircle::contains()
@@ -307,6 +311,38 @@ void tst_QGeoCircle::contains()
QCOMPARE(area.contains(probe), result);
}
+void tst_QGeoCircle::boundingGeoRectangle_data()
+{
+ QTest::addColumn<QGeoCoordinate>("center");
+ QTest::addColumn<qreal>("radius");
+ QTest::addColumn<QGeoCoordinate>("probe");
+ QTest::addColumn<bool>("result");
+
+ QTest::newRow("own center") << QGeoCoordinate(1,1) << qreal(100.0) <<
+ QGeoCoordinate(1,1) << true;
+ QTest::newRow("over the hills") << QGeoCoordinate(1,1) << qreal(100.0) <<
+ QGeoCoordinate(30, 40) << false;
+ QTest::newRow("at 0.5*radius") << QGeoCoordinate(1,1) << qreal(100.0) <<
+ QGeoCoordinate(1.00015374,1.00015274) << true;
+ QTest::newRow("at 0.99*radius") << QGeoCoordinate(1,1) << qreal(100.0) <<
+ QGeoCoordinate(1.00077538, 0.99955527) << true;
+ QTest::newRow("Outside the box") << QGeoCoordinate(1,1) << qreal(100.0) <<
+ QGeoCoordinate(1.00071413, 0.99903423) << false;
+ // TODO: add tests for edge circle cases: cross 1 pole, cross both poles
+}
+
+void tst_QGeoCircle::boundingGeoRectangle()
+{
+ QFETCH(QGeoCoordinate, center);
+ QFETCH(qreal, radius);
+ QFETCH(QGeoCoordinate, probe);
+ QFETCH(bool, result);
+
+ QGeoCircle c(center, radius);
+ QGeoRectangle box = c.boundingGeoRectangle();
+ QCOMPARE(box.contains(probe), result);
+}
+
void tst_QGeoCircle::extendShape()
{
QFETCH(QGeoCircle, circle);
diff --git a/tests/auto/qgeorectangle/tst_qgeorectangle.cpp b/tests/auto/qgeorectangle/tst_qgeorectangle.cpp
index 71a3765a..59dc38be 100644
--- a/tests/auto/qgeorectangle/tst_qgeorectangle.cpp
+++ b/tests/auto/qgeorectangle/tst_qgeorectangle.cpp
@@ -71,6 +71,9 @@ private slots:
void center();
void center_data();
+ void boundingGeoRectangle();
+ void boundingGeoRectangle_data();
+
void containsCoord();
void containsCoord_data();
@@ -957,6 +960,28 @@ void tst_QGeoRectangle::center_data()
QGeoCoordinate(-90.0, -170.0));
}
+void tst_QGeoRectangle::boundingGeoRectangle_data()
+{
+ QTest::addColumn<QGeoRectangle>("rectangle");
+
+ QGeoRectangle b1(QGeoCoordinate(70, 30), QGeoCoordinate(30, 70));
+ QGeoRectangle b2(QGeoCoordinate(70, 150), QGeoCoordinate(30, -170));
+ QGeoRectangle b3(QGeoCoordinate(90, 30), QGeoCoordinate(50, 70));
+ QGeoRectangle b4(QGeoCoordinate(-50, 30), QGeoCoordinate(-90, 70));
+
+ QTest::newRow("Box 1") << b1;
+ QTest::newRow("Box 2") << b2;
+ QTest::newRow("Box 3") << b3;
+ QTest::newRow("Box 4") << b4;
+}
+
+void tst_QGeoRectangle::boundingGeoRectangle()
+{
+ QFETCH(QGeoRectangle, rectangle);
+
+ QGeoRectangle box = rectangle.boundingGeoRectangle();
+ QCOMPARE(box, rectangle);
+}
void tst_QGeoRectangle::containsCoord()
{