mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Don't access gasmix.o2.fraction
Air is a special gas that does not contain oxygen according to gasmix.o2.fraction. If you want to use the fo2, you need to use get_o2() to treat this special case correctly. This fixes a bug when setting the MND of a gas containing 21% oxygen when o2 is considered not narcotic. Reported-by: Christoph Gruen <gruen.christoph@gmail.com> Signed-off-by: Robert C. Helling <helling@atdotde.de>
This commit is contained in:
parent
5e9ee9febb
commit
41258647d2
8 changed files with 9280 additions and 9276 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
planner: fix a bug setting the MND for gasmix with 21% oxygen
|
||||||
mobile: remove support for acquiring fine grain location / GPS
|
mobile: remove support for acquiring fine grain location / GPS
|
||||||
mobile: Add support for rich text when displaying dive notes
|
mobile: Add support for rich text when displaying dive notes
|
||||||
core: fix off-by-one causing incorrect profile display #3184
|
core: fix off-by-one causing incorrect profile display #3184
|
||||||
|
|
|
@ -86,7 +86,9 @@ double isothermal_pressure(struct gasmix gas, double p1, int volume1, int volume
|
||||||
|
|
||||||
double gas_density(struct gasmix gas, int pressure)
|
double gas_density(struct gasmix gas, int pressure)
|
||||||
{
|
{
|
||||||
int density = gas.he.permille * HE_DENSITY + gas.o2.permille * O2_DENSITY + (1000 - gas.he.permille - gas.o2.permille) * N2_DENSITY;
|
int fo2 = get_o2(gas);
|
||||||
|
int fhe = get_he(gas);
|
||||||
|
int density = fhe * HE_DENSITY + fo2 * O2_DENSITY + (1000 - fhe - fo2) * N2_DENSITY;
|
||||||
|
|
||||||
return density * (double) pressure / gas_compressibility_factor(gas, pressure / 1000.0) / SURFACE_PRESSURE / 1000000.0;
|
return density * (double) pressure / gas_compressibility_factor(gas, pressure / 1000.0) / SURFACE_PRESSURE / 1000000.0;
|
||||||
}
|
}
|
||||||
|
|
22
core/gas.c
22
core/gas.c
|
@ -33,15 +33,15 @@ int same_gasmix(struct gasmix a, struct gasmix b)
|
||||||
return 0;
|
return 0;
|
||||||
if (gasmix_is_air(a) && gasmix_is_air(b))
|
if (gasmix_is_air(a) && gasmix_is_air(b))
|
||||||
return 1;
|
return 1;
|
||||||
return a.o2.permille == b.o2.permille && a.he.permille == b.he.permille;
|
return get_o2(a) == get_o2(b) && get_he(a) == get_he(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sanitize_gasmix(struct gasmix *mix)
|
void sanitize_gasmix(struct gasmix *mix)
|
||||||
{
|
{
|
||||||
unsigned int o2, he;
|
unsigned int o2, he;
|
||||||
|
|
||||||
o2 = mix->o2.permille;
|
o2 = get_o2(*mix);
|
||||||
he = mix->he.permille;
|
he = get_he(*mix);
|
||||||
|
|
||||||
/* Regular air: leave empty */
|
/* Regular air: leave empty */
|
||||||
if (!he) {
|
if (!he) {
|
||||||
|
@ -74,12 +74,12 @@ int gasmix_distance(struct gasmix a, struct gasmix b)
|
||||||
|
|
||||||
bool gasmix_is_air(struct gasmix gasmix)
|
bool gasmix_is_air(struct gasmix gasmix)
|
||||||
{
|
{
|
||||||
int o2 = gasmix.o2.permille;
|
int o2 = get_o2(gasmix);
|
||||||
int he = gasmix.he.permille;
|
int he = get_he(gasmix);
|
||||||
return (he == 0) && (o2 == 0 || ((o2 >= O2_IN_AIR - 1) && (o2 <= O2_IN_AIR + 1)));
|
return (he == 0) && (o2 == 0 || ((o2 >= O2_IN_AIR - 1) && (o2 <= O2_IN_AIR + 1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
static fraction_t make_fraction(int i)
|
fraction_t make_fraction(int i)
|
||||||
{
|
{
|
||||||
fraction_t res;
|
fraction_t res;
|
||||||
res.permille = i;
|
res.permille = i;
|
||||||
|
@ -152,13 +152,13 @@ enum gastype gasmix_to_type(struct gasmix mix)
|
||||||
{
|
{
|
||||||
if (gasmix_is_air(mix))
|
if (gasmix_is_air(mix))
|
||||||
return GASTYPE_AIR;
|
return GASTYPE_AIR;
|
||||||
if (mix.o2.permille >= 980)
|
if (get_o2(mix) >= 980)
|
||||||
return GASTYPE_OXYGEN;
|
return GASTYPE_OXYGEN;
|
||||||
if (mix.he.permille == 0)
|
if (get_he(mix) == 0)
|
||||||
return mix.o2.permille >= 230 ? GASTYPE_NITROX : GASTYPE_AIR;
|
return get_o2(mix) >= 230 ? GASTYPE_NITROX : GASTYPE_AIR;
|
||||||
if (mix.o2.permille <= 180)
|
if (get_o2(mix) <= 180)
|
||||||
return GASTYPE_HYPOXIC_TRIMIX;
|
return GASTYPE_HYPOXIC_TRIMIX;
|
||||||
return mix.o2.permille <= 230 ? GASTYPE_NORMOXIC_TRIMIX : GASTYPE_HYPEROXIC_TRIMIX;
|
return get_o2(mix) <= 230 ? GASTYPE_NORMOXIC_TRIMIX : GASTYPE_HYPEROXIC_TRIMIX;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *gastype_names[] = {
|
static const char *gastype_names[] = {
|
||||||
|
|
|
@ -44,12 +44,12 @@ extern double isothermal_pressure(struct gasmix gas, double p1, int volume1, int
|
||||||
extern double gas_density(struct gasmix gas, int pressure);
|
extern double gas_density(struct gasmix gas, int pressure);
|
||||||
extern int same_gasmix(struct gasmix a, struct gasmix b);
|
extern int same_gasmix(struct gasmix a, struct gasmix b);
|
||||||
|
|
||||||
static inline int get_o2(struct gasmix mix)
|
static inline int get_o2(const struct gasmix mix)
|
||||||
{
|
{
|
||||||
return mix.o2.permille ?: O2_IN_AIR;
|
return mix.o2.permille ?: O2_IN_AIR;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int get_he(struct gasmix mix)
|
static inline int get_he(const struct gasmix mix)
|
||||||
{
|
{
|
||||||
return mix.he.permille;
|
return mix.he.permille;
|
||||||
}
|
}
|
||||||
|
@ -74,6 +74,7 @@ extern bool gasmix_is_air(struct gasmix gasmix);
|
||||||
extern bool gasmix_is_invalid(struct gasmix mix);
|
extern bool gasmix_is_invalid(struct gasmix mix);
|
||||||
extern enum gastype gasmix_to_type(struct gasmix mix);
|
extern enum gastype gasmix_to_type(struct gasmix mix);
|
||||||
extern const char *gastype_name(enum gastype type);
|
extern const char *gastype_name(enum gastype type);
|
||||||
|
extern fraction_t make_fraction(int f);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -445,11 +445,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, cyl.gasmix.o2);
|
cyl.gasmix.he = best_he(d->maxdepth, d, 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, cyl.gasmix.o2);
|
cyl.gasmix.he = best_he(string_to_depth(qPrintable(vString)), d, prefs.o2narcotic, make_fraction(get_o2(cyl.gasmix)));
|
||||||
}
|
}
|
||||||
type = Command::EditCylinderType::GASMIX;
|
type = Command::EditCylinderType::GASMIX;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -1499,12 +1499,12 @@ struct gas_bin_t bin_gasmix(struct gasmix mix, int size)
|
||||||
{
|
{
|
||||||
if (gasmix_is_air(mix))
|
if (gasmix_is_air(mix))
|
||||||
return gas_bin_t::air();
|
return gas_bin_t::air();
|
||||||
if (mix.o2.permille == 1000)
|
if (get_o2(mix) == 1000)
|
||||||
return gas_bin_t::oxygen();
|
return gas_bin_t::oxygen();
|
||||||
return mix.he.permille == 0 ?
|
return get_he(mix) == 0 ?
|
||||||
gas_bin_t::ean(mix.o2.permille / 10 / size * size) :
|
gas_bin_t::ean(get_o2(mix) / 10 / size * size) :
|
||||||
gas_bin_t::trimix(mix.o2.permille / 10 / size * size,
|
gas_bin_t::trimix(get_o2(mix) / 10 / size * size,
|
||||||
mix.he.permille / 10 / size * size);
|
get_he(mix) / 10 / size * size);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct GasTypeBinner : public MultiBinner<GasTypeBinner, GasTypeBin> {
|
struct GasTypeBinner : public MultiBinner<GasTypeBinner, GasTypeBin> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue