Fixed variable names

This commit is contained in:
2023-06-11 16:52:23 -07:00
parent e59cfac837
commit 28c1a84b80
4 changed files with 297 additions and 297 deletions

View File

@ -2,7 +2,7 @@ use std::hash::Hash;
use crate::quantity::Scalar;
use crate::quantity::Quantity;
use super::UnitBase;
use super::WholeUnit;
use super::Prefix;
use super::Unit;
use super::unit_db;
@ -13,7 +13,7 @@ use super::unit_db;
#[derive(Copy, Clone)]
#[derive(PartialEq, Eq)]
pub struct FreeUnit {
pub (in super) base: UnitBase,
pub (in super) whole: WholeUnit,
pub (in super) prefix: Prefix
}
@ -28,7 +28,7 @@ macro_rules! unpack_string {
impl ToString for FreeUnit {
fn to_string(&self) -> String {
let s = unit_db!(self.base, unpack_string);
let s = unit_db!(self.whole, unpack_string);
let p = self.prefix.to_string();
format!("{p}{s}")
@ -55,9 +55,9 @@ macro_rules! unpack_base_factor {
scalar: Scalar::new_float_from_string($value).unwrap(),
unit: Unit::from_array(&[
$(
(FreeUnit::from_base($u), Scalar::new_rational($p).unwrap()),
(FreeUnit::from_whole($u), Scalar::new_rational($p).unwrap()),
)*
(FreeUnit::from_base($unit), Scalar::new_rational(-1f64).unwrap())
(FreeUnit::from_whole($unit), Scalar::new_rational(-1f64).unwrap())
])
})
};
@ -73,9 +73,9 @@ macro_rules! unpack_base_factor {
scalar: Scalar::new_rational_from_string($value).unwrap(),
unit: Unit::from_array(&[
$(
(FreeUnit::from_base($u), Scalar::new_rational($p).unwrap()),
(FreeUnit::from_whole($u), Scalar::new_rational($p).unwrap()),
)*
(FreeUnit::from_base($unit), Scalar::new_rational(-1f64).unwrap())
(FreeUnit::from_whole($unit), Scalar::new_rational(-1f64).unwrap())
])
})
};
@ -91,9 +91,9 @@ macro_rules! unpack_base_factor {
scalar: Scalar::new_rational_from_frac($t, $b).unwrap(),
unit: Unit::from_array(&[
$(
(FreeUnit::from_base($u), Scalar::new_rational($p).unwrap()),
(FreeUnit::from_whole($u), Scalar::new_rational($p).unwrap()),
)*
(FreeUnit::from_base($unit), Scalar::new_rational(-1f64).unwrap())
(FreeUnit::from_whole($unit), Scalar::new_rational(-1f64).unwrap())
])
})
};
@ -101,11 +101,11 @@ macro_rules! unpack_base_factor {
impl FreeUnit {
pub fn from_base(base: UnitBase) -> FreeUnit {
return FreeUnit { base, prefix: Prefix::None }
pub fn from_whole(whole: WholeUnit) -> FreeUnit {
return FreeUnit { whole, prefix: Prefix::None }
}
pub fn from_base_prefix(base: UnitBase, prefix: Prefix) -> FreeUnit { FreeUnit {base, prefix} }
pub fn from_whole_prefix(whole: WholeUnit, prefix: Prefix) -> FreeUnit { FreeUnit {whole, prefix} }
pub fn set_prefix(&mut self, prefix: Prefix) { self.prefix = prefix; }
pub fn get_prefix(&self) -> Prefix { self.prefix }
@ -113,12 +113,12 @@ impl FreeUnit {
/// gives a quantity in base units.
pub fn to_base_factor(&self) -> Quantity {
let q = unit_db!(self.base, unpack_base_factor);
let q = unit_db!(self.whole, unpack_base_factor);
let mut q = q.unwrap_or(Quantity::new_rational_from_string("1").unwrap());
let mut p = self.prefix.to_ratio();
p.insert_unit(FreeUnit::from_base(self.base), Scalar::new_rational(1f64).unwrap());
p.insert_unit(FreeUnit::from_base_prefix(self.base, self.prefix), Scalar::new_rational(-1f64).unwrap());
p.insert_unit(FreeUnit::from_whole(self.whole), Scalar::new_rational(1f64).unwrap());
p.insert_unit(FreeUnit::from_whole_prefix(self.whole, self.prefix), Scalar::new_rational(-1f64).unwrap());
q.mul_assign_no_convert(p);
return q;
@ -126,11 +126,11 @@ impl FreeUnit {
// Get this unit in terms of base units
pub fn get_base(&self) -> Quantity {
let q = unit_db!(self.base, unpack_base_factor);
let q = unit_db!(self.whole, unpack_base_factor);
let mut q = q.unwrap_or(Quantity::new_rational_from_string("1").unwrap());
// Don't divide by self
q.insert_unit(FreeUnit::from_base(self.base), Scalar::new_rational(1f64).unwrap());
q.insert_unit(FreeUnit::from_whole_prefix(self.whole, self.prefix), Scalar::new_rational(1f64).unwrap());
return q;
}