From 082b09038d9834f8dccde97733eab6f3d90b7016 Mon Sep 17 00:00:00 2001 From: Tim Segers Date: Mon, 3 Oct 2022 15:50:45 +0200 Subject: Optimize stoplen calculation Find the length of a stop in 10 minute increments before refining it with 1 minute increments. --- schedule.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/schedule.c b/schedule.c index b737453..4c111f2 100644 --- a/schedule.c +++ b/schedule.c @@ -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); -- cgit v1.2.3-70-g09d2