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>
This commit is contained in:
Berthold Stoeger 2020-05-01 10:55:42 +02:00 committed by Robert C. Helling
parent 8bc4233add
commit d787e8812c
2 changed files with 17 additions and 10 deletions

View file

@ -1,3 +1,4 @@
Desktop: fix profile display of planned dives with surface segments
maps: show the dive site as marker when opening Google Maps
Mobile: fix false rejection of Subsurface cloud SSL certificate
Mobile: fix misdetection of Shearwater Petrel 2 on iOS

View file

@ -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;