mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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 <neolit123@gmail.com>
This commit is contained in:
parent
f5f2754b81
commit
56e755b711
5 changed files with 18 additions and 18 deletions
|
@ -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)) {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -187,8 +187,8 @@ void LocationInformationWidget::acceptChanges()
|
|||
if (!ui.diveSiteCoordinates->text().isEmpty()) {
|
||||
double lat, lon;
|
||||
parseGpsText(ui.diveSiteCoordinates->text(), &lat, &lon);
|
||||
currentDs->latitude.udeg = (int)(lat * 1000000.0);
|
||||
currentDs->longitude.udeg = (int)(lon * 1000000.0);
|
||||
currentDs->latitude.udeg = lrint(lat * 1000000.0);
|
||||
currentDs->longitude.udeg = lrint(lon * 1000000.0);
|
||||
}
|
||||
if (dive_site_is_empty(currentDs)) {
|
||||
LocationInformationModel::instance()->removeRow(get_divesite_idx(currentDs));
|
||||
|
@ -265,8 +265,8 @@ void LocationInformationWidget::on_diveSiteCoordinates_textChanged(const QString
|
|||
if (!same_string(qPrintable(text), coords)) {
|
||||
double latitude, longitude;
|
||||
if (parseGpsText(text, &latitude, &longitude)) {
|
||||
displayed_dive_site.latitude.udeg = (int)(latitude * 1000000);
|
||||
displayed_dive_site.longitude.udeg = (int)(longitude * 1000000);
|
||||
displayed_dive_site.latitude.udeg = lrint(latitude * 1000000);
|
||||
displayed_dive_site.longitude.udeg = lrint(longitude * 1000000);
|
||||
markChangedWidget(ui.diveSiteCoordinates);
|
||||
emit coordinatesChanged();
|
||||
ui.geoCodeButton->setEnabled(latitude != 0 && longitude != 0);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue