capra_core/deco/deco_algorithm.rs
1use crate::common::dive_segment;
2use crate::common::dive_segment::DiveSegment;
3use crate::common::gas::Gas;
4use crate::deco::tissue::Tissue;
5
6/// Trait for decompression models. This trait must be implemented for any custom decompression
7/// algorithms if they are to be used in dive plans with the [`DivePlan`] trait.
8pub trait DecoAlgorithm: Copy {
9 /// Apply a segment to the deco model.
10 /// # Arguments
11 /// * `segment` - DiveSegment to apply.
12 /// * `gas` - Gas that is being consumed in this segment.
13 /// * `metres_per_bar` - Depth of water required to induce 1 bar of pressure.
14 fn add_dive_segment(&mut self, segment: &DiveSegment, gas: &Gas, metres_per_bar: f64);
15
16 /// Surface the deco model, returning the mandatory decompression stops / remaining no-decompression
17 /// time along the way.
18 /// # Arguments
19 /// * `ascent_rate` - Ascent rate to use during stops
20 /// * `descent_rate` - Ascent rate to use during stops
21 fn surface(
22 &mut self,
23 ascent_rate: isize,
24 descent_rate: isize,
25 gas: &Gas,
26 metres_per_bar: f64,
27 ) -> Vec<dive_segment::DiveSegment>;
28
29 /// Get the tissue loadings of the model
30 fn get_tissue(&self) -> Tissue;
31
32 /// Get the decompression stops required to surface the model. This is identical to `surface`
33 /// but it does not modify the original model in any way.
34 fn get_stops(
35 &self,
36 ascent_rate: isize,
37 descent_rate: isize,
38 gas: &Gas,
39 metres_per_bar: f64,
40 ) -> Vec<dive_segment::DiveSegment> {
41 let mut virtual_deco = *self;
42 virtual_deco.surface(ascent_rate, descent_rate, gas, metres_per_bar)
43 }
44}