diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/dive.c | 20 | ||||
-rw-r--r-- | core/dive.h | 1 |
2 files changed, 21 insertions, 0 deletions
diff --git a/core/dive.c b/core/dive.c index 2840e864f..2c4539530 100644 --- a/core/dive.c +++ b/core/dive.c @@ -3441,6 +3441,10 @@ static int split_dive_at(struct dive *dive, int a, int b) if ((nr = get_divenr(dive)) < 0) return 0; + /* Splitting should leave at least 3 samples per dive */ + if (a < 3 || b > dive->dc.samples - 4) + return 0; + /* We're not trying to be efficient here.. */ d1 = create_new_copy(dive); d2 = create_new_copy(dive); @@ -3583,6 +3587,22 @@ int split_dive(struct dive *dive) return 0; } +void split_dive_at_time(struct dive *dive, duration_t time) +{ + int i = 0; + struct sample *sample = dive->dc.sample; + + if (!dive) + return; + while(sample->time.seconds < time.seconds) { + ++sample; + ++i; + if (dive->dc.samples == i) + return; + } + split_dive_at(dive, i, i - 1); +} + /* * "dc_maxtime()" is how much total time this dive computer * has for this dive. Note that it can differ from "duration" diff --git a/core/dive.h b/core/dive.h index 3ab270261..1ce180238 100644 --- a/core/dive.h +++ b/core/dive.h @@ -761,6 +761,7 @@ extern int dive_getUniqID(struct dive *d); extern unsigned int dc_airtemp(struct divecomputer *dc); extern unsigned int dc_watertemp(struct divecomputer *dc); extern int split_dive(struct dive *); +extern void split_dive_at_time(struct dive *dive, duration_t time); extern struct dive *merge_dives(struct dive *a, struct dive *b, int offset, bool prefer_downloaded); extern struct dive *try_to_merge(struct dive *a, struct dive *b, bool prefer_downloaded); extern struct event *clone_event(const struct event *src_ev); |