mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-31 23:03:23 +00:00
Move mod calculations to a separate helper
We use mod calculations on multiple places, so make a separate helper from it with proper types. The "clumsiness" of defining a local variable to pass into the function and out from it comes from the discrepancies in how c and c++ handles initializations of variables in a struct. Thanks goes to Tiago and Linus for pointing me in the right direction. Signed-off-by: Anton Lundin <glance@acc.umu.se> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
a85023a661
commit
ff966f2c1a
3 changed files with 11 additions and 5 deletions
6
dive.h
6
dive.h
|
@ -104,6 +104,12 @@ static inline int interpolate(int a, int b, int part, int whole)
|
|||
return rint(x / whole);
|
||||
}
|
||||
|
||||
static inline depth_t gas_mod(struct gasmix *mix, pressure_t po2_limit) {
|
||||
depth_t depth;
|
||||
depth.mm = po2_limit.mbar * 1000 / get_o2(mix) * 10 - 10000;
|
||||
return depth;
|
||||
}
|
||||
|
||||
struct sample {
|
||||
duration_t time;
|
||||
depth_t depth;
|
||||
|
|
|
@ -1155,7 +1155,8 @@ static void calculate_gas_information_new(struct dive *dive, struct plot_info *p
|
|||
* so there is no difference in calculating between OC and CC
|
||||
* END takes O2 + N2 (air) into account ("Narcotic" for trimix dives)
|
||||
* EAD just uses N2 ("Air" for nitrox dives) */
|
||||
entry->mod = (prefs.modppO2 / fo2 * 1000 - 1) * 10000;
|
||||
pressure_t modppO2 = { .mbar = (int) (prefs.modppO2 * 1000) };
|
||||
entry->mod = (double) gas_mod(&dive->cylinder[cylinderindex].gasmix, modppO2).mm;
|
||||
entry->end = (entry->depth + 10000) * (1000 - fhe) / 1000.0 - 10000;
|
||||
entry->ead = (entry->depth + 10000) * (1000 - fo2 - fhe) / (double)N2_IN_AIR - 10000;
|
||||
entry->eadd = (entry->depth + 10000) *
|
||||
|
|
|
@ -499,10 +499,9 @@ bool DivePlannerPointsModel::addGas(int o2, int he)
|
|||
cyl->gasmix.he.permille = he;
|
||||
/* The depth to change to that gas is given by the depth where its pO2 is 1.6 bar.
|
||||
* The user should be able to change this depth manually. */
|
||||
if (!o2)
|
||||
cyl->depth.mm = 1600 * 1000 / O2_IN_AIR * 10 - 10000;
|
||||
else
|
||||
cyl->depth.mm = 1600 * 1000 / o2 * 10 - 10000;
|
||||
pressure_t modppO2;
|
||||
modppO2.mbar = 1600;
|
||||
cyl->depth = gas_mod(&cyl->gasmix, modppO2);
|
||||
CylindersModel::instance()->setDive(stagingDive);
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue