1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
use num_traits::cast::FromPrimitive;
use std::isize;
use time::Duration;
pub const DEFAULT_DESCENT_RATE: isize = 30;
pub const DEFAULT_ASCENT_RATE: isize = -18;
pub const DENSITY_FRESHWATER: f64 = 997.0;
pub const DENSITY_SALTWATER: f64 = 1023.6;
pub mod dive_segment;
pub mod gas;
pub mod tank;
pub mod otu;
pub use dive_segment::DiveSegment;
pub use dive_segment::DiveSegmentError;
pub use dive_segment::SegmentType;
pub use gas::Gas;
pub use gas::GasError;
pub use tank::Tank;
pub fn bar_mtr(bar: f64, metres_per_bar: f64) -> f64 {
(bar - 1.0) * metres_per_bar
}
pub fn mtr_bar(mtr: f64, metres_per_bar: f64) -> f64 {
(mtr / metres_per_bar) + 1.0
}
pub fn time_taken(rate: isize, depth_1: usize, depth_2: usize) -> Duration {
let delta_depth = ((depth_1 as isize) - (depth_2 as isize)).abs();
let rate_seconds = rate.abs() as f64 / 60.0;
Duration::seconds(
i64::from_f64(delta_depth as f64 / rate_seconds).expect("overflow in time taken"),
)
}