Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
KG32 committed Jun 20, 2024
1 parent 104fa99 commit 7879756
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 16 deletions.
6 changes: 3 additions & 3 deletions src/buehlmann/buehlmann_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -121,7 +121,7 @@ impl DecoModel for BuehlmannModel {
}

fn deco(&self, gas_mixes: Vec<Gas>) -> Deco {
let mut deco = Deco::new();
let mut deco = Deco::default();
deco.calc(self.fork(), gas_mixes);

deco
Expand Down
19 changes: 6 additions & 13 deletions src/common/deco.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,13 @@ pub struct DecoStage {
pub gas: Gas,
}

#[derive(Clone, Debug)]
#[derive(Default, Clone, Debug)]
pub struct Deco {
pub deco_stages: Vec<DecoStage>,
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<Gas>) -> Self {
// run model simulation until no deco stages
loop {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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<Gas>, surface_pressure: MbarPressure) -> Option<Gas> {
let current_gas_partial_pressures = current_gas.partial_pressures(&current_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(&current_depth, surface_pressure);
let partial_pressures = gas.partial_pressures(current_depth, surface_pressure);
partial_pressures.o2 > current_gas_partial_pressures.o2
})
.collect::<Vec<Gas>>();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 7879756

Please sign in to comment.