summaryrefslogtreecommitdiffstats
path: root/planner.c
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2013-01-08 13:54:29 -0800
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-01-08 13:54:29 -0800
commit1bec821c731780a9a0b8292691f5e375128a6640 (patch)
treee9fbcf7d35ff0cb33b7070e2dbb07510f8c14872 /planner.c
parentbad7882ae141efbee3a339046c4a8f5b51ef89c6 (diff)
downloadsubsurface-1bec821c731780a9a0b8292691f5e375128a6640.tar.gz
Fix the deco calculation in the dive planner
The existing code incorrectly started all calculation at the depth at the end of the first segment. So if you went to 50m in 5min in your first segment, you incorrectly got 5 minutes at 50m (instead of a progression from 0 to 50m, over 5 minutes). This commit fixes that and now gives us planned dives that then match what is shown in the profile. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'planner.c')
-rw-r--r--planner.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/planner.c b/planner.c
index d74dd7570..16f09010b 100644
--- a/planner.c
+++ b/planner.c
@@ -48,7 +48,7 @@ double tissue_at_end(struct dive *dive, char **cached_datap)
{
struct divecomputer *dc;
struct sample *sample, *psample;
- int i, j, t0, t1;
+ int i, j, t0, t1, lastdepth;
double tissue_tolerance;
if (!dive)
@@ -63,11 +63,13 @@ double tissue_at_end(struct dive *dive, char **cached_datap)
if (!dc->samples)
return tissue_tolerance;
psample = sample = dc->sample;
- t0 = 0;
+ lastdepth = t0 = 0;
for (i = 0; i < dc->samples; i++, sample++) {
t1 = sample->time.seconds;
+ if (i > 0)
+ lastdepth = psample->depth.mm;
for (j = t0; j < t1; j++) {
- int depth = psample->depth.mm + (j - t0) * (sample->depth.mm - psample->depth.mm) / (t1 - t0);
+ int depth = lastdepth + (j - t0) * (sample->depth.mm - lastdepth) / (t1 - t0);
tissue_tolerance = add_segment(depth_to_mbar(depth, dive) / 1000.0,
&dive->cylinder[sample->sensor].gasmix, 1, sample->po2, dive);
}