From 56e755b7119b494d2d875c617500d0299ae06a35 Mon Sep 17 00:00:00 2001 From: "Lubomir I. Ivanov" Date: Sat, 7 Oct 2017 21:39:20 +0300 Subject: Use lrint() for all degrees_t related rounding In certain places the '(int)' cast is used, while in other the llrint() or lrint() functions. Make the conversation from degrees in the 'double' form to the 'int' degrees_t consistent using lrint(). lrint() is the function which should give the best results, because it accepts a 'double' and results in a 'long' even if degrees_t is 'int'. If the truncation from 'long' to 'int' is discarding some of the precision then the next step would be to turn degrees_t into a 64bit signed integer type. Possible fix for #625. Signed-off-by: Lubomir I. Ivanov --- core/gpslocation.cpp | 8 ++++---- core/qthelper.cpp | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'core') diff --git a/core/gpslocation.cpp b/core/gpslocation.cpp index 22525ca3d..753b4a72f 100644 --- a/core/gpslocation.cpp +++ b/core/gpslocation.cpp @@ -171,8 +171,8 @@ void GpsLocation::newPosition(QGeoPositionInfo pos) gpsTracker gt; gt.when = pos.timestamp().toTime_t(); gt.when += gettimezoneoffset(gt.when); - gt.latitude.udeg = (int)(pos.coordinate().latitude() * 1000000); - gt.longitude.udeg = (int)(pos.coordinate().longitude() * 1000000); + gt.latitude.udeg = lrint(pos.coordinate().latitude() * 1000000); + gt.longitude.udeg = lrint(pos.coordinate().longitude() * 1000000); addFixToStorage(gt); } } @@ -626,8 +626,8 @@ void GpsLocation::downloadFromServer() struct gpsTracker gt; gt.when = timestamp.toMSecsSinceEpoch() / 1000; - gt.latitude.udeg = (int)(latitude.toDouble() * 1000000); - gt.longitude.udeg = (int)(longitude.toDouble() * 1000000); + gt.latitude.udeg = lrint(latitude.toDouble() * 1000000); + gt.longitude.udeg = lrint(longitude.toDouble() * 1000000); gt.name = name; // add this GPS fix to the QMap and the settings (remove existing fix at the same timestamp first) if (m_trackers.keys().contains(gt.when)) { diff --git a/core/qthelper.cpp b/core/qthelper.cpp index e6a4e056a..b7db56a20 100644 --- a/core/qthelper.cpp +++ b/core/qthelper.cpp @@ -1290,8 +1290,8 @@ extern "C" void picture_load_exif_data(struct picture *p) goto picture_load_exit; if (exif.parseFrom((const unsigned char *)mem.buffer, (unsigned)mem.size) != PARSE_EXIF_SUCCESS) goto picture_load_exit; - p->longitude.udeg= llrint(1000000.0 * exif.GeoLocation.Longitude); - p->latitude.udeg = llrint(1000000.0 * exif.GeoLocation.Latitude); + p->longitude.udeg = lrint(1000000.0 * exif.GeoLocation.Longitude); + p->latitude.udeg = lrint(1000000.0 * exif.GeoLocation.Latitude); picture_load_exit: free(mem.buffer); -- cgit v1.2.3-70-g09d2