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.
This commit is contained in:
9
dive.c
9
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user