From c0a429457ab9fae5e6995777b869b111ef32be74 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Tue, 6 Sep 2011 12:16:39 -0700 Subject: [PATCH] Tweak the "show depth in text" heuristic a bit Use a 10-minute window *or* when the depth has reversed sufficiently to make the max we've found interesting. Signed-off-by: Linus Torvalds --- profile.c | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/profile.c b/profile.c index 5ac8a01..52dc82b 100644 --- a/profile.c +++ b/profile.c @@ -52,9 +52,15 @@ static void plot_text(cairo_t *cr, double x, double y, const char *fmt, ...) cairo_show_text(cr, buffer); } -/* Find the next maximum point in a 5-minute window */ -static int next_minmax(struct dive *dive, int index, int max) +/* + * Find the next maximum point in a 10-minute window. + * + * We exit early if we hit "enough" of a depth reversal, + * which is roughly 10 feet. + */ +static int next_minmax(struct dive *dive, int index, int minmax) { + const int enough = 3000; int timelimit, depthlimit, result; struct sample *sample = dive->sample + index; @@ -76,17 +82,25 @@ static int next_minmax(struct dive *dive, int index, int max) depth = sample->depth.mm; if (time > timelimit) break; - if (max) { - if (depth <= depthlimit) + + if (minmax) { + if (depth <= depthlimit) { + if (depthlimit - depth > enough) + break; continue; + } } else { - if (depth >= depthlimit) + if (depth >= depthlimit) { + if (depth - depthlimit > enough) + break; continue; + } } - depthlimit = depth; - timelimit = time + 300; result = index; + depthlimit = depth; + /* Look up to ten minutes into the future */ + timelimit = time + 600; } return result; } -- 2.43.0