mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
core: introduce a few user-defined literals for unit types
Thise makes initialization of unit types more palatable. For example: surface.time = sample.time - duration_t { .seconds = 20 }; => surface.time = sample.time - 20_sec; delta_depth.mm = feet_to_mm(1.0); // 1ft => delta_depth = 1_ft; get_cylinderid_at_time(..., { .seconds = 20 * 60 + 1 })); => get_cylinderid_at_time(..., 20_min + 1_sec)); Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
f09601bc93
commit
ae81b42fe2
36 changed files with 320 additions and 264 deletions
|
@ -47,10 +47,10 @@ diveplan setupPlan()
|
|||
dp.bottomsac = prefs.bottomsac;
|
||||
dp.decosac = prefs.decosac;
|
||||
|
||||
struct gasmix bottomgas = {{.permille = 150}, {.permille = 450}};
|
||||
struct gasmix ean36 = {{.permille = 360}, {}};
|
||||
struct gasmix oxygen = {{.permille = 1000}, {}};
|
||||
pressure_t po2 = {.mbar = 1600};
|
||||
struct gasmix bottomgas = { 15_percent, 45_percent};
|
||||
struct gasmix ean36 = { 36_percent, 0_percent};
|
||||
struct gasmix oxygen = { 100_percent, 0_percent};
|
||||
pressure_t po2 = 1600_mbar;;
|
||||
// Note: we add the highest-index cylinder first, because
|
||||
// pointers to cylinders are not stable when reallocating.
|
||||
// For testing OK - don't do this in actual code!
|
||||
|
@ -58,8 +58,8 @@ diveplan setupPlan()
|
|||
cylinder_t *cyl0 = dive.get_or_create_cylinder(0);
|
||||
cylinder_t *cyl1 = dive.get_or_create_cylinder(1);
|
||||
cyl0->gasmix = bottomgas;
|
||||
cyl0->type.size.mliter = 36000;
|
||||
cyl0->type.workingpressure.mbar = 232000;
|
||||
cyl0->type.size = 36_l;
|
||||
cyl0->type.workingpressure = 232_bar;
|
||||
cyl1->gasmix = ean36;
|
||||
cyl2->gasmix = oxygen;
|
||||
reset_cylinders(&dive, true);
|
||||
|
@ -82,10 +82,10 @@ diveplan setupPlanVpmb45m30mTx()
|
|||
dp.bottomsac = prefs.bottomsac;
|
||||
dp.decosac = prefs.decosac;
|
||||
|
||||
struct gasmix bottomgas = {{.permille = 210}, {.permille = 350}};
|
||||
struct gasmix ean50 = {{.permille = 500}, {}};
|
||||
struct gasmix oxygen = {{.permille = 1000}, {}};
|
||||
pressure_t po2 = {.mbar = 1600};
|
||||
struct gasmix bottomgas = { 21_percent, 35_percent};
|
||||
struct gasmix ean50 = { 50_percent, 0_percent};
|
||||
struct gasmix oxygen = { 100_percent, 0_percent};
|
||||
pressure_t po2 = 1600_mbar;
|
||||
// Note: we add the highest-index cylinder first, because
|
||||
// pointers to cylinders are not stable when reallocating.
|
||||
// For testing OK - don't do this in actual code!
|
||||
|
@ -93,8 +93,8 @@ diveplan setupPlanVpmb45m30mTx()
|
|||
cylinder_t *cyl0 = dive.get_or_create_cylinder(0);
|
||||
cylinder_t *cyl1 = dive.get_or_create_cylinder(1);
|
||||
cyl0->gasmix = bottomgas;
|
||||
cyl0->type.size.mliter = 24000;
|
||||
cyl0->type.workingpressure.mbar = 232000;
|
||||
cyl0->type.size = 24_l;
|
||||
cyl0->type.workingpressure = 232_bar;
|
||||
cyl1->gasmix = ean50;
|
||||
cyl2->gasmix = oxygen;
|
||||
reset_cylinders(&dive, true);
|
||||
|
@ -117,10 +117,10 @@ diveplan setupPlanVpmb60m10mTx()
|
|||
dp.bottomsac = prefs.bottomsac;
|
||||
dp.decosac = prefs.decosac;
|
||||
|
||||
struct gasmix bottomgas = {{.permille = 180}, {.permille = 450}};
|
||||
struct gasmix tx50_15 = {{.permille = 500}, {.permille = 150}};
|
||||
struct gasmix oxygen = {{.permille = 1000}, {}};
|
||||
pressure_t po2 = {.mbar = 1600};
|
||||
struct gasmix bottomgas = { 18_percent, 45_percent };
|
||||
struct gasmix tx50_15 = { 50_percent, 15_percent };
|
||||
struct gasmix oxygen = { 100_percent, 0_percent };
|
||||
pressure_t po2 = 1600_mbar;
|
||||
// Note: we add the highest-index cylinder first, because
|
||||
// pointers to cylinders are not stable when reallocating.
|
||||
// For testing OK - don't do this in actual code!
|
||||
|
@ -128,8 +128,8 @@ diveplan setupPlanVpmb60m10mTx()
|
|||
cylinder_t *cyl0 = dive.get_or_create_cylinder(0);
|
||||
cylinder_t *cyl1 = dive.get_or_create_cylinder(1);
|
||||
cyl0->gasmix = bottomgas;
|
||||
cyl0->type.size.mliter = 24000;
|
||||
cyl0->type.workingpressure.mbar = 232000;
|
||||
cyl0->type.size = 24_l;
|
||||
cyl0->type.workingpressure = 232_bar;
|
||||
cyl1->gasmix = tx50_15;
|
||||
cyl2->gasmix = oxygen;
|
||||
reset_cylinders(&dive, true);
|
||||
|
@ -150,12 +150,12 @@ diveplan setupPlanVpmb60m30minAir()
|
|||
dp.bottomsac = prefs.bottomsac;
|
||||
dp.decosac = prefs.decosac;
|
||||
|
||||
struct gasmix bottomgas = {{.permille = 210}, {}};
|
||||
struct gasmix bottomgas = { 21_percent, 0_percent};
|
||||
cylinder_t *cyl0 = dive.get_or_create_cylinder(0);
|
||||
cyl0->gasmix = bottomgas;
|
||||
cyl0->type.size.mliter = 100000;
|
||||
cyl0->type.workingpressure.mbar = 232000;
|
||||
dive.surface_pressure.mbar = 1013;
|
||||
cyl0->type.size = 100_l;
|
||||
cyl0->type.workingpressure = 232_bar;
|
||||
dive.surface_pressure = 1_atm;
|
||||
reset_cylinders(&dive, true);
|
||||
|
||||
int droptime = M_OR_FT(60, 200) * 60 / M_OR_FT(99, 330);
|
||||
|
@ -172,19 +172,19 @@ diveplan setupPlanVpmb60m30minEan50()
|
|||
dp.bottomsac = prefs.bottomsac;
|
||||
dp.decosac = prefs.decosac;
|
||||
|
||||
struct gasmix bottomgas = {{.permille = 210}, {}};
|
||||
struct gasmix ean50 = {{.permille = 500}, {}};
|
||||
pressure_t po2 = {.mbar = 1600};
|
||||
struct gasmix bottomgas = { 21_percent, 0_percent };
|
||||
struct gasmix ean50 = { 50_percent, 0_percent };
|
||||
pressure_t po2 = 1600_mbar;
|
||||
// Note: we add the highest-index cylinder first, because
|
||||
// pointers to cylinders are not stable when reallocating.
|
||||
// For testing OK - don't do this in actual code!
|
||||
cylinder_t *cyl1 = dive.get_or_create_cylinder(1);
|
||||
cylinder_t *cyl0 = dive.get_or_create_cylinder(0);
|
||||
cyl0->gasmix = bottomgas;
|
||||
cyl0->type.size.mliter = 36000;
|
||||
cyl0->type.workingpressure.mbar = 232000;
|
||||
cyl0->type.size = 36_l;
|
||||
cyl0->type.workingpressure = 232_bar;
|
||||
cyl1->gasmix = ean50;
|
||||
dive.surface_pressure.mbar = 1013;
|
||||
dive.surface_pressure = 1_atm;
|
||||
reset_cylinders(&dive, true);
|
||||
|
||||
int droptime = M_OR_FT(60, 200) * 60 / M_OR_FT(99, 330);
|
||||
|
@ -202,19 +202,19 @@ diveplan setupPlanVpmb60m30minTx()
|
|||
dp.bottomsac = prefs.bottomsac;
|
||||
dp.decosac = prefs.decosac;
|
||||
|
||||
struct gasmix bottomgas = {{.permille = 180}, {.permille = 450}};
|
||||
struct gasmix ean50 = {{.permille = 500}, {}};
|
||||
pressure_t po2 = {.mbar = 1600};
|
||||
struct gasmix bottomgas = { 18_percent, 45_percent };
|
||||
struct gasmix ean50 = { 50_percent, 0_percent };
|
||||
pressure_t po2 = 1600_mbar;
|
||||
// Note: we add the highest-index cylinder first, because
|
||||
// pointers to cylinders are not stable when reallocating.
|
||||
// For testing OK - don't do this in actual code!
|
||||
cylinder_t *cyl1 = dive.get_or_create_cylinder(1);
|
||||
cylinder_t *cyl0 = dive.get_or_create_cylinder(0);
|
||||
cyl0->gasmix = bottomgas;
|
||||
cyl0->type.size.mliter = 36000;
|
||||
cyl0->type.workingpressure.mbar = 232000;
|
||||
cyl0->type.size = 36_l;
|
||||
cyl0->type.workingpressure = 232_bar;
|
||||
cyl1->gasmix = ean50;
|
||||
dive.surface_pressure.mbar = 1013;
|
||||
dive.surface_pressure = 1_atm;
|
||||
reset_cylinders(&dive, true);
|
||||
|
||||
int droptime = M_OR_FT(60, 200) * 60 / M_OR_FT(99, 330);
|
||||
|
@ -232,12 +232,12 @@ diveplan setupPlanVpmbMultiLevelAir()
|
|||
dp.bottomsac = prefs.bottomsac;
|
||||
dp.decosac = prefs.decosac;
|
||||
|
||||
struct gasmix bottomgas = {{.permille = 210}, {}};
|
||||
struct gasmix bottomgas = { 21_percent, 0_percent };
|
||||
cylinder_t *cyl0 = dive.get_or_create_cylinder(0);
|
||||
cyl0->gasmix = bottomgas;
|
||||
cyl0->type.size.mliter = 200000;
|
||||
cyl0->type.workingpressure.mbar = 232000;
|
||||
dive.surface_pressure.mbar = 1013;
|
||||
cyl0->type.size = 200_l;
|
||||
cyl0->type.workingpressure = 232_bar;
|
||||
dive.surface_pressure = 1_atm;
|
||||
reset_cylinders(&dive, true);
|
||||
|
||||
int droptime = M_OR_FT(20, 66) * 60 / M_OR_FT(99, 330);
|
||||
|
@ -256,10 +256,10 @@ diveplan setupPlanVpmb100m60min()
|
|||
dp.bottomsac = prefs.bottomsac;
|
||||
dp.decosac = prefs.decosac;
|
||||
|
||||
struct gasmix bottomgas = {{.permille = 180}, {.permille = 450}};
|
||||
struct gasmix ean50 = {{.permille = 500}, {}};
|
||||
struct gasmix oxygen = {{.permille = 1000}, {}};
|
||||
pressure_t po2 = {.mbar = 1600};
|
||||
struct gasmix bottomgas = { 18_percent, 45_percent };
|
||||
struct gasmix ean50 = { 50_percent, 0_percent };
|
||||
struct gasmix oxygen = { 100_percent, 0_percent };
|
||||
pressure_t po2 = 1600_mbar;
|
||||
// Note: we add the highest-index cylinder first, because
|
||||
// pointers to cylinders are not stable when reallocating.
|
||||
// For testing OK - don't do this in actual code!
|
||||
|
@ -267,11 +267,11 @@ diveplan setupPlanVpmb100m60min()
|
|||
cylinder_t *cyl0 = dive.get_or_create_cylinder(0);
|
||||
cylinder_t *cyl1 = dive.get_or_create_cylinder(1);
|
||||
cyl0->gasmix = bottomgas;
|
||||
cyl0->type.size.mliter = 200000;
|
||||
cyl0->type.workingpressure.mbar = 232000;
|
||||
cyl0->type.size = 200_l;
|
||||
cyl0->type.workingpressure = 232_bar;
|
||||
cyl1->gasmix = ean50;
|
||||
cyl2->gasmix = oxygen;
|
||||
dive.surface_pressure.mbar = 1013;
|
||||
dive.surface_pressure = 1_atm;
|
||||
reset_cylinders(&dive, true);
|
||||
|
||||
int droptime = M_OR_FT(100, 330) * 60 / M_OR_FT(99, 330);
|
||||
|
@ -290,10 +290,10 @@ diveplan setupPlanVpmb100m10min()
|
|||
dp.bottomsac = prefs.bottomsac;
|
||||
dp.decosac = prefs.decosac;
|
||||
|
||||
struct gasmix bottomgas = {{.permille = 180}, {.permille = 450}};
|
||||
struct gasmix ean50 = {{.permille = 500}, {}};
|
||||
struct gasmix oxygen = {{.permille = 1000}, {}};
|
||||
pressure_t po2 = {.mbar = 1600};
|
||||
struct gasmix bottomgas = { 18_percent, 45_percent };
|
||||
struct gasmix ean50 = { 50_percent, 0_percent};
|
||||
struct gasmix oxygen = { 100_percent, 0_percent};
|
||||
pressure_t po2 = 1600_mbar;
|
||||
// Note: we add the highest-index cylinder first, because
|
||||
// pointers to cylinders are not stable when reallocating.
|
||||
// For testing OK - don't do this in actual code!
|
||||
|
@ -301,11 +301,11 @@ diveplan setupPlanVpmb100m10min()
|
|||
cylinder_t *cyl0 = dive.get_or_create_cylinder(0);
|
||||
cylinder_t *cyl1 = dive.get_or_create_cylinder(1);
|
||||
cyl0->gasmix = bottomgas;
|
||||
cyl0->type.size.mliter = 60000;
|
||||
cyl0->type.workingpressure.mbar = 232000;
|
||||
cyl0->type.size = 60_l;
|
||||
cyl0->type.workingpressure = 232_bar;
|
||||
cyl1->gasmix = ean50;
|
||||
cyl2->gasmix = oxygen;
|
||||
dive.surface_pressure.mbar = 1013;
|
||||
dive.surface_pressure = 1_atm;
|
||||
reset_cylinders(&dive, true);
|
||||
|
||||
int droptime = M_OR_FT(100, 330) * 60 / M_OR_FT(99, 330);
|
||||
|
@ -324,12 +324,12 @@ diveplan setupPlanVpmb30m20min()
|
|||
dp.bottomsac = prefs.bottomsac;
|
||||
dp.decosac = prefs.decosac;
|
||||
|
||||
struct gasmix bottomgas = {{.permille = 210}, {}};
|
||||
struct gasmix bottomgas = { 21_percent, 0_percent };
|
||||
cylinder_t *cyl0 = dive.get_or_create_cylinder(0);
|
||||
cyl0->gasmix = bottomgas;
|
||||
cyl0->type.size.mliter = 36000;
|
||||
cyl0->type.workingpressure.mbar = 232000;
|
||||
dive.surface_pressure.mbar = 1013;
|
||||
cyl0->type.size = 36_l;
|
||||
cyl0->type.workingpressure = 232_bar;
|
||||
dive.surface_pressure = 1_atm;
|
||||
reset_cylinders(&dive, true);
|
||||
|
||||
int droptime = M_OR_FT(30, 100) * 60 / M_OR_FT(18, 60);
|
||||
|
@ -346,11 +346,11 @@ diveplan setupPlanVpmb100mTo70m30min()
|
|||
dp.bottomsac = prefs.bottomsac;
|
||||
dp.decosac = prefs.decosac;
|
||||
|
||||
struct gasmix bottomgas = {{.permille = 120}, {.permille = 650}};
|
||||
struct gasmix tx21_35 = {{.permille = 210}, {.permille = 350}};
|
||||
struct gasmix ean50 = {{.permille = 500}, {}};
|
||||
struct gasmix oxygen = {{.permille = 1000}, {}};
|
||||
pressure_t po2 = {.mbar = 1600};
|
||||
struct gasmix bottomgas = { 12_percent, 65_percent };
|
||||
struct gasmix tx21_35 = { 21_percent, 35_percent };
|
||||
struct gasmix ean50 = { 50_percent, 0_percent };
|
||||
struct gasmix oxygen = { 100_percent, 0_percent };
|
||||
pressure_t po2 = 1600_mbar;
|
||||
// Note: we add the highest-index cylinder first, because
|
||||
// pointers to cylinders are not stable when reallocating.
|
||||
// For testing OK - don't do this in actual code!
|
||||
|
@ -359,12 +359,12 @@ diveplan setupPlanVpmb100mTo70m30min()
|
|||
cylinder_t *cyl1 = dive.get_or_create_cylinder(1);
|
||||
cylinder_t *cyl2 = dive.get_or_create_cylinder(2);
|
||||
cyl0->gasmix = bottomgas;
|
||||
cyl0->type.size.mliter = 36000;
|
||||
cyl0->type.workingpressure.mbar = 232000;
|
||||
cyl0->type.size = 36_l;
|
||||
cyl0->type.workingpressure = 232_bar;
|
||||
cyl1->gasmix = tx21_35;
|
||||
cyl2->gasmix = ean50;
|
||||
cyl3->gasmix = oxygen;
|
||||
dive.surface_pressure.mbar = 1013;
|
||||
dive.surface_pressure = 1_atm;
|
||||
reset_cylinders(&dive, true);
|
||||
|
||||
int droptime = M_OR_FT(100, 330) * 60 / M_OR_FT(18, 60);
|
||||
|
@ -388,8 +388,8 @@ diveplan setupPlanSeveralGases()
|
|||
dp.bottomsac = prefs.bottomsac;
|
||||
dp.decosac = prefs.decosac;
|
||||
|
||||
struct gasmix ean36 = {{.permille = 360}, {}};
|
||||
struct gasmix tx11_50 = {{.permille = 110}, {.permille = 500}};
|
||||
struct gasmix ean36 = { 36_percent, 0_percent };
|
||||
struct gasmix tx11_50 = { 11_percent, 50_percent };
|
||||
|
||||
// Note: we add the highest-index cylinder first, because
|
||||
// pointers to cylinders are not stable when reallocating.
|
||||
|
@ -397,10 +397,10 @@ diveplan setupPlanSeveralGases()
|
|||
cylinder_t *cyl1 = dive.get_or_create_cylinder(1);
|
||||
cylinder_t *cyl0 = dive.get_or_create_cylinder(0);
|
||||
cyl0->gasmix = ean36;
|
||||
cyl0->type.size.mliter = 36000;
|
||||
cyl0->type.workingpressure.mbar = 232000;
|
||||
cyl0->type.size = 36_l;
|
||||
cyl0->type.workingpressure = 232_bar;
|
||||
cyl1->gasmix = tx11_50;
|
||||
dive.surface_pressure.mbar = 1013;
|
||||
dive.surface_pressure = 1_atm;
|
||||
reset_cylinders(&dive, true);
|
||||
|
||||
plan_add_segment(dp, 120, 40000, 0, 0, true, OC);
|
||||
|
@ -420,10 +420,10 @@ diveplan setupPlanCcr()
|
|||
dp.bottomsac = prefs.bottomsac;
|
||||
dp.decosac = prefs.decosac;
|
||||
|
||||
pressure_t po2 = {.mbar = 1600};
|
||||
struct gasmix diluent = {{.permille = 200}, {.permille = 210}};
|
||||
struct gasmix ean53 = {{.permille = 530}, {}};
|
||||
struct gasmix tx19_33 = {{.permille = 190}, {.permille = 330}};
|
||||
pressure_t po2 = 1600_mbar;
|
||||
struct gasmix diluent = { 20_percent, 21_percent};
|
||||
struct gasmix ean53 = { 53_percent, 0_percent};
|
||||
struct gasmix tx19_33 = { 19_percent, 33_percent};
|
||||
// Note: we add the highest-index cylinder first, because
|
||||
// pointers to cylinders are not stable when reallocating.
|
||||
// For testing OK - don't do this in actual code!
|
||||
|
@ -432,8 +432,8 @@ diveplan setupPlanCcr()
|
|||
cylinder_t *cyl1 = dive.get_or_create_cylinder(1);
|
||||
cyl0->gasmix = diluent;
|
||||
cyl0->depth = dive.gas_mod(diluent, po2, M_OR_FT(3, 10));
|
||||
cyl0->type.size.mliter = 3000;
|
||||
cyl0->type.workingpressure.mbar = 200000;
|
||||
cyl0->type.size = 3_l;
|
||||
cyl0->type.workingpressure = 200_bar;
|
||||
cyl0->cylinder_use = DILUENT;
|
||||
cyl1->gasmix = ean53;
|
||||
cyl1->depth = dive.gas_mod(ean53, po2, M_OR_FT(3, 10));
|
||||
|
@ -754,7 +754,7 @@ void TestPlan::testMultipleGases()
|
|||
save_dive(stdout, dive, false);
|
||||
#endif
|
||||
|
||||
gasmix gas = dive.get_gasmix_at_time(dive.dcs[0], {.seconds = 20 * 60 + 1});
|
||||
gasmix gas = dive.get_gasmix_at_time(dive.dcs[0], 20_min + 1_sec);
|
||||
QCOMPARE(get_o2(gas), 110);
|
||||
QVERIFY(compareDecoTime(dive.dcs[0].duration.seconds, 2480u, 2480u));
|
||||
}
|
||||
|
@ -934,17 +934,17 @@ void TestPlan::testCcrBailoutGasSelection()
|
|||
#endif
|
||||
|
||||
// check diluent used
|
||||
cylinder_t *cylinder = dive.get_cylinder(get_cylinderid_at_time(&dive, &dive.dcs[0], { .seconds = 20 * 60 - 1 }));
|
||||
cylinder_t *cylinder = dive.get_cylinder(get_cylinderid_at_time(&dive, &dive.dcs[0], 20_min - 1_sec));
|
||||
QCOMPARE(cylinder->cylinder_use, DILUENT);
|
||||
QCOMPARE(get_o2(cylinder->gasmix), 200);
|
||||
|
||||
// check deep bailout used
|
||||
cylinder = dive.get_cylinder(get_cylinderid_at_time(&dive, &dive.dcs[0], { .seconds = 20 * 60 + 1 }));
|
||||
cylinder = dive.get_cylinder(get_cylinderid_at_time(&dive, &dive.dcs[0], 20_min + 1_sec));
|
||||
QCOMPARE(cylinder->cylinder_use, OC_GAS);
|
||||
QCOMPARE(get_o2(cylinder->gasmix), 190);
|
||||
|
||||
// check shallow bailout used
|
||||
cylinder = dive.get_cylinder(get_cylinderid_at_time(&dive, &dive.dcs[0], { .seconds = 30 * 60 }));
|
||||
cylinder = dive.get_cylinder(get_cylinderid_at_time(&dive, &dive.dcs[0], 30_min));
|
||||
QCOMPARE(cylinder->cylinder_use, OC_GAS);
|
||||
QCOMPARE(get_o2(cylinder->gasmix), 530);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue