diff --git a/Subsurface-mobile.pro b/Subsurface-mobile.pro index a2dadee57..95c64eced 100644 --- a/Subsurface-mobile.pro +++ b/Subsurface-mobile.pro @@ -57,7 +57,7 @@ SOURCES += subsurface-mobile-main.cpp \ core/filterpreset.cpp \ core/divelist.cpp \ core/divelog.cpp \ - core/gas-model.c \ + core/gas-model.cpp \ core/gaspressures.c \ core/git-access.cpp \ core/globals.cpp \ diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index 4d0a2c9b7..6b7aab7ab 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -101,7 +101,7 @@ set(SUBSURFACE_CORE_LIB_SRCS fulltext.h gas.c gas.h - gas-model.c + gas-model.cpp gaspressures.c gaspressures.h gettext.h diff --git a/core/gas-model.c b/core/gas-model.cpp similarity index 87% rename from core/gas-model.c rename to core/gas-model.cpp index 194c8a030..6c8bee1a6 100644 --- a/core/gas-model.c +++ b/core/gas-model.cpp @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 -/* gas-model.c */ +/* gas-model.cpp */ /* gas compressibility model */ +#include // std::clamp #include #include #include "dive.h" @@ -46,23 +47,20 @@ double gas_compressibility_factor(struct gasmix gas, double bar) -8.83632921053e-08, +5.33304543646e-11 }; - int o2, he; - double Z; /* * The curve fitting range is only [0,500] bar. * Anything else is way out of range for cylinder * pressures. */ - if (bar < 0) bar = 0; - if (bar > 500) bar = 500; + bar = std::clamp(bar, 0.0, 500.0); - o2 = get_o2(gas); - he = get_he(gas); + int o2 = get_o2(gas); + int he = get_he(gas); - Z = virial_m1(o2_coefficients, bar) * o2 + - virial_m1(he_coefficients, bar) * he + - virial_m1(n2_coefficients, bar) * (1000 - o2 - he); + double Z = virial_m1(o2_coefficients, bar) * o2 + + virial_m1(he_coefficients, bar) * he + + virial_m1(n2_coefficients, bar) * (1000 - o2 - he); /* * We add the 1.0 at the very end - the linear mixing of the