Added torr to quantities
This commit is contained in:
@ -16,7 +16,7 @@ members = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
[workspace.package]
|
[workspace.package]
|
||||||
version = "0.4.3"
|
version = "0.4.4"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
repository = "https://git.bfpower.io/BFPOWER/physical"
|
repository = "https://git.bfpower.io/BFPOWER/physical"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use crate::quantity::{Quantity, Value};
|
use crate::quantity::{KILO, Quantity, Value};
|
||||||
use generate_quantity::quantity_type;
|
use generate_quantity::quantity_type;
|
||||||
|
|
||||||
use super::KILO;
|
const PASCALS_PER_TORR: f64 = 101325.0 / 760.0;
|
||||||
|
|
||||||
//----- Pascals ----------------------------------
|
//----- Pascals ----------------------------------
|
||||||
quantity_type! {Pascals, "Pa"}
|
quantity_type! {Pascals, "Pa"}
|
||||||
@ -12,6 +12,13 @@ impl<V: Value> Pascals<V> {
|
|||||||
let divisor = V::from_u16(KILO).unwrap();
|
let divisor = V::from_u16(KILO).unwrap();
|
||||||
KiloPascals(self.0 / divisor)
|
KiloPascals(self.0 / divisor)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Should this be in separate imple with `V` bound to `num_traits::Float`?
|
||||||
|
#[inline]
|
||||||
|
pub fn to_torr(self) -> Torr<V> {
|
||||||
|
let divisor = V::from_f64(PASCALS_PER_TORR).unwrap();
|
||||||
|
Torr(self.0 / divisor)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//----- Kilopascals ----------------------------------
|
//----- Kilopascals ----------------------------------
|
||||||
@ -25,12 +32,25 @@ impl<V: Value> KiloPascals<V> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//----- Torr ----------------------------------
|
||||||
|
quantity_type! {Torr, "Torr"}
|
||||||
|
|
||||||
|
// Should this bound `V` to `num_traits::Float`?
|
||||||
|
impl<V: Value> Torr<V> {
|
||||||
|
#[inline]
|
||||||
|
pub fn to_pascals(self) -> Pascals<V> {
|
||||||
|
let multiplier = V::from_f64(PASCALS_PER_TORR).unwrap();
|
||||||
|
Pascals(self.0 * multiplier)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------------------------------------------------
|
||||||
// ----- Tests ------------------------
|
// ----- Tests ------------------------
|
||||||
// ---------------------------------------------------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------------------------------------------------
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use float_cmp::assert_approx_eq;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn convert_u32() {
|
fn convert_u32() {
|
||||||
@ -40,4 +60,13 @@ mod tests {
|
|||||||
assert_eq!(pascals.0, kilo_pascals.to_pascals().0);
|
assert_eq!(pascals.0, kilo_pascals.to_pascals().0);
|
||||||
assert_eq!(kilo_pascals.0, pascals.to_kilo_pascals().0);
|
assert_eq!(kilo_pascals.0, pascals.to_kilo_pascals().0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn torr_pascal() {
|
||||||
|
let torr: Torr<f32> = 7.5.torr();
|
||||||
|
let pascals: Pascals<f32> = 999.9177631578947.pascals();
|
||||||
|
|
||||||
|
assert_approx_eq!(f32, pascals.to_torr().0, torr.0);
|
||||||
|
assert_approx_eq!(f32, torr.to_pascals().0, pascals.0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user