diff options
author | Tim Segers <tsegers@pm.me> | 2022-10-03 15:50:45 +0200 |
---|---|---|
committer | Tim Segers <tsegers@pm.me> | 2022-10-03 15:50:45 +0200 |
commit | 082b09038d9834f8dccde97733eab6f3d90b7016 (patch) | |
tree | 6e855cc9b398c7d551d7385d808f45fa0eb41bba /schedule.c | |
parent | e2ff193809aeb9cbc4cda896a48ecbefa4adb00c (diff) | |
download | opendeco-082b09038d9834f8dccde97733eab6f3d90b7016.tar.gz |
Optimize stoplen calculation
Find the length of a stop in 10 minute increments before refining it
with 1 minute increments.
Diffstat (limited to 'schedule.c')
-rw-r--r-- | schedule.c | 26 |
1 files changed, 26 insertions, 0 deletions
@@ -90,6 +90,23 @@ double calc_ndl(decostate_t *ds, const double depth, const double ascrate, const return ndl; } +double calc_stoplen_rough(decostate_t *ds, const double depth, const double current_gf, const gas_t *gas) +{ + decostate_t ds_ = *ds; + double stoplen = 0; + + while (1) { + double tmp = add_segment_const(&ds_, depth, 10, gas); + + if (ceiling(&ds_, current_gf) != depth) + break; + + stoplen += tmp; + } + + return stoplen; +} + int should_switch(const gas_t **next, double *switch_depth, const decostate_t *ds, const double depth, const double next_stop, const gas_t *deco_gasses, const int nof_gasses) { @@ -222,6 +239,15 @@ decoinfo_t calc_deco(decostate_t *ds, const double start_depth, const gas_t *sta /* stop */ double stoplen = 0; + /* rough steps */ + double stoplen_rough = calc_stoplen_rough(ds, depth, current_gf, gas); + + if (stoplen_rough) { + add_segment_const(ds, depth, stoplen_rough, gas); + stoplen += stoplen_rough; + } + + /* fine steps */ while (ceiling(ds, current_gf) == depth) stoplen += add_segment_const(ds, depth, 1, gas); |