]> git.tdb.fi Git - ext/subsurface.git/blobdiff - profile.c
Get rid of timelimit code and corner cases
[ext/subsurface.git] / profile.c
index 280a7fa1a214436d743ef4dc44606aa295c59f9e..706f60ba0d6fea984ca9c7bd73109ef6ed96aa7e 100644 (file)
--- a/profile.c
+++ b/profile.c
@@ -104,12 +104,11 @@ static struct sample *next_minmax(struct sample *sample, struct sample *end, int
 {
        const int enough = 3000;
        struct sample *result;
-       int timelimit, depthlimit;
+       int depthlimit;
 
        if (sample >= end)
                return 0;
 
-       timelimit = 24*60*60;
        depthlimit = sample->depth.mm;
        result = NULL;
 
@@ -121,8 +120,6 @@ static struct sample *next_minmax(struct sample *sample, struct sample *end, int
                        return NULL;
                time = sample->time.seconds;
                depth = sample->depth.mm;
-               if (time > timelimit)
-                       break;
 
                if (minmax) {
                        if (depth <= depthlimit) {
@@ -140,51 +137,48 @@ static struct sample *next_minmax(struct sample *sample, struct sample *end, int
 
                result = sample;
                depthlimit = depth;
-               /* Look up to ten minutes into the future */
-               timelimit = time + 600;
        }
        return result;
 }
 
-void plot_text_samples(struct dive *dive, struct graphics_context *gc,
-                       struct sample *a, struct sample *b)
+static void render_depth_sample(struct graphics_context *gc, struct sample *sample)
+{
+       text_render_options_t tro = {1.0, 0.2, 0.2, CENTER};
+       int sec = sample->time.seconds;
+       depth_t depth = sample->depth;
+       const char *fmt;
+       double d;
+
+       switch (output_units.length) {
+       case METERS:
+               d = depth.mm / 1000.0;
+               fmt = "%.1f";
+               break;
+       case FEET:
+               d = to_feet(depth);
+               fmt = "%.0f";
+               break;
+       }
+       plot_text(gc, &tro, sec, depth.mm, fmt, d);
+}
+
+static void plot_text_samples(struct graphics_context *gc, struct sample *a, struct sample *b)
 {
        struct sample *max, *min;
 
-       if (b < a)
+       if (b <= a)
                return;
-       if (b->time.seconds - a->time.seconds < 3*60)
+       if (b[-1].time.seconds - a->time.seconds < 3*60)
                return;
 
        max = next_minmax(a, b, 1);
        if (max) {
-               text_render_options_t tro = {1.0, 0.2, 0.2, CENTER};
-               int sec = max->time.seconds;
-               depth_t depth = max->depth;
-               const char *fmt;
-               double d;
-
+               render_depth_sample(gc, max);
                min = next_minmax(max, b, 0);
-               plot_text_samples(dive, gc, a, max);
                if (min) {
-                       plot_text_samples(dive, gc, max, min);
-                       plot_text_samples(dive, gc, min, b);
-               } else
-                       plot_text_samples(dive, gc, max, b);
-
-               switch (output_units.length) {
-               case METERS:
-                       d = depth.mm / 1000.0;
-                       fmt = "%.1f";
-                       break;
-               case FEET:
-                       d = to_feet(depth);
-                       fmt = "%.0f";
-                       break;
+                       plot_text_samples(gc, min, b);
+                       return;
                }
-
-               plot_text(gc, &tro, sec, depth.mm, fmt, d);
-               return;
        }
 }
 
@@ -202,15 +196,10 @@ static void plot_depth_text(struct dive *dive, struct graphics_context *gc)
 
        cairo_set_font_size(gc->cr, 14);
 
-       /*
-        * We never take the last sample into account.
-        * It should be a surface event anyway, although
-        * there are buggy cases where it isn't..
-        */
        sample = dive->sample;
-       end = dive->sample + dive->samples - 1;
+       end = dive->sample + dive->samples;
 
-       plot_text_samples(dive, gc, sample, end);
+       plot_text_samples(gc, sample, end);
 }
 
 static void plot_depth_profile(struct dive *dive, struct graphics_context *gc)