Skip to content

Commit

Permalink
Add LinearMassDensity and ArealMassDensity quantities with related un…
Browse files Browse the repository at this point in the history
…its.
  • Loading branch information
crystal-growth authored and iliekturtles committed Sep 3, 2022
1 parent d4bdcd9 commit 8f24d0f
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 0 deletions.
58 changes: 58 additions & 0 deletions src/si/areal_mass_density.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//! Areal mass density (base unit kilogram per square meter, m⁻² · kg).
quantity! {
/// Areal mass density (base unit kilogram per square meter, m⁻² · kg).
quantity: ArealMassDensity; "areal mass density";
/// Dimension of areal mass density, L⁻²M (base unit kilogram per square meter, m⁻² · kg).
dimension: ISQ<
N2, // length
P1, // mass
Z0, // time
Z0, // electric current
Z0, // thermodynamic temperature
Z0, // amount of substance
Z0>; // luminous intensity
units {
@kilogram_per_square_meter: prefix!(none); "kg/m²", "kilogram per square meter",
"kilograms per square meter";
@gram_per_square_meter: prefix!(milli); "g/m²", "gram per square meter",
"grams per square meter";
@gram_per_square_centimeter: prefix!(milli) / prefix!(centi) / prefix!(centi); "g/cm²",
"gram per square centimeter", "grams per square centimeter";

@ounce_per_square_foot: 2.834_952_E-2 / 9.290_304_E-2; "oz/ft²", "ounce per square foot",
"ounces per square foot";
}
}

#[cfg(test)]
mod test {
storage_types! {
use crate::num::One;
use crate::si::mass as m;
use crate::si::areal_mass_density as d;
use crate::si::quantities::*;
use crate::si::area as a;
use crate::tests::Test;

#[test]
fn check_dimension() {
let _: ArealMassDensity<V> = Mass::new::<m::kilogram>(V::one())
/ Area::new::<a::square_meter>(V::one());
}

#[test]
fn check_units() {
test::<m::kilogram, a::square_meter, d::kilogram_per_square_meter>();
test::<m::gram, a::square_meter, d::gram_per_square_meter>();
test::<m::gram, a::square_centimeter, d::gram_per_square_centimeter>();

test::<m::ounce, a::square_foot, d::ounce_per_square_foot>();

fn test<M: m::Conversion<V>, A: a::Conversion<V>, D: d::Conversion<V>>() {
Test::assert_approx_eq(&ArealMassDensity::new::<D>(V::one()),
&(Mass::new::<M>(V::one()) / Area::new::<A>(V::one())));
}
}
}
}
64 changes: 64 additions & 0 deletions src/si/linear_mass_density.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
//! Linear mass density (base unit kilogram per meter, m⁻¹ · kg).
quantity! {
/// Linear mass density (base unit kilogram per meter, m⁻¹ · kg).
quantity: LinearMassDensity; "linear mass density";
/// Dimension of linear mass density, L⁻¹M (base unit kilogram per meter, m⁻¹ · kg).
dimension: ISQ<
N1, // length
P1, // mass
Z0, // time
Z0, // electric current
Z0, // thermodynamic temperature
Z0, // amount of substance
Z0>; // luminous intensity
units {
@kilogram_per_meter: prefix!(none); "kg/m", "kilogram per meter", "kilograms per meter";
@gram_per_kilometer: prefix!(milli) / prefix!(kilo); "g/km", "gram per kilometer",
"grams per kilometer";
@gram_per_centimeter: prefix!(milli) / prefix!(centi); "g/cm", "gram per centimeter",
"grams per centimeter";

@ounce_per_foot: 2.834_952_E-2 / 3.048_E-1; "oz/ft", "ounce per foot", "ounces per foot";
@ounce_per_inch: 2.834_952_E-2 / 2.54_E-2; "oz/in", "ounce per inch", "ounces per inch";
@pound_per_yard: 4.535_924_E-1 / 9.144_E-1; "lb/yd", "pound per yard", "pounds per yard";
@pound_per_foot: 4.535_924_E-1 / 3.048_E-1; "lb/ft", "pound per foot", "pounds per foot";
@pound_per_inch: 4.535_924_E-1 / 2.54_E-2; "lb/in", "pound per inch", "pounds per inch";
}
}

#[cfg(test)]
mod test {
storage_types! {
use crate::num::One;
use crate::si::mass as m;
use crate::si::linear_mass_density as d;
use crate::si::quantities::*;
use crate::si::length as l;
use crate::tests::Test;

#[test]
fn check_dimension() {
let _: LinearMassDensity<V> = Mass::new::<m::kilogram>(V::one())
/ Length::new::<l::meter>(V::one());
}

#[test]
fn check_units() {
test::<m::kilogram, l::meter, d::kilogram_per_meter>();
test::<m::gram, l::kilometer, d::gram_per_kilometer>();
test::<m::gram, l::centimeter, d::gram_per_centimeter>();

test::<m::ounce, l::foot, d::ounce_per_foot>();
test::<m::ounce, l::inch, d::ounce_per_inch>();
test::<m::pound, l::yard, d::pound_per_yard>();
test::<m::pound, l::foot, d::pound_per_foot>();
test::<m::pound, l::inch, d::pound_per_inch>();

fn test<M: m::Conversion<V>, L: l::Conversion<V>, D: d::Conversion<V>>() {
Test::assert_approx_eq(&LinearMassDensity::new::<D>(V::one()),
&(Mass::new::<M>(V::one()) / Length::new::<L>(V::one())));
}
}
}
}
2 changes: 2 additions & 0 deletions src/si/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ system! {
angular_jerk::AngularJerk,
angular_velocity::AngularVelocity,
area::Area,
areal_mass_density::ArealMassDensity,
available_energy::AvailableEnergy,
capacitance::Capacitance,
catalytic_activity::CatalyticActivity,
Expand All @@ -79,6 +80,7 @@ system! {
information_rate::InformationRate,
jerk::Jerk,
length::Length,
linear_mass_density::LinearMassDensity,
luminance::Luminance,
luminous_intensity::LuminousIntensity,
magnetic_flux::MagneticFlux,
Expand Down

0 comments on commit 8f24d0f

Please sign in to comment.