From 9ec5076b0f891b1dea64d165e622841ef4dfb1c0 Mon Sep 17 00:00:00 2001 From: Tim Segers Date: Fri, 14 Oct 2022 14:27:21 +0200 Subject: Tether GF to first and last stop instead of first stop and surface Also make an exception for when the last stop is at 6m. In that case, do not tether the GF to 6m, but instead treat 6m as if it was 3m. Fixes ~tsegers/opendeco#6 --- src/deco.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/deco.c b/src/deco.c index 204a2a7..80853b8 100644 --- a/src/deco.c +++ b/src/deco.c @@ -197,18 +197,19 @@ double get_gf(const decostate_t *ds, const double depth) const unsigned char lo = ds->gflo; const unsigned char hi = ds->gfhi; + double last_stop_gauge = LAST_STOP_AT_SIX ? 2 * ds->ceil_multiple : ds->ceil_multiple; + if (ds->firststop == -1) return lo; - if (depth < SURFACE_PRESSURE) + if (depth <= SURFACE_PRESSURE + last_stop_gauge) return hi; - if (depth > ds->firststop) + if (depth >= ds->firststop) return lo; - /* interpolate lo and hi between first stop and surface */ - double next_stop = depth - ds->ceil_multiple; - return hi - (hi - lo) * gauge_depth(next_stop) / gauge_depth(ds->firststop); + /* interpolate lo and hi between first stop and last stop */ + return hi - (hi - lo) * gauge_depth(depth - ds->ceil_multiple) / gauge_depth(ds->firststop - ds->ceil_multiple); } double round_ceiling(const decostate_t *ds, const double c) -- cgit v1.2.3-70-g09d2