diff options
author | Jan Mulder <jlmulder@xs4all.nl> | 2017-12-12 09:29:03 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2017-12-13 05:07:15 -0800 |
commit | 3479c9e19778a39f02a55a8681933227d9c6a37d (patch) | |
tree | b2ab2473c329c80a1066b1e65e05b026109959ee /core/gpslocation.cpp | |
parent | ee9531f76ec31ac2d1f35ba5b7b1513874f2be01 (diff) | |
download | subsurface-3479c9e19778a39f02a55a8681933227d9c6a37d.tar.gz |
applying gps fixes: group repetitive code under a macro
See 2182167b533b4c. Keep the dupicated code in sync.
Originally-by: Salvador Cuñat <salvador.cunat@gmail.com>
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
Diffstat (limited to 'core/gpslocation.cpp')
-rw-r--r-- | core/gpslocation.cpp | 27 |
1 files changed, 12 insertions, 15 deletions
diff --git a/core/gpslocation.cpp b/core/gpslocation.cpp index 15c7f0ab0..2d65ae211 100644 --- a/core/gpslocation.cpp +++ b/core/gpslocation.cpp @@ -252,6 +252,13 @@ static void copy_gps_location(struct gpsTracker &gps, struct dive *d) } #define SAME_GROUP 6 * 3600 /* six hours */ +#define SET_LOCATION(_dive, _gpsfix, _mark) \ +{ \ + copy_gps_location(_gpsfix, _dive); \ + changed = true; \ + last = _mark; \ +} + bool GpsLocation::applyLocations() { int i; @@ -283,9 +290,7 @@ bool GpsLocation::applyLocations() if (time_during_dive_with_offset(d, gpsTable[j].when, 0)) { if (verbose) qDebug() << "gpsFix is during the dive, pick that one"; - copy_gps_location(gpsTable[j], d); - changed = true; - last = j; + SET_LOCATION(d, gpsTable[j], j); break; } else { /* @@ -304,25 +309,19 @@ bool GpsLocation::applyLocations() } else if (gpsTable[j].when > dive_endtime(d)) { if (verbose) qDebug() << "which is even later after the end of the dive, so pick the previous one"; - copy_gps_location(gpsTable[j], d); - changed = true; - last = j; + SET_LOCATION(d, gpsTable[j], j); break; } else { /* ok, gpsFix is before, nextgpsFix is after */ if (d->when - gpsTable[j].when <= gpsTable[j+1].when - dive_endtime(d)) { if (verbose) qDebug() << "pick the one before as it's closer to the start"; - copy_gps_location(gpsTable[j], d); - changed = true; - last = j; + SET_LOCATION(d, gpsTable[j], j); break; } else { if (verbose) qDebug() << "pick the one after as it's closer to the start"; - copy_gps_location(gpsTable[j+1], d); - changed = true; - last = j + 1; + SET_LOCATION(d, gpsTable[j + 1], j + 1); break; } } @@ -332,9 +331,7 @@ bool GpsLocation::applyLocations() } else { if (verbose) qDebug() << "which seems to be the best one for this dive, so pick it"; - copy_gps_location(gpsTable[j], d); - changed = true; - last = j; + SET_LOCATION(d, gpsTable[j], j); break; } } |