22
33use super :: measurement:: * ;
44
5- /// Number of Pascals in an atomosphere
5+ /// Number of Pascals in an atmosphere
66pub const PASCAL_ATMOSPHERE_FACTOR : f64 = 101_325.0 ;
77/// Number of Pascals in a hectopascal
88pub const PASCAL_HECTOPASCAL_FACTOR : f64 = 100.0 ;
@@ -14,8 +14,12 @@ pub const PASCAL_MILLIBAR_FACTOR: f64 = 100.0;
1414pub const PASCAL_BAR_FACTOR : f64 = 100_000.0 ;
1515/// Number of Pascals in a PSI
1616pub const PASCAL_PSI_FACTOR : f64 = 6894.76 ;
17+ /// Number of Pascals in a Torr
18+ pub const PASCAL_TORR_FACTOR : f64 = PASCAL_ATMOSPHERE_FACTOR / 760.0 ;
19+ /// Number of Pascals in a millitorr
20+ pub const PASCAL_MILLITORR_FACTOR : f64 = PASCAL_TORR_FACTOR / 1000.0 ;
1721
18- /// The `Pressure` struct can be used to deal with presssures in a common way.
22+ /// The `Pressure` struct can be used to deal with pressures in a common way.
1923/// Common metric and imperial units are supported.
2024///
2125/// # Example
@@ -39,7 +43,7 @@ impl Pressure {
3943 Pressure { pascals }
4044 }
4145
42- /// Create new Pressure from floating point value in hectopascals (hPA )
46+ /// Create new Pressure from floating point value in hectopascals (hPa )
4347 pub fn from_hectopascals ( hectopascals : f64 ) -> Pressure {
4448 Self :: from_pascals ( hectopascals * PASCAL_HECTOPASCAL_FACTOR )
4549 }
@@ -69,6 +73,17 @@ impl Pressure {
6973 Self :: from_pascals ( atmospheres * PASCAL_ATMOSPHERE_FACTOR )
7074 }
7175
76+ /// Create new Pressure from floating point value in Torr (also often referred to as mmHg)
77+ pub fn from_torrs ( torrs : f64 ) -> Pressure {
78+ Self :: from_pascals ( torrs * PASCAL_TORR_FACTOR )
79+ }
80+
81+ /// Create new Pressure from floating point value in millitorr (mTorr, also often referred to
82+ /// as microns for µmHg)
83+ pub fn from_millitorrs ( millitorrs : f64 ) -> Pressure {
84+ Self :: from_pascals ( millitorrs * PASCAL_MILLITORR_FACTOR )
85+ }
86+
7287 /// Convert this Pressure into a floating point value in Pascals
7388 pub fn as_pascals ( & self ) -> f64 {
7489 self . pascals
@@ -103,6 +118,17 @@ impl Pressure {
103118 pub fn as_atmospheres ( & self ) -> f64 {
104119 self . pascals / PASCAL_ATMOSPHERE_FACTOR
105120 }
121+
122+ /// Convert this Pressure into a floating point value in Torr (also often referred to as mmHg)
123+ pub fn as_torrs ( & self ) -> f64 {
124+ self . pascals / PASCAL_TORR_FACTOR
125+ }
126+
127+ /// Convert this Pressure into a floating point value in millitorr (mTorr, also often referred
128+ /// to as microns for µmHg)
129+ pub fn as_millitorrs ( & self ) -> f64 {
130+ self . pascals / PASCAL_MILLITORR_FACTOR
131+ }
106132}
107133
108134impl Measurement for Pressure {
@@ -201,6 +227,28 @@ mod test {
201227 assert_almost_eq ( o, 689476.9760513823 ) ;
202228 }
203229
230+ #[ test]
231+ fn torr ( ) {
232+ let t = Pressure :: from_pascals ( 100.0 ) ;
233+ let o = t. as_torrs ( ) ;
234+ assert_almost_eq ( o, 0.7500617 ) ;
235+
236+ let t = Pressure :: from_torrs ( 100.0 ) ;
237+ let o = t. as_pascals ( ) ;
238+ assert_almost_eq ( o, 13332.24 ) ;
239+ }
240+
241+ #[ test]
242+ fn millitorr ( ) {
243+ let t = Pressure :: from_pascals ( 100.0 ) ;
244+ let o = t. as_millitorrs ( ) ;
245+ assert_almost_eq ( o, 750.0617 ) ;
246+
247+ let t = Pressure :: from_millitorrs ( 100.0 ) ;
248+ let o = t. as_pascals ( ) ;
249+ assert_almost_eq ( o, 13.33224 ) ;
250+ }
251+
204252 // Traits
205253 #[ test]
206254 fn add ( ) {
0 commit comments