core: move get_max_mod() and get_max_mnd() to struct dive

Feels natural in a C++ code base.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2024-06-30 16:17:20 +02:00 committed by bstoeger
parent d36fd79527
commit 286d8fe21c
6 changed files with 36 additions and 42 deletions

View file

@ -2476,21 +2476,16 @@ int dive::mbar_to_depth(int mbar) const
}
/* MOD rounded to multiples of roundto mm */
depth_t gas_mod(struct gasmix mix, pressure_t po2_limit, const struct dive *dive, int roundto)
depth_t dive::gas_mod(struct gasmix mix, pressure_t po2_limit, int roundto) const
{
depth_t rounded_depth;
double depth = (double) dive->mbar_to_depth(po2_limit.mbar * 1000 / get_o2(mix));
rounded_depth.mm = (int)lrint(depth / roundto) * roundto;
return rounded_depth;
double depth = (double) mbar_to_depth(po2_limit.mbar * 1000 / get_o2(mix));
return depth_t { (int)lrint(depth / roundto) * roundto };
}
/* Maximum narcotic depth rounded to multiples of roundto mm */
depth_t gas_mnd(struct gasmix mix, depth_t end, const struct dive *dive, int roundto)
depth_t dive::gas_mnd(struct gasmix mix, depth_t end, int roundto) const
{
depth_t rounded_depth;
pressure_t ppo2n2;
ppo2n2.mbar = dive->depth_to_mbar(end.mm);
pressure_t ppo2n2 { depth_to_mbar(end.mm) };
int maxambient = prefs.o2narcotic ?
(int)lrint(ppo2n2.mbar / (1 - get_he(mix) / 1000.0))
@ -2500,8 +2495,7 @@ depth_t gas_mnd(struct gasmix mix, depth_t end, const struct dive *dive, int rou
:
// Actually: Infinity
1000000;
rounded_depth.mm = (int)lrint(((double)dive->mbar_to_depth(maxambient)) / roundto) * roundto;
return rounded_depth;
return depth_t { (int)lrint(((double)mbar_to_depth(maxambient)) / roundto) * roundto };
}
struct dive_site *get_dive_site_for_dive(const struct dive *dive)

View file

@ -115,6 +115,8 @@ struct dive {
pressure_t calculate_surface_pressure() const;
pressure_t un_fixup_surface_pressure() const;
depth_t gas_mod(struct gasmix mix, pressure_t po2_limit, int roundto) const;
depth_t gas_mnd(struct gasmix mix, depth_t end, int roundto) const;
/* Don't call directly, use dive_table::merge_dives()! */
static std::unique_ptr<dive> create_merged_dive(const struct dive &a, const struct dive &b, int offset, bool prefer_downloaded);
@ -153,8 +155,6 @@ extern fraction_t best_o2(depth_t depth, const struct dive *dive, bool in_planne
extern fraction_t best_he(depth_t depth, const struct dive *dive, bool o2narcotic, fraction_t fo2);
extern int get_surface_pressure_in_mbar(const struct dive *dive, bool non_null);
extern depth_t gas_mod(struct gasmix mix, pressure_t po2_limit, const struct dive *dive, int roundto);
extern depth_t gas_mnd(struct gasmix mix, depth_t end, const struct dive *dive, int roundto);
extern struct dive_site *get_dive_site_for_dive(const struct dive *dive);
extern std::string get_dive_country(const struct dive *dive);

View file

@ -333,7 +333,7 @@ void reset_cylinders(struct dive *dive, bool track_gas)
for (cylinder_t &cyl: dive->cylinders) {
if (cyl.depth.mm == 0) /* if the gas doesn't give a mod, calculate based on prefs */
cyl.depth = gas_mod(cyl.gasmix, decopo2, dive, M_OR_FT(3,10));
cyl.depth = dive->gas_mod(cyl.gasmix, decopo2, M_OR_FT(3,10));
if (track_gas)
cyl.start.mbar = cyl.end.mbar = cyl.type.workingpressure.mbar;
cyl.gas_used.mliter = 0;
@ -400,7 +400,7 @@ void fill_default_cylinder(const struct dive *dive, cylinder_t *cyl)
cyl->type.size.mliter = lrint(cuft_to_l(ti.cuft) * 1000 / bar_to_atm(psi_to_bar(ti.psi)));
}
// MOD of air
cyl->depth = gas_mod(cyl->gasmix, pO2, dive, 1);
cyl->depth = dive->gas_mod(cyl->gasmix, pO2, 1);
return;
}
}

View file

@ -1129,7 +1129,7 @@ static void calculate_gas_information_new(const struct dive *dive, const struct
* END takes O + N (air) into account ("Narcotic" for trimix dives)
* EAD just uses N ("Air" for nitrox dives) */
pressure_t modpO2 = { .mbar = (int)(prefs.modpO2 * 1000) };
entry.mod = gas_mod(gasmix, modpO2, dive, 1).mm;
entry.mod = dive->gas_mod(gasmix, modpO2, 1).mm;
entry.end = dive->mbar_to_depth(lrint(dive->depth_to_mbarf(entry.depth) * (1000 - fhe) / 1000.0));
entry.ead = dive->mbar_to_depth(lrint(dive->depth_to_mbarf(entry.depth) * fn2 / (double)N2_IN_AIR));
entry.eadd = dive->mbar_to_depth(lrint(dive->depth_to_mbarf(entry.depth) *