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 --- mobile-widgets/qmlmanager.cpp | 8 ++++---- mobile-widgets/qmlmapwidgethelper.cpp | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'mobile-widgets') diff --git a/mobile-widgets/qmlmanager.cpp b/mobile-widgets/qmlmanager.cpp index 7305166e8..dc37fd4b0 100644 --- a/mobile-widgets/qmlmanager.cpp +++ b/mobile-widgets/qmlmanager.cpp @@ -654,12 +654,12 @@ void QMLManager::refreshDiveList() static void setupDivesite(struct dive *d, struct dive_site *ds, double lat, double lon, const char *locationtext) { if (ds) { - ds->latitude.udeg = (int) (lat * 1000000); - ds->longitude.udeg = (int) (lon * 1000000); + ds->latitude.udeg = lrint(lat * 1000000); + ds->longitude.udeg = lrint(lon * 1000000); } else { degrees_t latData, lonData; - latData.udeg = (int) lat; - lonData.udeg = (int) lon; + latData.udeg = lrint(lat); + lonData.udeg = lrint(lon); d->dive_site_uuid = create_dive_site_with_gps(locationtext, latData, lonData, d->when); } } diff --git a/mobile-widgets/qmlmapwidgethelper.cpp b/mobile-widgets/qmlmapwidgethelper.cpp index 7745bf71c..1ad5503dc 100644 --- a/mobile-widgets/qmlmapwidgethelper.cpp +++ b/mobile-widgets/qmlmapwidgethelper.cpp @@ -201,8 +201,8 @@ void MapWidgetHelper::copyToClipboardCoordinates(QGeoCoordinate coord, bool form bool savep = prefs.coordinates_traditional; prefs.coordinates_traditional = formatTraditional; - const int lat = llrint(1000000.0 * coord.latitude()); - const int lon = llrint(1000000.0 * coord.longitude()); + const int lat = lrint(1000000.0 * coord.latitude()); + const int lon = lrint(1000000.0 * coord.longitude()); const char *coordinates = printGPSCoords(lat, lon); QApplication::clipboard()->setText(QString(coordinates), QClipboard::Clipboard); @@ -215,8 +215,8 @@ void MapWidgetHelper::updateCurrentDiveSiteCoordinates(quint32 uuid, QGeoCoordin MapLocation *loc = m_mapLocationModel->getMapLocationForUuid(uuid); if (loc) loc->setCoordinate(coord); - displayed_dive_site.latitude.udeg = llrint(coord.latitude() * 1000000.0); - displayed_dive_site.longitude.udeg = llrint(coord.longitude() * 1000000.0); + displayed_dive_site.latitude.udeg = lrint(coord.latitude() * 1000000.0); + displayed_dive_site.longitude.udeg = lrint(coord.longitude() * 1000000.0); emit coordinatesChanged(); } -- cgit v1.2.3-70-g09d2