]> git.tdb.fi Git - ext/subsurface.git/commitdiff
Fix profile and average depth for freedives master
authorMikko Rasa <tdb@tdb.fi>
Wed, 29 Aug 2012 16:10:26 +0000 (19:10 +0300)
committerMikko Rasa <tdb@tdb.fi>
Wed, 29 Aug 2012 16:12:18 +0000 (19:12 +0300)
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.

dive.c
profile.c

diff --git a/dive.c b/dive.c
index aee09d53a8b37796fc6f2fa0e448f92102be745e..54784cdbabfb01fbb5c5a8db539cdc481f20c613 100644 (file)
--- 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;
        }
index d4e88c02c21c498293d87a87ebf0f7a853a13ea0..0039867efc29355737294cb1ac02a0cb85743ce6 100644 (file)
--- a/profile.c
+++ b/profile.c
@@ -1387,6 +1387,8 @@ void plot(struct graphics_context *gc, cairo_rectangle_int_t *drawing_area, stru
                int duration = dive->duration.seconds;
                int maxdepth = dive->maxdepth.mm;
                int asc_desc_time = dive->maxdepth.mm*60/9000;
+               if (asc_desc_time * 2 >= duration)
+                       asc_desc_time = duration / 2;
                sample = fake;
                fake[1].time.seconds = asc_desc_time;
                fake[1].depth.mm = maxdepth;