diff options
author | Tarja Sundqvist <tarja.sundqvist@qt.io> | 2022-08-16 20:37:28 +0300 |
---|---|---|
committer | Tarja Sundqvist <tarja.sundqvist@qt.io> | 2022-08-16 20:37:28 +0300 |
commit | 261b146c5c9dd51c2a88837342b2fe605b3a3c78 (patch) | |
tree | 88fea542f06983eff3052138a91e0ad0cda1de4e /src/positioning/qgeocoordinate.cpp | |
parent | ddf3f88156369671576a9bcc703feb22e7b7ff0d (diff) | |
parent | ade8147da038ebaae230a38a6e0f16364fc0edbe (diff) | |
download | qtlocation-261b146c5c9dd51c2a88837342b2fe605b3a3c78.tar.gz |
Merge remote-tracking branch 'origin/tqtc/lts-5.15.6' into tqtc/lts-5.15-opensourcev5.15.6-lts-lgpl
Change-Id: I7592fcec7b13c5bbe021716a424dd03004b101c6
Diffstat (limited to 'src/positioning/qgeocoordinate.cpp')
-rw-r--r-- | src/positioning/qgeocoordinate.cpp | 47 |
1 files changed, 23 insertions, 24 deletions
diff --git a/src/positioning/qgeocoordinate.cpp b/src/positioning/qgeocoordinate.cpp index 5ff1299d..dddb61b3 100644 --- a/src/positioning/qgeocoordinate.cpp +++ b/src/positioning/qgeocoordinate.cpp @@ -594,19 +594,18 @@ QString QGeoCoordinate::toString(CoordinateFormat format) const double latMin = (absLat - int(absLat)) * 60; double lngMin = (absLng - int(absLng)) * 60; - if (qRound(latMin) >= 60) { + // We use QString::number(val, 'f', 3) to represent minutes. + // It rounds up to the next integer in case the fraction > 0.9995. + // Such behavior should be handled specifically when the rounded + // value is 60, so that we overflow to degrees correctly. + // If we overflow, the minutes should unconditionally be 0.0. + if (latMin > 59.9995) { absLat++; - latMin = qAbs(latMin - 60.0f); - //avoid invalid latitude due to latMin rounding below - if (qRound(absLat) >= 90) - latMin = 0.0f; + latMin = 0.0f; } - if (qRound(lngMin) >= 60) { + if (lngMin > 59.9995) { absLng++; - lngMin = qAbs(lngMin - 60.0f); - // avoid invalid longitude due to lngMin rounding below - if (qRound(absLng) >= 180) - lngMin = 0.0f; + lngMin = 0.0f; } latStr = QString::fromLatin1("%1%2 %3'") @@ -626,28 +625,28 @@ QString QGeoCoordinate::toString(CoordinateFormat format) const double latSec = (latMin - int(latMin)) * 60; double lngSec = (lngMin - int(lngMin)) * 60; - // overflow to full minutes - if (qRound(latSec) >= 60) { + // We use QString::number(val, 'f', 1) to represent seconds. + // It rounds up to the next integer in case the fraction >= 0.95. + // Such behavior should be handled specifically when the rounded + // value is 60, so that we overflow to minutes correctly. + // If we overflow, the seconds should unconditionally be 0.0. + if (latSec >= 59.95) { latMin++; - latSec = qAbs(latSec - 60.0f); - // overflow to full degrees + latSec = 0.0f; + // We cast to int to represent minutes, so we can use qRound() + // to determine if we need to overflow to full degrees. + // If we overflow, the minutes will unconditionally be 0.0. if (qRound(latMin) >= 60) { absLat++; - latMin = qAbs(latMin - 60.0f); - // avoid invalid latitude due to latSec rounding below - if (qRound(absLat) >= 90) - latSec = 0.0f; + latMin = 0.0f; } } - if (qRound(lngSec) >= 60) { + if (lngSec >= 59.95) { lngMin++; - lngSec = qAbs(lngSec - 60.0f); + lngSec = 0.0f; if (qRound(lngMin) >= 60) { absLng++; - lngMin = qAbs(lngMin - 60.0f); - // avoid invalid longitude due to lngSec rounding below - if (qRound(absLng) >= 180) - lngSec = 0.0f; + lngMin = 0.0f; } } |