diff options
author | Robert C. Helling <helling@atdotde.de> | 2015-07-06 00:07:39 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2015-07-05 15:53:49 -0700 |
commit | a7d18a9fa649e1f6e9b7d553e286abce8a430b9a (patch) | |
tree | 61737419a9b77a6737d931fc4e195579fcb19e70 /dive.h | |
parent | 9c6a3a7ff387578ddede2e69d8b994a11cf8eaee (diff) | |
download | subsurface-a7d18a9fa649e1f6e9b7d553e286abce8a430b9a.tar.gz |
Round MOD of gas rather than truncate
For the proper calculation, we need to take salinity and surface pressure
into account (rather than depth = bar * 10 - 10)
Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'dive.h')
-rw-r--r-- | dive.h | 26 |
1 files changed, 19 insertions, 7 deletions
@@ -167,13 +167,6 @@ static inline int interpolate(int a, int b, int part, int whole) return rint(x / whole); } -/* MOD rounded to multiples of roundto mm */ -static inline depth_t gas_mod(struct gasmix *mix, pressure_t po2_limit, int roundto) { - depth_t depth; - depth.mm = ((po2_limit.mbar * 1000 / get_o2(mix) * 10 - 10000) / roundto) * roundto; - return depth; -} - void get_gas_string(const struct gasmix *gasmix, char *text, int len); const char *gasname(const struct gasmix *gasmix); @@ -445,6 +438,25 @@ static inline int rel_mbar_to_depth(int mbar, struct dive *dive) return cm * 10; } +static inline int mbar_to_depth(int mbar, struct dive *dive) +{ + pressure_t surface_pressure; + if (dive->surface_pressure.mbar) + surface_pressure = dive->surface_pressure; + else + surface_pressure.mbar = SURFACE_PRESSURE; + return rel_mbar_to_depth(mbar - surface_pressure.mbar, dive); +} + +/* MOD rounded to multiples of roundto mm */ +static inline depth_t gas_mod(struct gasmix *mix, pressure_t po2_limit, struct dive *dive, int roundto) { + depth_t rounded_depth; + + double depth = (double) mbar_to_depth(po2_limit.mbar * 1000 / get_o2(mix), dive); + rounded_depth.mm = rint(depth / roundto) * roundto; + return rounded_depth; +} + #define SURFACE_THRESHOLD 750 /* somewhat arbitrary: only below 75cm is it really diving */ /* this is a global spot for a temporary dive structure that we use to |