mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-19 14:25:27 +00:00
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:
parent
6f42ab46da
commit
2182167b53
1 changed files with 12 additions and 15 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue