applying gps fixes: group repetitive code under a macro

Title is self explanatory.

[Dirk Hohndel: small edits to remove typo / improve readability]

Signed-off-by: Salvador Cuñat <salvador.cunat@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Salvador Cuñat 2017-12-02 11:28:00 +01:00 committed by Dirk Hohndel
parent 6f42ab46da
commit 2182167b53

View file

@ -55,6 +55,13 @@ static void copy_gps_location(struct dive *from, struct dive *to)
} }
#define SAME_GROUP 6 * 3600 // six hours #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. //TODO: C Code. static functions are not good if we plan to have a test for them.
static bool merge_locations_into_dives(void) 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 (time_during_dive_with_offset(dive, gpsfix->when, 0)) {
if (verbose) if (verbose)
qDebug() << "gpsfix is during the dive, pick that one"; qDebug() << "gpsfix is during the dive, pick that one";
copy_gps_location(gpsfix, dive); SET_LOCATION(dive, gpsfix, j);
changed++;
tracer = j;
break; break;
} else { } else {
/* /*
@ -101,25 +106,19 @@ static bool merge_locations_into_dives(void)
} else if (gpsfix->when > dive_endtime(dive)) { } else if (gpsfix->when > dive_endtime(dive)) {
if (verbose) if (verbose)
qDebug() << "which is even later after the end of the dive, so pick the previous one"; qDebug() << "which is even later after the end of the dive, so pick the previous one";
copy_gps_location(gpsfix, dive); SET_LOCATION(dive, gpsfix, j);
changed++;
tracer = j;
break; break;
} else { } else {
/* ok, gpsfix is before, nextgpsfix is after */ /* ok, gpsfix is before, nextgpsfix is after */
if (dive->when - gpsfix->when <= nextgpsfix->when - dive_endtime(dive)) { if (dive->when - gpsfix->when <= nextgpsfix->when - dive_endtime(dive)) {
if (verbose) if (verbose)
qDebug() << "pick the one before as it's closer to the start"; qDebug() << "pick the one before as it's closer to the start";
copy_gps_location(gpsfix, dive); SET_LOCATION(dive, gpsfix, j);
changed++;
tracer = j;
break; break;
} else { } else {
if (verbose) if (verbose)
qDebug() << "pick the one after as it's closer to the start"; qDebug() << "pick the one after as it's closer to the start";
copy_gps_location(nextgpsfix, dive); SET_LOCATION(dive, nextgpsfix, j + 1);
changed++;
tracer = j + 1;
break; break;
} }
} }
@ -129,9 +128,7 @@ static bool merge_locations_into_dives(void)
} else { } else {
if (verbose) if (verbose)
qDebug() << "which seems to be the best one for this dive, so pick it"; qDebug() << "which seems to be the best one for this dive, so pick it";
copy_gps_location(gpsfix, dive); SET_LOCATION(dive, gpsfix, j);
changed++;
tracer = j;
break; break;
} }
} }