mkproj_lib/uc.rs
1pub mod uniconv {
2 //! This is used to convert units of various measurements
3 //!
4 //! All methods use the same parameters `(unit1: f32 )->f32`
5 //!
6 //! - unit1 represents the unit to be converted
7 //! - represents the converted unit
8 // Ex. function
9 // pub fn (unit1: f32 ) -> f32{}
10 pub mod temperature {
11 //! This is used to convert temperatures
12 /// Fahrenheit to Celsius degrees
13 pub fn fahr_to_cels(unit1: f32) -> f32 {
14 (unit1 - 32.0) * (5.0 / 9.0)
15 }
16 /// Fahrenheit to Kelvin degrees
17 pub fn fahr_to_kelv(unit1: f32) -> f32 {
18 (5.0 / 9.0) * (unit1 - 32.0) + 273.0
19 }
20 /// Celsius to Fahrenheit degrees
21 pub fn cels_to_fahr(unit1: f32) -> f32 {
22 (unit1 * 9.0 / 5.0) + 32.0
23 }
24 /// Celsius to Kelvin degrees
25 pub fn cels_to_kelv(unit1: f32) -> f32 {
26 unit1 + 273.0
27 }
28 /// Kelvin to Fahrenheit degrees
29 pub fn kelv_to_fahr(unit1: f32) -> f32 {
30 (9.0 / 5.0) * (unit1 - 273.0) + 32.0
31 }
32 /// Kelvin to Celsius degrees
33 pub fn kelv_to_cels(unit1: f32) -> f32 {
34 unit1 - 273.0
35 }
36 }
37 pub mod speed {
38 //! This is used to convert speeds
39 /// Metres per Second to Kilometre per Hour
40 pub fn mps_to_kph(unit1: f32) -> f32 {
41 unit1 * 3.6
42 }
43 /// Kilometre per Hour to Metres per Second
44 pub fn kph_to_mps(unit1: f32) -> f32 {
45 unit1 / 3.6
46 }
47 /// Metres per Second to Knots
48 pub fn mps_to_knots(unit1: f32) -> f32 {
49 unit1 * 1.944
50 }
51 /// Kilometre per Hour to Knots
52 pub fn kph_to_knots(unit1: f32) -> f32 {
53 unit1 / 1.852
54 }
55 }
56 pub mod length {
57 //! This is used to convert lengths
58 //!
59 //! **Only metres will be used for imperial unit conversions!**
60 /// Metres to Inches
61 pub fn m_to_inch(unit1: f32) -> f32 {
62 unit1 * 39.37
63 }
64 /// Metres to Feet
65 pub fn m_to_foot(unit1: f32) -> f32 {
66 unit1 * 3.281
67 }
68 /// Metres to Yards
69 pub fn m_to_yard(unit1: f32) -> f32 {
70 unit1 * 1.094
71 }
72 /// Metres to Miles
73 pub fn m_to_mile(unit1: f32) -> f32 {
74 unit1 / 1609.0
75 }
76 /// Inches to Metres
77 pub fn inch_to_m(unit1: f32) -> f32 {
78 unit1 / 39.37
79 }
80 /// Feet to Metres
81 pub fn foot_to_m(unit1: f32) -> f32 {
82 unit1 / 3.281
83 }
84 /// Yards to Metres
85 pub fn yard_to_m(unit1: f32) -> f32 {
86 unit1 / 1.094
87 }
88 /// Miles to Metres
89 pub fn mile_to_m(unit1: f32) -> f32 {
90 unit1 * 1609.0
91 }
92 /// Milimetres to Metres
93 pub fn mm_to_m(unit1: f32) -> f32 {
94 unit1 / 1000.0
95 }
96 /// Centimetres to Metres
97 pub fn cm_to_m(unit1: f32) -> f32 {
98 unit1 / 100.0
99 }
100 /// Kilometres to Metres
101 pub fn km_to_m(unit1: f32) -> f32 {
102 unit1 * 1000.0
103 }
104 }
105}