core: convert gas-model.c to C++

A nice one - nothing to do. Introduce an std::clamp(), just
because we can...

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2024-05-02 22:42:09 +02:00
parent 17b23ddb69
commit 14d60a7245
3 changed files with 10 additions and 12 deletions

View file

@ -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 \

View file

@ -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

View file

@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-2.0
/* gas-model.c */
/* gas-model.cpp */
/* gas compressibility model */
#include <algorithm> // std::clamp
#include <stdio.h>
#include <stdlib.h>
#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