summaryrefslogtreecommitdiffstats
path: root/planner.c
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2014-07-11 10:10:15 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-07-11 10:10:15 -0700
commit6c9aaf406ad4dd7e5eb208a376def396a96a69d6 (patch)
tree7e6d05521f093e3fe6d76e7960f49ffff696ce29 /planner.c
parent966192613164622da2ae8f0770aad8a6cde508ee (diff)
downloadsubsurface-6c9aaf406ad4dd7e5eb208a376def396a96a69d6.tar.gz
Planner: fix calculation when it is safe to surface
We were comparing with a negative depth which apparently confused the algorithm. Fixes #611 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'planner.c')
-rw-r--r--planner.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/planner.c b/planner.c
index fa81563f1..462030177 100644
--- a/planner.c
+++ b/planner.c
@@ -822,7 +822,6 @@ void plan(struct diveplan *diveplan, char **cached_datap, bool is_planner, bool
if (depth <= 0)
break; /* We are at the surface */
-
if (gi >= 0 && stoplevels[stopidx] == gaschanges[gi].depth) {
/* We have reached a gas change.
* Record this in the dive plan */
@@ -849,6 +848,8 @@ void plan(struct diveplan *diveplan, char **cached_datap, bool is_planner, bool
clear_to_ascend = true;
while (trial_depth > stoplevels[stopidx]) {
int deltad = ascend_velocity(trial_depth, avg_depth, bottom_time) * TIMESTEP;
+ if (deltad > trial_depth) /* don't test against depth above surface */
+ deltad = trial_depth;
tissue_tolerance = add_segment(depth_to_mbar(trial_depth, &displayed_dive) / 1000.0,
&displayed_dive.cylinder[current_cylinder].gasmix,
TIMESTEP, po2, &displayed_dive);