diff --git a/core/deco.cpp b/core/deco.cpp index 5536a9e2f..7460f12da 100644 --- a/core/deco.cpp +++ b/core/deco.cpp @@ -551,7 +551,7 @@ int deco_allowed_depth(double tissues_tolerance, double surface_pressure, const /* Avoid negative depths */ pressure_delta = tissues_tolerance > surface_pressure ? tissues_tolerance - surface_pressure : 0.0; - depth = rel_mbar_to_depth(lrint(pressure_delta * 1000), dive); + depth = dive->rel_mbar_to_depth(lrint(pressure_delta * 1000)); if (!smooth) depth = lrint(ceil(depth / DECO_STOPS_MULTIPLIER_MM) * DECO_STOPS_MULTIPLIER_MM); diff --git a/core/dive.cpp b/core/dive.cpp index d7d5c9f58..66cd6a696 100644 --- a/core/dive.cpp +++ b/core/dive.cpp @@ -2824,10 +2824,10 @@ double dive::depth_to_atm(int depth) const * (that's the one that some dive computers like the Uemis Zurich * provide - for the other models that do this libdivecomputer has to * take care of this, but the Uemis we support natively */ -int rel_mbar_to_depth(int mbar, const struct dive *dive) +int dive::rel_mbar_to_depth(int mbar) const { // For downloaded and planned dives, use DC's salinity. Manual dives, use user's salinity - int salinity = is_dc_manually_added_dive(&dive->dcs[0]) ? dive->user_salinity : dive->dcs[0].salinity; + int salinity = is_dc_manually_added_dive(&dcs[0]) ? user_salinity : dcs[0].salinity; if (!salinity) salinity = SEAWATER_SALINITY; @@ -2836,17 +2836,17 @@ int rel_mbar_to_depth(int mbar, const struct dive *dive) return (int)lrint(mbar / specific_weight); } -int mbar_to_depth(int mbar, const struct dive *dive) +int dive::mbar_to_depth(int mbar) const { // For downloaded and planned dives, use DC's pressure. Manual dives, use user's pressure - pressure_t surface_pressure = is_dc_manually_added_dive(&dive->dcs[0]) - ? dive->surface_pressure - : dive->dcs[0].surface_pressure; + pressure_t surface_pressure = is_dc_manually_added_dive(&dcs[0]) + ? this->surface_pressure + : dcs[0].surface_pressure; if (!surface_pressure.mbar) surface_pressure.mbar = SURFACE_PRESSURE; - return rel_mbar_to_depth(mbar - surface_pressure.mbar, dive); + return rel_mbar_to_depth(mbar - surface_pressure.mbar); } /* MOD rounded to multiples of roundto mm */ @@ -2854,7 +2854,7 @@ depth_t gas_mod(struct gasmix mix, pressure_t po2_limit, const struct dive *dive { depth_t rounded_depth; - double depth = (double) mbar_to_depth(po2_limit.mbar * 1000 / get_o2(mix), dive); + 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; } @@ -2874,7 +2874,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)mbar_to_depth(maxambient, dive)) / roundto) * roundto; + rounded_depth.mm = (int)lrint(((double)dive->mbar_to_depth(maxambient)) / roundto) * roundto; return rounded_depth; } diff --git a/core/dive.h b/core/dive.h index dbfda86e7..59d0db225 100644 --- a/core/dive.h +++ b/core/dive.h @@ -91,6 +91,8 @@ struct dive { double depth_to_mbarf(int depth) const; double depth_to_bar(int depth) const; double depth_to_atm(int depth) const; + int rel_mbar_to_depth(int mbar) const; + int mbar_to_depth(int mbar) const; }; /* For the top-level list: an entry is either a dive or a trip */ @@ -133,8 +135,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 int rel_mbar_to_depth(int mbar, const struct dive *dive); -extern int mbar_to_depth(int mbar, const struct dive *dive); 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); diff --git a/core/profile.cpp b/core/profile.cpp index bbf4698f2..a1f8bd5d5 100644 --- a/core/profile.cpp +++ b/core/profile.cpp @@ -1159,13 +1159,13 @@ static void calculate_gas_information_new(const struct dive *dive, const struct * 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.end = mbar_to_depth(lrint(dive->depth_to_mbarf(entry.depth) * (1000 - fhe) / 1000.0), dive); - entry.ead = mbar_to_depth(lrint(dive->depth_to_mbarf(entry.depth) * fn2 / (double)N2_IN_AIR), dive); - entry.eadd = mbar_to_depth(lrint(dive->depth_to_mbarf(entry.depth) * + 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) * (entry.pressures.o2 / amb_pressure * O2_DENSITY + entry.pressures.n2 / amb_pressure * N2_DENSITY + entry.pressures.he / amb_pressure * HE_DENSITY) / - (O2_IN_AIR * O2_DENSITY + N2_IN_AIR * N2_DENSITY) * 1000), dive); + (O2_IN_AIR * O2_DENSITY + N2_IN_AIR * N2_DENSITY) * 1000)); entry.density = gas_density(entry.pressures); if (entry.mod < 0) entry.mod = 0; diff --git a/core/uemis.cpp b/core/uemis.cpp index 0f65d71f6..271fda0a7 100644 --- a/core/uemis.cpp +++ b/core/uemis.cpp @@ -248,7 +248,7 @@ void uemis::event(struct dive *dive, struct divecomputer *dc, struct sample *sam * flags[3].bit0 | flags[5].bit1 != 0 ==> in deco * flags[0].bit7 == 1 ==> Safety Stop * otherwise NDL */ - stopdepth = rel_mbar_to_depth(u_sample->hold_depth, dive); + stopdepth = dive->rel_mbar_to_depth(u_sample->hold_depth); if ((flags[3] & 1) | (flags[5] & 2)) { /* deco */ sample->in_deco = true; @@ -344,7 +344,7 @@ void uemis::parse_divelog_binary(std::string_view base64, struct dive *dive) } sample = prepare_sample(dc); sample->time.seconds = u_sample->dive_time; - sample->depth.mm = rel_mbar_to_depth(u_sample->water_pressure, dive); + sample->depth.mm = dive->rel_mbar_to_depth(u_sample->water_pressure); sample->temperature.mkelvin = C_to_mkelvin(u_sample->dive_temperature / 10.0); add_sample_pressure(sample, active, (u_sample->tank_pressure_high * 256 + u_sample->tank_pressure_low) * 10); sample->cns = u_sample->cns; diff --git a/tests/testplan.cpp b/tests/testplan.cpp index acf7c5d7d..87b5804e3 100644 --- a/tests/testplan.cpp +++ b/tests/testplan.cpp @@ -575,7 +575,7 @@ void TestPlan::testVpmbMetric45m30minTx() dp = dp->next; QCOMPARE(lrint(dp->minimum_gas.mbar / 1000.0), 108l); // print first ceiling - printf("First ceiling %.1f m\n", (mbar_to_depth(test_deco_state.first_ceiling_pressure.mbar, &dive) * 0.001)); + printf("First ceiling %.1f m\n", dive.mbar_to_depth(test_deco_state.first_ceiling_pressure.mbar) * 0.001); // check benchmark run time of 141 minutes, and known Subsurface runtime of 139 minutes //QVERIFY(compareDecoTime(dive.dcs[0].duration.seconds, 141u * 60u + 20u, 139u * 60u + 20u)); } @@ -604,7 +604,7 @@ void TestPlan::testVpmbMetric60m10minTx() dp = dp->next; QCOMPARE(lrint(dp->minimum_gas.mbar / 1000.0), 162l); // print first ceiling - printf("First ceiling %.1f m\n", (mbar_to_depth(test_deco_state.first_ceiling_pressure.mbar, &dive) * 0.001)); + printf("First ceiling %.1f m\n", dive.mbar_to_depth(test_deco_state.first_ceiling_pressure.mbar) * 0.001); // check benchmark run time of 141 minutes, and known Subsurface runtime of 139 minutes //QVERIFY(compareDecoTime(dive.dcs[0].duration.seconds, 141u * 60u + 20u, 139u * 60u + 20u)); } @@ -633,7 +633,7 @@ void TestPlan::testVpmbMetric60m30minAir() dp = dp->next; QCOMPARE(lrint(dp->minimum_gas.mbar / 1000.0), 180l); // print first ceiling - printf("First ceiling %.1f m\n", (mbar_to_depth(test_deco_state.first_ceiling_pressure.mbar, &dive) * 0.001)); + printf("First ceiling %.1f m\n", dive.mbar_to_depth(test_deco_state.first_ceiling_pressure.mbar) * 0.001); // check benchmark run time of 141 minutes, and known Subsurface runtime of 139 minutes QVERIFY(compareDecoTime(dive.dcs[0].duration.seconds, 141u * 60u + 20u, 139u * 60u + 20u)); } @@ -662,7 +662,7 @@ void TestPlan::testVpmbMetric60m30minEan50() dp = dp->next; QCOMPARE(lrint(dp->minimum_gas.mbar / 1000.0), 155l); // print first ceiling - printf("First ceiling %.1f m\n", (mbar_to_depth(test_deco_state.first_ceiling_pressure.mbar, &dive) * 0.001)); + printf("First ceiling %.1f m\n", dive.mbar_to_depth(test_deco_state.first_ceiling_pressure.mbar) * 0.001); QVERIFY(dive.dcs[0].events.size() >= 1); // check first gas change to EAN50 at 21m struct event *ev = &dive.dcs[0].events[0]; @@ -697,7 +697,7 @@ void TestPlan::testVpmbMetric60m30minTx() dp = dp->next; QCOMPARE(lrint(dp->minimum_gas.mbar / 1000.0), 159l); // print first ceiling - printf("First ceiling %.1f m\n", (mbar_to_depth(test_deco_state.first_ceiling_pressure.mbar, &dive) * 0.001)); + printf("First ceiling %.1f m\n", dive.mbar_to_depth(test_deco_state.first_ceiling_pressure.mbar) * 0.001); // check first gas change to EAN50 at 21m QVERIFY(dive.dcs[0].events.size() >= 1); struct event *ev = &dive.dcs[0].events[0]; @@ -732,7 +732,7 @@ void TestPlan::testVpmbMetric100m60min() dp = dp->next; QCOMPARE(lrint(dp->minimum_gas.mbar / 1000.0), 157l); // print first ceiling - printf("First ceiling %.1f m\n", (mbar_to_depth(test_deco_state.first_ceiling_pressure.mbar, &dive) * 0.001)); + printf("First ceiling %.1f m\n", dive.mbar_to_depth(test_deco_state.first_ceiling_pressure.mbar) * 0.001); QVERIFY(dive.dcs[0].events.size() >= 2); // check first gas change to EAN50 at 21m struct event *ev = &dive.dcs[0].events[0]; @@ -798,7 +798,7 @@ void TestPlan::testVpmbMetricMultiLevelAir() dp = dp->next; QCOMPARE(lrint(dp->minimum_gas.mbar / 1000.0), 101l); // print first ceiling - printf("First ceiling %.1f m\n", (mbar_to_depth(test_deco_state.first_ceiling_pressure.mbar, &dive) * 0.001)); + printf("First ceiling %.1f m\n", dive.mbar_to_depth(test_deco_state.first_ceiling_pressure.mbar) * 0.001); // check benchmark run time of 167 minutes, and known Subsurface runtime of 169 minutes QVERIFY(compareDecoTime(dive.dcs[0].duration.seconds, 167u * 60u + 20u, 169u * 60u + 20u)); } @@ -827,7 +827,7 @@ void TestPlan::testVpmbMetric100m10min() dp = dp->next; QCOMPARE(lrint(dp->minimum_gas.mbar / 1000.0), 175l); // print first ceiling - printf("First ceiling %.1f m\n", (mbar_to_depth(test_deco_state.first_ceiling_pressure.mbar, &dive) * 0.001)); + printf("First ceiling %.1f m\n", dive.mbar_to_depth(test_deco_state.first_ceiling_pressure.mbar) * 0.001); QVERIFY(dive.dcs[0].events.size() >= 2); // check first gas change to EAN50 at 21m struct event *ev = &dive.dcs[0].events[0]; @@ -873,7 +873,7 @@ void TestPlan::testVpmbMetricRepeat() dp = dp->next; QCOMPARE(lrint(dp->minimum_gas.mbar / 1000.0), 61l); // print first ceiling - printf("First ceiling %.1f m\n", (mbar_to_depth(test_deco_state.first_ceiling_pressure.mbar, &dive) * 0.001)); + printf("First ceiling %.1f m\n", dive.mbar_to_depth(test_deco_state.first_ceiling_pressure.mbar) * 0.001); // check benchmark run time of 27 minutes, and known Subsurface runtime of 28 minutes QVERIFY(compareDecoTime(dive.dcs[0].duration.seconds, 27u * 60u + 20u, 27u * 60u + 20u)); @@ -893,7 +893,7 @@ void TestPlan::testVpmbMetricRepeat() dp = dp->next; QCOMPARE(lrint(dp->minimum_gas.mbar / 1000.0), 80l); // print first ceiling - printf("First ceiling %.1f m\n", (mbar_to_depth(test_deco_state.first_ceiling_pressure.mbar, &dive) * 0.001)); + printf("First ceiling %.1f m\n", dive.mbar_to_depth(test_deco_state.first_ceiling_pressure.mbar) * 0.001); QVERIFY(dive.dcs[0].events.size() >= 3); // check first gas change to 21/35 at 66m struct event *ev = &dive.dcs[0].events[0]; @@ -930,7 +930,7 @@ void TestPlan::testVpmbMetricRepeat() dp = dp->next; QCOMPARE(lrint(dp->minimum_gas.mbar / 1000.0), 61l); // print first ceiling - printf("First ceiling %.1f m\n", (mbar_to_depth(test_deco_state.first_ceiling_pressure.mbar, &dive) * 0.001)); + printf("First ceiling %.1f m\n", dive.mbar_to_depth(test_deco_state.first_ceiling_pressure.mbar) * 0.001); // check runtime is exactly the same as the first time int finalDiveRunTimeSeconds = dive.dcs[0].duration.seconds;