@@ -18,6 +18,8 @@ pub const PASCAL_PSI_FACTOR: f64 = 6894.76;
1818pub const PASCAL_TORR_FACTOR : f64 = PASCAL_ATMOSPHERE_FACTOR / 760.0 ;
1919/// Number of Pascals in a millitorr
2020pub const PASCAL_MILLITORR_FACTOR : f64 = PASCAL_TORR_FACTOR / 1000.0 ;
21+ /// Number of Pascals in mmHg
22+ pub const PASCAL_MMHG_FACTOR : f64 = 133.322387415 ;
2123
2224/// The `Pressure` struct can be used to deal with pressures in a common way.
2325/// Common metric and imperial units are supported.
@@ -73,17 +75,21 @@ impl Pressure {
7375 Self :: from_pascals ( atmospheres * PASCAL_ATMOSPHERE_FACTOR )
7476 }
7577
76- /// Create new Pressure from floating point value in Torr (also often referred to as mmHg)
78+ /// Create new Pressure from floating point value in Torr
7779 pub fn from_torrs ( torrs : f64 ) -> Pressure {
7880 Self :: from_pascals ( torrs * PASCAL_TORR_FACTOR )
7981 }
8082
81- /// Create new Pressure from floating point value in millitorr (mTorr, also often referred to
82- /// as microns for µmHg)
83+ /// Create new Pressure from floating point value in millitorr (mTorr)
8384 pub fn from_millitorrs ( millitorrs : f64 ) -> Pressure {
8485 Self :: from_pascals ( millitorrs * PASCAL_MILLITORR_FACTOR )
8586 }
8687
88+ /// Create new Pressure from floating point value in millimeter of mercury (mmHg)
89+ pub fn from_millimeter_mercury ( mmhg : f64 ) -> Pressure {
90+ Self :: from_pascals ( mmhg * PASCAL_MMHG_FACTOR )
91+ }
92+
8793 /// Convert this Pressure into a floating point value in Pascals
8894 pub fn as_pascals ( & self ) -> f64 {
8995 self . pascals
@@ -119,16 +125,20 @@ impl Pressure {
119125 self . pascals / PASCAL_ATMOSPHERE_FACTOR
120126 }
121127
122- /// Convert this Pressure into a floating point value in Torr (also often referred to as mmHg)
128+ /// Convert this Pressure into a floating point value in Torr
123129 pub fn as_torrs ( & self ) -> f64 {
124130 self . pascals / PASCAL_TORR_FACTOR
125131 }
126132
127- /// Convert this Pressure into a floating point value in millitorr (mTorr, also often referred
128- /// to as microns for µmHg)
133+ /// Convert this Pressure into a floating point value in millitorr (mTorr)
129134 pub fn as_millitorrs ( & self ) -> f64 {
130135 self . pascals / PASCAL_MILLITORR_FACTOR
131136 }
137+
138+ /// Convert this Pressure into a floating point value in millimeter of mercury (mmHg)
139+ pub fn as_millimeter_mercury ( & self ) -> f64 {
140+ self . pascals / PASCAL_MMHG_FACTOR
141+ }
132142}
133143
134144impl Measurement for Pressure {
@@ -249,6 +259,17 @@ mod test {
249259 assert_almost_eq ( o, 13.33224 ) ;
250260 }
251261
262+ #[ test]
263+ fn mmhg ( ) {
264+ let t = Pressure :: from_pascals ( 100.0 ) ;
265+ let o = t. as_millimeter_mercury ( ) ;
266+ assert_almost_eq ( o, 0.7500615758 ) ;
267+
268+ let t = Pressure :: from_millimeter_mercury ( 100.0 ) ;
269+ let o = t. as_pascals ( ) ;
270+ assert_almost_eq ( o, 13332.2387415 ) ;
271+ }
272+
252273 // Traits
253274 #[ test]
254275 fn add ( ) {
0 commit comments