diff options
author | Robert C. Helling <helling@atdotde.de> | 2018-07-02 21:13:44 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2018-07-03 14:47:15 -0700 |
commit | 00f4fa0d1da7b07efed340e5530dd966b22a1fc7 (patch) | |
tree | 3b221380f8db65ce05c02a0d8473c5a2e4c059d8 /core/dive.c | |
parent | 8697f7a84d988155e13079e32a7dd00fe418ee42 (diff) | |
download | subsurface-00f4fa0d1da7b07efed340e5530dd966b22a1fc7.tar.gz |
Profile context menu entry to split a dive
Allow the user to manually split a dive in two.
Signed-off-by: Robert C. Helling <helling@atdotde.de>
Diffstat (limited to 'core/dive.c')
-rw-r--r-- | core/dive.c | 20 |
1 files changed, 20 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" |