summaryrefslogtreecommitdiffstats
path: root/dive.c
diff options
context:
space:
mode:
authorGravatar Mikko Rasa <tdb@tdb.fi>2012-08-29 19:10:26 +0300
committerGravatar Mikko Rasa <tdb@tdb.fi>2012-08-29 19:12:18 +0300
commitd6b50e30e405433bdb1edad341ee90c65ae65419 (patch)
treee620ed4f383748b93d6e63eccbc1aacd6f260b47 /dive.c
parent9d46581913ce33664e333a4d6eaf7f4e26e20b1c (diff)
downloadsubsurface-d6b50e30e405433bdb1edad341ee90c65ae65419.tar.gz
Fix profile and average depth for freedives
Freedives can easily exceed the assumed ascent/descent rate, which results in wacky dive profiles. Add a check to make the ascent and descent fit within the duration of the dive.
Diffstat (limited to 'dive.c')
-rw-r--r--dive.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/dive.c b/dive.c
index aee09d53a..54784cdba 100644
--- a/dive.c
+++ b/dive.c
@@ -478,11 +478,12 @@ struct dive *fixup_dive(struct dive *dive)
int asc_desc_time = depth*60/9000;
int duration = dive->duration.seconds;
- /* Protect against insane dives - make mean be half of max */
- if (duration <= asc_desc_time) {
+ /* Some sanity checks against insane dives */
+ if (duration < 2)
duration = 2;
- asc_desc_time = 1;
- }
+ if (asc_desc_time * 2 >= duration)
+ asc_desc_time = duration/2;
+
dive->meandepth.mm = depth*(duration-asc_desc_time)/duration;
return dive;
}