mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
core: move best_o2() and best_he() 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:
parent
6e349793d1
commit
28814829e0
3 changed files with 13 additions and 14 deletions
|
@ -2342,12 +2342,12 @@ std::unique_ptr<dive> clone_make_first_dc(const struct dive &d, int dc_number)
|
||||||
}
|
}
|
||||||
|
|
||||||
//Calculate O2 in best mix
|
//Calculate O2 in best mix
|
||||||
fraction_t best_o2(depth_t depth, const struct dive *dive, bool in_planner)
|
fraction_t dive::best_o2(depth_t depth, bool in_planner) const
|
||||||
{
|
{
|
||||||
fraction_t fo2;
|
fraction_t fo2;
|
||||||
int po2 = in_planner ? prefs.bottompo2 : (int)(prefs.modpO2 * 1000.0);
|
int po2 = in_planner ? prefs.bottompo2 : (int)(prefs.modpO2 * 1000.0);
|
||||||
|
|
||||||
fo2.permille = (po2 * 100 / dive->depth_to_mbar(depth.mm)) * 10; //use integer arithmetic to round down to nearest percent
|
fo2.permille = (po2 * 100 / depth_to_mbar(depth.mm)) * 10; //use integer arithmetic to round down to nearest percent
|
||||||
// Don't permit >100% O2
|
// Don't permit >100% O2
|
||||||
if (fo2.permille > 1000)
|
if (fo2.permille > 1000)
|
||||||
fo2.permille = 1000;
|
fo2.permille = 1000;
|
||||||
|
@ -2355,12 +2355,12 @@ fraction_t best_o2(depth_t depth, const struct dive *dive, bool in_planner)
|
||||||
}
|
}
|
||||||
|
|
||||||
//Calculate He in best mix. O2 is considered narcopic
|
//Calculate He in best mix. O2 is considered narcopic
|
||||||
fraction_t best_he(depth_t depth, const struct dive *dive, bool o2narcotic, fraction_t fo2)
|
fraction_t dive::best_he(depth_t depth, bool o2narcotic, fraction_t fo2) const
|
||||||
{
|
{
|
||||||
fraction_t fhe;
|
fraction_t fhe;
|
||||||
int pnarcotic, ambient;
|
int pnarcotic, ambient;
|
||||||
pnarcotic = dive->depth_to_mbar(prefs.bestmixend.mm);
|
pnarcotic = depth_to_mbar(prefs.bestmixend.mm);
|
||||||
ambient = dive->depth_to_mbar(depth.mm);
|
ambient = depth_to_mbar(depth.mm);
|
||||||
if (o2narcotic) {
|
if (o2narcotic) {
|
||||||
fhe.permille = (100 - 100 * pnarcotic / ambient) * 10; //use integer arithmetic to round up to nearest percent
|
fhe.permille = (100 - 100 * pnarcotic / ambient) * 10; //use integer arithmetic to round up to nearest percent
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -125,6 +125,8 @@ struct dive {
|
||||||
pressure_t un_fixup_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_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_mnd(struct gasmix mix, depth_t end, int 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;
|
||||||
|
|
||||||
bool dive_has_gps_location() const;
|
bool dive_has_gps_location() const;
|
||||||
location_t get_gps_location() const;
|
location_t get_gps_location() const;
|
||||||
|
@ -162,9 +164,6 @@ struct dive_components {
|
||||||
unsigned int when : 1;
|
unsigned int when : 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern fraction_t best_o2(depth_t depth, const struct dive *dive, bool in_planner);
|
|
||||||
extern fraction_t best_he(depth_t depth, const struct dive *dive, bool o2narcotic, fraction_t fo2);
|
|
||||||
|
|
||||||
extern std::unique_ptr<dive> clone_make_first_dc(const struct dive &d, int dc_number);
|
extern std::unique_ptr<dive> clone_make_first_dc(const struct dive &d, int dc_number);
|
||||||
|
|
||||||
extern bool time_during_dive_with_offset(const struct dive *dive, timestamp_t when, timestamp_t offset);
|
extern bool time_during_dive_with_offset(const struct dive *dive, timestamp_t when, timestamp_t offset);
|
||||||
|
|
|
@ -424,11 +424,11 @@ bool CylindersModel::setData(const QModelIndex &index, const QVariant &value, in
|
||||||
if (QString::compare(qPrintable(vString), "*") == 0) {
|
if (QString::compare(qPrintable(vString), "*") == 0) {
|
||||||
cyl.bestmix_o2 = true;
|
cyl.bestmix_o2 = true;
|
||||||
// Calculate fO2 for max. depth
|
// Calculate fO2 for max. depth
|
||||||
cyl.gasmix.o2 = best_o2(d->maxdepth, d, inPlanner);
|
cyl.gasmix.o2 = d->best_o2(d->maxdepth, inPlanner);
|
||||||
} else {
|
} else {
|
||||||
cyl.bestmix_o2 = false;
|
cyl.bestmix_o2 = false;
|
||||||
// Calculate fO2 for input depth
|
// Calculate fO2 for input depth
|
||||||
cyl.gasmix.o2 = best_o2(string_to_depth(qPrintable(vString)), d, inPlanner);
|
cyl.gasmix.o2 = d->best_o2(string_to_depth(qPrintable(vString)), inPlanner);
|
||||||
}
|
}
|
||||||
pressure_t modpO2;
|
pressure_t modpO2;
|
||||||
modpO2.mbar = prefs.decopo2;
|
modpO2.mbar = prefs.decopo2;
|
||||||
|
@ -440,11 +440,11 @@ bool CylindersModel::setData(const QModelIndex &index, const QVariant &value, in
|
||||||
if (QString::compare(qPrintable(vString), "*") == 0) {
|
if (QString::compare(qPrintable(vString), "*") == 0) {
|
||||||
cyl.bestmix_he = true;
|
cyl.bestmix_he = true;
|
||||||
// Calculate fO2 for max. depth
|
// Calculate fO2 for max. depth
|
||||||
cyl.gasmix.he = best_he(d->maxdepth, d, prefs.o2narcotic, make_fraction(get_o2(cyl.gasmix)));
|
cyl.gasmix.he = d->best_he(d->maxdepth, prefs.o2narcotic, make_fraction(get_o2(cyl.gasmix)));
|
||||||
} else {
|
} else {
|
||||||
cyl.bestmix_he = false;
|
cyl.bestmix_he = false;
|
||||||
// Calculate fHe for input depth
|
// Calculate fHe for input depth
|
||||||
cyl.gasmix.he = best_he(string_to_depth(qPrintable(vString)), d, prefs.o2narcotic, make_fraction(get_o2(cyl.gasmix)));
|
cyl.gasmix.he = d->best_he(string_to_depth(qPrintable(vString)), prefs.o2narcotic, make_fraction(get_o2(cyl.gasmix)));
|
||||||
}
|
}
|
||||||
type = Command::EditCylinderType::GASMIX;
|
type = Command::EditCylinderType::GASMIX;
|
||||||
break;
|
break;
|
||||||
|
@ -663,7 +663,7 @@ bool CylindersModel::updateBestMixes()
|
||||||
bool gasUpdated = false;
|
bool gasUpdated = false;
|
||||||
for (auto &cyl: d->cylinders) {
|
for (auto &cyl: d->cylinders) {
|
||||||
if (cyl.bestmix_o2) {
|
if (cyl.bestmix_o2) {
|
||||||
cyl.gasmix.o2 = best_o2(d->maxdepth, d, inPlanner);
|
cyl.gasmix.o2 = d->best_o2(d->maxdepth, inPlanner);
|
||||||
// fO2 + fHe must not be greater than 1
|
// fO2 + fHe must not be greater than 1
|
||||||
if (get_o2(cyl.gasmix) + get_he(cyl.gasmix) > 1000)
|
if (get_o2(cyl.gasmix) + get_he(cyl.gasmix) > 1000)
|
||||||
cyl.gasmix.he.permille = 1000 - get_o2(cyl.gasmix);
|
cyl.gasmix.he.permille = 1000 - get_o2(cyl.gasmix);
|
||||||
|
@ -673,7 +673,7 @@ bool CylindersModel::updateBestMixes()
|
||||||
gasUpdated = true;
|
gasUpdated = true;
|
||||||
}
|
}
|
||||||
if (cyl.bestmix_he) {
|
if (cyl.bestmix_he) {
|
||||||
cyl.gasmix.he = best_he(d->maxdepth, d, prefs.o2narcotic, cyl.gasmix.o2);
|
cyl.gasmix.he = d->best_he(d->maxdepth, prefs.o2narcotic, cyl.gasmix.o2);
|
||||||
// fO2 + fHe must not be greater than 1
|
// fO2 + fHe must not be greater than 1
|
||||||
if (get_o2(cyl.gasmix) + get_he(cyl.gasmix) > 1000)
|
if (get_o2(cyl.gasmix) + get_he(cyl.gasmix) > 1000)
|
||||||
cyl.gasmix.o2.permille = 1000 - get_he(cyl.gasmix);
|
cyl.gasmix.o2.permille = 1000 - get_he(cyl.gasmix);
|
||||||
|
|
Loading…
Add table
Reference in a new issue