diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2020-05-01 10:55:42 +0200 |
---|---|---|
committer | Robert C. Helling <helling@atdotde.de> | 2020-05-01 12:36:28 +0200 |
commit | d787e8812c4cb62e323eb98bc0d9cbd1f714ffa7 (patch) | |
tree | ac38bdd608f742056d938ae07abed282681c5f4c /core | |
parent | 8bc4233add0a70a647e53a557b9c87146b8294f8 (diff) | |
download | subsurface-d787e8812c4cb62e323eb98bc0d9cbd1f714ffa7.tar.gz |
profile: for maxtime calculation include the sample after the last event
When plotting profiles with surface segments, there were strange
artifacts. As we found out with Robert, these were due to the fact
that the calculated maxtime was set to the last event which is just one
second inside the surface segment. This terribly confused the profile
code. For example, it didn't properly allocate samples for the surface
segment.
Thus, when calculating maxtime, consider the last sample beyond the
last event.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core')
-rw-r--r-- | core/profile.c | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/core/profile.c b/core/profile.c index efcfe45a4..6723f3734 100644 --- a/core/profile.c +++ b/core/profile.c @@ -391,6 +391,7 @@ static void calculate_max_limits_new(struct dive *dive, struct divecomputer *giv { struct divecomputer *dc = &(dive->dc); bool seen = false; + bool found_sample_beyond_last_event = false; int maxdepth = dive->maxdepth.mm; int maxtime = 0; int maxpressure = 0, minpressure = INT_MAX; @@ -418,6 +419,14 @@ static void calculate_max_limits_new(struct dive *dive, struct divecomputer *giv struct sample *s = dc->sample; struct event *ev; + /* Make sure we can fit all events */ + ev = dc->events; + while (ev) { + if (ev->time.seconds > maxtime) + maxtime = ev->time.seconds; + ev = ev->next; + } + while (--i >= 0) { int depth = s->depth.mm; int pressure = s->pressure[0].mbar; @@ -440,21 +449,18 @@ static void calculate_max_limits_new(struct dive *dive, struct divecomputer *giv if (depth > maxdepth) maxdepth = s->depth.mm; - if ((depth > SURFACE_THRESHOLD || lastdepth > SURFACE_THRESHOLD || in_planner()) && - s->time.seconds > maxtime) + /* Make sure that we get the first sample beyond the last event. + * If maxtime is somewhere in the middle of the last segment, + * populate_plot_entries() gets confused leading to display artifacts. */ + if ((depth > SURFACE_THRESHOLD || lastdepth > SURFACE_THRESHOLD || in_planner() || !found_sample_beyond_last_event) && + s->time.seconds > maxtime) { + found_sample_beyond_last_event = true; maxtime = s->time.seconds; + } lastdepth = depth; s++; } - /* Make sure we can fit all events */ - ev = dc->events; - while (ev) { - if (ev->time.seconds > maxtime) - maxtime = ev->time.seconds; - ev = ev->next; - } - dc = dc->next; if (dc == NULL && !seen) { dc = given_dc; |