Added Pascals
This commit is contained in:
@ -16,7 +16,7 @@ members = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
[workspace.package]
|
[workspace.package]
|
||||||
version = "0.4.2"
|
version = "0.4.3"
|
||||||
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,5 +1,43 @@
|
|||||||
use crate::quantity::{Quantity, Value};
|
use crate::quantity::{Quantity, Value};
|
||||||
use generate_quantity::quantity_type;
|
use generate_quantity::quantity_type;
|
||||||
|
|
||||||
//----- Kilopascal ----------------------------------
|
use super::KILO;
|
||||||
|
|
||||||
|
//----- Pascals ----------------------------------
|
||||||
|
quantity_type! {Pascals, "Pa"}
|
||||||
|
|
||||||
|
impl<V: Value> Pascals<V> {
|
||||||
|
#[inline]
|
||||||
|
pub fn to_kilo_pascals(self) -> KiloPascals<V> {
|
||||||
|
let divisor = V::from_u16(KILO).unwrap();
|
||||||
|
KiloPascals(self.0 / divisor)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//----- Kilopascals ----------------------------------
|
||||||
quantity_type! {KiloPascals, "kPa"}
|
quantity_type! {KiloPascals, "kPa"}
|
||||||
|
|
||||||
|
impl<V: Value> KiloPascals<V> {
|
||||||
|
#[inline]
|
||||||
|
pub fn to_pascals(self) -> Pascals<V> {
|
||||||
|
let multiplier = V::from_u16(KILO).unwrap();
|
||||||
|
Pascals(self.0 * multiplier)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------------------------------------------------
|
||||||
|
// ----- Tests ------------------------
|
||||||
|
// ---------------------------------------------------------------------------------------------------------------------
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn convert_u32() {
|
||||||
|
let pascals: Pascals<u32> = 1_000.pascals();
|
||||||
|
let kilo_pascals: KiloPascals<u32> = 1.kilo_pascals();
|
||||||
|
|
||||||
|
assert_eq!(pascals.0, kilo_pascals.to_pascals().0);
|
||||||
|
assert_eq!(kilo_pascals.0, pascals.to_kilo_pascals().0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user