core: make round_to parameter of gas_mod() and gas_mnd() a depth_t

Simplifies practically all the callers.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2024-12-14 10:35:56 +01:00
parent e9c14c523c
commit c46579c006
6 changed files with 34 additions and 34 deletions

View file

@ -2455,16 +2455,16 @@ depth_t dive::mbar_to_depth(int mbar) const
}
/* MOD rounded to multiples of roundto mm */
depth_t dive::gas_mod(struct gasmix mix, pressure_t po2_limit, int roundto) const
depth_t dive::gas_mod(struct gasmix mix, pressure_t po2_limit, depth_t roundto) const
{
double depth = (double) mbar_to_depth(po2_limit.mbar * 1000 / get_o2(mix)).mm;
// Rounding should be towards lower=safer depths but we give a bit
// of fudge to all to switch to o2 at 6m. So from .9 we round up.
return depth_t { .mm = (int)(depth / roundto + 0.1) * roundto };
return depth_t { .mm = (int)(depth / roundto.mm + 0.1) * roundto.mm };
}
/* Maximum narcotic depth rounded to multiples of roundto mm */
depth_t dive::gas_mnd(struct gasmix mix, depth_t end, int roundto) const
depth_t dive::gas_mnd(struct gasmix mix, depth_t end, depth_t roundto) const
{
pressure_t ppo2n2 { .mbar = depth_to_mbar(end) };
@ -2477,7 +2477,7 @@ depth_t dive::gas_mnd(struct gasmix mix, depth_t end, int roundto) const
// Actually: Infinity
1000000;
double depth = static_cast<double>(mbar_to_depth(maxambient).mm);
return depth_t { .mm = int_cast<int>(depth / roundto) * roundto };
return depth_t { .mm = int_cast<int>(depth / roundto.mm) * roundto.mm };
}
std::string dive::get_country() const

View file

@ -125,8 +125,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;
depth_t gas_mod(struct gasmix mix, pressure_t po2_limit, depth_t roundto) const;
depth_t gas_mnd(struct gasmix mix, depth_t end, depth_t roundto) const;
fraction_t best_o2(depth_t depth, bool in_planner) const;
fraction_t best_he(depth_t depth, bool o2narcotic, fraction_t fo2) const;

View file

@ -314,7 +314,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 = dive->gas_mod(cyl.gasmix, decopo2, m_or_ft(3, 10).mm);
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 = 0_l;
@ -364,7 +364,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 = dive->gas_mod(cyl->gasmix, pO2, 1);
cyl->depth = dive->gas_mod(cyl->gasmix, pO2, 1_mm);
return;
}
}

View file

@ -1131,7 +1131,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 = dive->gas_mod(gasmix, modpO2, 1).mm;
entry.mod = dive->gas_mod(gasmix, modpO2, 1_mm).mm;
entry.end = dive->mbar_to_depth(lrint(dive->depth_to_mbarf(depth) * (1000 - fhe) / 1000.0)).mm;
entry.ead = dive->mbar_to_depth(lrint(dive->depth_to_mbarf(depth) * fn2 / (double)N2_IN_AIR)).mm;
entry.eadd = dive->mbar_to_depth(lrint(dive->depth_to_mbarf(depth) *