aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorGravatar Tim Segers <tsegers@pm.me>2022-10-02 16:04:31 +0200
committerGravatar Tim Segers <tsegers@pm.me>2022-10-02 16:28:41 +0200
commit723d76f2912faeac891156ee061eb57fc2700f51 (patch)
tree297c48f343ecc7a9bcf72355b332030afb9c58fc
parent104aff651d31d66e8e0375bbfdf78eba673b174d (diff)
downloadopendeco-723d76f2912faeac891156ee061eb57fc2700f51.tar.gz
Fix descents leading to negative segment times
-rw-r--r--schedule.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/schedule.c b/schedule.c
index 9f0114d..f7f998a 100644
--- a/schedule.c
+++ b/schedule.c
@@ -158,7 +158,7 @@ decoinfo_t calc_deco(decostate_t *ds, const double start_depth, const gas_t *sta
if (should_switch(&next, &switch_depth, ds, depth, next_stop, deco_gasses, nof_gasses)) {
/* ascend to gas switch */
- ret.tts += add_segment_ascdec(ds, depth, switch_depth, (depth - switch_depth) / asc_per_min, gas);
+ ret.tts += add_segment_ascdec(ds, depth, switch_depth, fabs(depth - switch_depth) / asc_per_min, gas);
depth = switch_depth;
current_gf = get_gf(ds, depth);
@@ -167,7 +167,7 @@ decoinfo_t calc_deco(decostate_t *ds, const double start_depth, const gas_t *sta
* any number of consecutive travel segments and the waypoint
* callback should be called.
*/
- waypoint_time = (last_waypoint_depth - depth) / asc_per_min;
+ waypoint_time = fabs(last_waypoint_depth - depth) / asc_per_min;
wp_cb(ds, (waypoint_t){.depth = depth, .time = waypoint_time, .gas = gas}, SEG_TRAVEL);
last_waypoint_depth = depth;
@@ -181,7 +181,7 @@ decoinfo_t calc_deco(decostate_t *ds, const double start_depth, const gas_t *sta
}
/* ascend to current ceiling */
- ret.tts += add_segment_ascdec(ds, depth, next_stop, (depth - next_stop) / asc_per_min, gas);
+ ret.tts += add_segment_ascdec(ds, depth, next_stop, fabs(depth - next_stop) / asc_per_min, gas);
depth = next_stop;
current_gf = get_gf(ds, depth);
@@ -194,7 +194,7 @@ decoinfo_t calc_deco(decostate_t *ds, const double start_depth, const gas_t *sta
* any number of consecutive travel segments and the waypoint
* callback should be called.
*/
- waypoint_time = (last_waypoint_depth - depth) / asc_per_min;
+ waypoint_time = fabs(last_waypoint_depth - depth) / asc_per_min;
if (depth <= SURFACE_PRESSURE)
wp_cb(ds, (waypoint_t){.depth = depth, .time = waypoint_time, .gas = gas}, SEG_SURFACE);