aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/schedule.c
diff options
context:
space:
mode:
authorGravatar Tim Segers <tsegers@pm.me>2022-10-03 15:50:45 +0200
committerGravatar Tim Segers <tsegers@pm.me>2022-10-03 15:50:45 +0200
commit082b09038d9834f8dccde97733eab6f3d90b7016 (patch)
tree6e855cc9b398c7d551d7385d808f45fa0eb41bba /schedule.c
parente2ff193809aeb9cbc4cda896a48ecbefa4adb00c (diff)
downloadopendeco-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.c26
1 files changed, 26 insertions, 0 deletions
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);