diff options
author | Paolo Angelelli <paolo.angelelli@theqtcompany.com> | 2016-04-08 10:41:23 +0200 |
---|---|---|
committer | Paolo Angelelli <paolo.angelelli@theqtcompany.com> | 2016-04-11 13:36:46 +0000 |
commit | 4528d53b7429e48c51988002bf35e3615a152cb5 (patch) | |
tree | a0365c4b2be0c0fc71e54374e6183ccd55c9df16 | |
parent | 46bef1bf9b00727832cad35440c554f26e7457b9 (diff) | |
download | qtlocation-4528d53b7429e48c51988002bf35e3615a152cb5.tar.gz |
Fix for negative QGeoCoordinate.azimuthTo results in range ]360, 359[
QGeoCoordinate.azimuthTo() currently returns negative value
(between 0 and -1) for azimuths that should instead be in the range
between 360 and 359.
This patch should bring all returned values in the range [0, 360[
(360 excluded).
Change-Id: I0b5ee7c3fc2bbeb80ca8167a53c7c16d9e067e29
Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
-rw-r--r-- | src/positioning/qgeocoordinate.cpp | 3 | ||||
-rw-r--r-- | tests/auto/qgeocoordinate/tst_qgeocoordinate.cpp | 7 |
2 files changed, 8 insertions, 2 deletions
diff --git a/src/positioning/qgeocoordinate.cpp b/src/positioning/qgeocoordinate.cpp index f28e1865..0386e859 100644 --- a/src/positioning/qgeocoordinate.cpp +++ b/src/positioning/qgeocoordinate.cpp @@ -469,8 +469,9 @@ qreal QGeoCoordinate::azimuthTo(const QGeoCoordinate &other) const double y = sin(dlon) * cos(lat2Rad); double x = cos(lat1Rad) * sin(lat2Rad) - sin(lat1Rad) * cos(lat2Rad) * cos(dlon); + double azimuth = qgeocoordinate_radToDeg(atan2(y, x)) + 360.0; double whole; - double fraction = modf(qgeocoordinate_radToDeg(atan2(y, x)), &whole); + double fraction = modf(azimuth, &whole); return qreal((int(whole + 360) % 360) + fraction); } diff --git a/tests/auto/qgeocoordinate/tst_qgeocoordinate.cpp b/tests/auto/qgeocoordinate/tst_qgeocoordinate.cpp index 413fa071..fa9fd5c5 100644 --- a/tests/auto/qgeocoordinate/tst_qgeocoordinate.cpp +++ b/tests/auto/qgeocoordinate/tst_qgeocoordinate.cpp @@ -469,7 +469,10 @@ private slots: QFETCH(QGeoCoordinate, c2); QFETCH(qreal, azimuth); - QCOMPARE(QString::number(c1.azimuthTo(c2)), QString::number(azimuth)); + qreal result = c1.azimuthTo(c2); + QVERIFY(result >= 0.0); + QVERIFY(result < 360.0); + QCOMPARE(QString::number(result), QString::number(azimuth)); } void azimuthTo_data() @@ -488,6 +491,8 @@ private slots: << LONDON << NEW_YORK << qreal(288.3388804508); QTest::newRow("north pole -> south pole") << NORTH_POLE << SOUTH_POLE << qreal(180.0); + QTest::newRow("Almost 360degrees bearing") + << QGeoCoordinate(0.5,45.0,0.0) << QGeoCoordinate(0.5,-134.9999651,0.0) << qreal(359.998); } void atDistanceAndAzimuth() |