diff options
-rw-r--r-- | desktop-widgets/subsurfacewebservices.cpp | 27 |
1 files changed, 12 insertions, 15 deletions
diff --git a/desktop-widgets/subsurfacewebservices.cpp b/desktop-widgets/subsurfacewebservices.cpp index 0537723b8..b11a910f1 100644 --- a/desktop-widgets/subsurfacewebservices.cpp +++ b/desktop-widgets/subsurfacewebservices.cpp @@ -55,6 +55,13 @@ static void copy_gps_location(struct dive *from, struct dive *to) } #define SAME_GROUP 6 * 3600 // six hours +#define SET_LOCATION(_dive, _gpsfix, _mark) \ +{ \ + copy_gps_location(_gpsfix, _dive); \ + changed ++; \ + tracer = _mark; \ +} + //TODO: C Code. static functions are not good if we plan to have a test for them. static bool merge_locations_into_dives(void) { @@ -79,9 +86,7 @@ static bool merge_locations_into_dives(void) if (time_during_dive_with_offset(dive, gpsfix->when, 0)) { if (verbose) qDebug() << "gpsfix is during the dive, pick that one"; - copy_gps_location(gpsfix, dive); - changed++; - tracer = j; + SET_LOCATION(dive, gpsfix, j); break; } else { /* @@ -101,25 +106,19 @@ static bool merge_locations_into_dives(void) } else if (gpsfix->when > dive_endtime(dive)) { if (verbose) qDebug() << "which is even later after the end of the dive, so pick the previous one"; - copy_gps_location(gpsfix, dive); - changed++; - tracer = j; + SET_LOCATION(dive, gpsfix, j); break; } else { /* ok, gpsfix is before, nextgpsfix is after */ if (dive->when - gpsfix->when <= nextgpsfix->when - dive_endtime(dive)) { if (verbose) qDebug() << "pick the one before as it's closer to the start"; - copy_gps_location(gpsfix, dive); - changed++; - tracer = j; + SET_LOCATION(dive, gpsfix, j); break; } else { if (verbose) qDebug() << "pick the one after as it's closer to the start"; - copy_gps_location(nextgpsfix, dive); - changed++; - tracer = j + 1; + SET_LOCATION(dive, nextgpsfix, j + 1); break; } } @@ -129,9 +128,7 @@ static bool merge_locations_into_dives(void) } else { if (verbose) qDebug() << "which seems to be the best one for this dive, so pick it"; - copy_gps_location(gpsfix, dive); - changed++; - tracer = j; + SET_LOCATION(dive, gpsfix, j); break; } } |