summaryrefslogtreecommitdiffstats
path: root/dive.c
diff options
context:
space:
mode:
authorGravatar Linus Torvalds <torvalds@linux-foundation.org>2012-11-11 07:20:05 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2012-11-11 10:48:09 +0100
commitcda1b73bf68d1802c32416bce3be0ef84137002e (patch)
tree8e3e35aa04876e0971a0f80b7ee18e4e6bb746d7 /dive.c
parent7c09991876ef8b34bda6f5615a37f99e1b476b18 (diff)
downloadsubsurface-cda1b73bf68d1802c32416bce3be0ef84137002e.tar.gz
Prepare to merge non-overlapping dives
This just re-organizes the dive merging code so that we expose a new "merge_dives(a, b, offset)" function that merges two dives together into one with the samples (and events) of 'b' at the specified offset after 'a'. We'll want to use this if a dive computer has decided that the dive ended (due to a pause at the surface), but we really want to just turn the two computer dives into one long one with an extended surface swim. No functional changes, but some independent cleanups due to the trip simplifications. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'dive.c')
-rw-r--r--dive.c25
1 files changed, 12 insertions, 13 deletions
diff --git a/dive.c b/dive.c
index 384b8dcad..16939de62 100644
--- a/dive.c
+++ b/dive.c
@@ -811,7 +811,7 @@ static void merge_equipment(struct dive *res, struct dive *a, struct dive *b)
* The 'next' dive is not involved in the dive merging, but is the dive
* that will be the next dive after the merged dive.
*/
-static void pick_and_delete_trip(struct dive *res, struct dive *pick, struct dive *remove, struct dive *next)
+static void pick_and_delete_trip(struct dive *res, struct dive *pick, struct dive *remove)
{
tripflag_t tripflag = pick->tripflag;
dive_trip_t *trip = pick->divetrip;
@@ -825,7 +825,7 @@ static void pick_and_delete_trip(struct dive *res, struct dive *pick, struct div
/*
* Pick a trip for a dive
*/
-static void merge_trip(struct dive *res, struct dive *a, struct dive *b, struct dive *next)
+static void merge_trip(struct dive *res, struct dive *a, struct dive *b)
{
/*
* The larger tripflag is more relevant: we prefer
@@ -860,10 +860,10 @@ static void merge_trip(struct dive *res, struct dive *a, struct dive *b, struct
goto pick_b;
pick_a:
- pick_and_delete_trip(res, a, b, next);
+ pick_and_delete_trip(res, a, b);
return;
pick_b:
- pick_and_delete_trip(res, b, a, next);
+ pick_and_delete_trip(res, b, a);
}
/*
@@ -1030,19 +1030,13 @@ static int find_sample_offset(struct dive *a, struct dive *b)
* merges almost exact duplicates - something that happens easily
* with overlapping dive downloads.
*/
-struct dive *try_to_merge(struct dive *a, struct dive *b, struct dive *next)
+struct dive *try_to_merge(struct dive *a, struct dive *b)
{
- struct dive *res;
int offset;
/*
* This assumes that the clocks on the dive computers are
* roughly synchronized.
- *
- * We'll probably have to move this into the caller, and
- * allow people to override this ("manual merge dives") if
- * they have computers that they forgot to change the time
- * zone on etc..
*/
if ((a->when >= b->when + 60) || (a->when <= b->when - 60))
return NULL;
@@ -1052,10 +1046,15 @@ struct dive *try_to_merge(struct dive *a, struct dive *b, struct dive *next)
if (offset > 120 || offset < -120)
return NULL;
- res = alloc_dive();
+ return merge_dives(a, b, offset);
+}
+
+struct dive *merge_dives(struct dive *a, struct dive *b, int offset)
+{
+ struct dive *res = alloc_dive();
res->when = a->when;
- merge_trip(res, a, b, next);
+ merge_trip(res, a, b);
MERGE_NONZERO(res, a, b, latitude);
MERGE_NONZERO(res, a, b, longitude);
MERGE_TXT(res, a, b, location);