diff --git a/src/buehlmann/buehlmann_model.rs b/src/buehlmann/buehlmann_model.rs index 65c4253..16816d3 100644 --- a/src/buehlmann/buehlmann_model.rs +++ b/src/buehlmann/buehlmann_model.rs @@ -50,7 +50,7 @@ impl DecoModel for BuehlmannModel { config, compartments: vec![], state: initial_model_state, - deco: Deco::new(), + deco: Deco::default(), }; model.create_compartments(ZHL_16C_N2_16A_HE_VALUES, config); @@ -93,7 +93,7 @@ impl DecoModel for BuehlmannModel { fn step_travel_with_rate(&mut self, target_depth: &Depth, rate: &AscentRatePerMinute, gas: &Gas) { self.validate_depth(target_depth); let distance = (target_depth - self.state.depth).abs(); - let travel_time_seconds = ((distance / rate * 60.)) as usize; + let travel_time_seconds = (distance / rate * 60.) as usize; self.step_travel(target_depth, &travel_time_seconds, gas); } @@ -121,7 +121,7 @@ impl DecoModel for BuehlmannModel { } fn deco(&self, gas_mixes: Vec) -> Deco { - let mut deco = Deco::new(); + let mut deco = Deco::default(); deco.calc(self.fork(), gas_mixes); deco diff --git a/src/common/deco.rs b/src/common/deco.rs index 37776f2..4a8a5d2 100644 --- a/src/common/deco.rs +++ b/src/common/deco.rs @@ -29,20 +29,13 @@ pub struct DecoStage { pub gas: Gas, } -#[derive(Clone, Debug)] +#[derive(Default, Clone, Debug)] pub struct Deco { pub deco_stages: Vec, pub tts: Minutes, } impl Deco { - pub fn new() -> Self { - Self { - deco_stages: vec![], - tts: 0, - } - } - pub fn calc(&mut self, mut sim_model: impl DecoModel, gas_mixes: Vec) -> Self { // run model simulation until no deco stages loop { @@ -99,7 +92,7 @@ impl Deco { }); // switch gas @todo configurable gas change duration - sim_model.step(&sim_model.dive_state().depth, &(1 * 60), &next_switch_gas); + sim_model.step(&sim_model.dive_state().depth, &60, &next_switch_gas); // @todo configurable oxygen window stop let post_switch_state = sim_model.dive_state(); deco_stages.push(DecoStage { @@ -176,12 +169,12 @@ impl Deco { /// check next deco gas in deco (the one with lowest MOD while more oxygen-rich than current) fn next_switch_gas(&self, current_depth: &Depth, current_gas: &Gas, gas_mixes: Vec, surface_pressure: MbarPressure) -> Option { - let current_gas_partial_pressures = current_gas.partial_pressures(¤t_depth, surface_pressure.clone()); + let current_gas_partial_pressures = current_gas.partial_pressures(current_depth, surface_pressure); // all potential deco gases that are more oxygen-rich than current (inc. trimix / heliox) let mut switch_gasses = gas_mixes .into_iter() .filter(|gas| { - let partial_pressures = gas.partial_pressures(¤t_depth, surface_pressure); + let partial_pressures = gas.partial_pressures(current_depth, surface_pressure); partial_pressures.o2 > current_gas_partial_pressures.o2 }) .collect::>(); @@ -243,7 +236,7 @@ mod tests { (3.00001, 6.), (12., 12.), ]; - let deco = Deco::new(); + let deco = Deco::default(); for case in test_cases.into_iter() { let (input_depth, expected_depth) = case; let res = deco.deco_stop_depth(&input_depth); @@ -275,7 +268,7 @@ mod tests { (30., air, vec![air, trimix], Some(trimix)), ]; - let deco = Deco::new(); + let deco = Deco::default(); for case in test_cases.into_iter() { dbg!(&case); let (current_depth, current_gas, available_gas_mixes, expected_switch_gas) = case;