Added Pascals

This commit is contained in:
Zachary Sunforge
2025-01-02 20:48:22 -08:00
parent 4c922b940b
commit 9fbbf0b1ce
2 changed files with 40 additions and 2 deletions

View File

@ -16,7 +16,7 @@ members = [
]
[workspace.package]
version = "0.4.2"
version = "0.4.3"
edition = "2021"
repository = "https://git.bfpower.io/BFPOWER/physical"
readme = "README.md"

View File

@ -1,5 +1,43 @@
use crate::quantity::{Quantity, Value};
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"}
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);
}
}