From 19929cf76924d1686a55b2c1befef66efabd42f2 Mon Sep 17 00:00:00 2001 From: Kuba Groblewski Date: Sat, 22 Jun 2024 00:28:46 +0200 Subject: [PATCH] fix: invalid depth on deco simulation --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/buehlmann/buehlmann_model.rs | 5 ++++- tests/deco_tests.rs | 4 ++-- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 41d932c..538eee1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,4 +4,4 @@ version = 3 [[package]] name = "dive-deco" -version = "1.3.0" +version = "1.3.1" diff --git a/Cargo.toml b/Cargo.toml index ba236f2..7eb5036 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "dive-deco" -version = "1.3.0" +version = "1.3.1" edition = "2021" license = "MIT" description = "A dive decompression models library (Buehlmann ZH-L 16C)" diff --git a/src/buehlmann/buehlmann_model.rs b/src/buehlmann/buehlmann_model.rs index 16816d3..c788363 100644 --- a/src/buehlmann/buehlmann_model.rs +++ b/src/buehlmann/buehlmann_model.rs @@ -227,7 +227,10 @@ impl BuehlmannModel { let sim_gas = sim_model.state.gas; let mut target_depth = sim_model.state.depth; while target_depth > 0. { - let sim_step_depth = target_depth - 1.; + let mut sim_step_depth = target_depth - 1.; + if sim_step_depth < 0. { + sim_step_depth = 0.; + } sim_model.step(&sim_step_depth, &0, &sim_gas); let Supersaturation { gf_99, .. } = sim_model.supersaturation(); if gf_99 >= gf_low.into() { diff --git a/tests/deco_tests.rs b/tests/deco_tests.rs index 0d22945..e6c2bec 100644 --- a/tests/deco_tests.rs +++ b/tests/deco_tests.rs @@ -75,7 +75,7 @@ fn deco_multi_gas() { let mut model = fixtures::model_default(); - model.step(&40., &(20 * 60), &air); + model.step(&40.0001, &(20 * 60), &air); let Deco { deco_stages, @@ -87,7 +87,7 @@ fn deco_multi_gas() { let expected_deco_stages = vec![ DecoStage { stage_type: DecoStageType::Ascent, - start_depth: 40.0, + start_depth: 40.0001, end_depth: 22., duration: 120, gas: air