Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add NumberDensity quantities: Volumetric, Areal, and Linear. #334

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions src/si/areal_number_density.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
//! Areal number density (base unit 1 per square meter, m⁻²).

quantity! {
/// Areal number density (base unit 1 per square meter, m⁻²).
quantity: ArealNumberDensity; "areal number density";
/// Dimension of areal number density, L⁻² (base unit 1 per square meter, m⁻²).
dimension: ISQ<
N2, // length
Z0, // mass
Z0, // time
Z0, // electric current
Z0, // thermodynamic temperature
Z0, // amount of substance
Z0>; // luminous intensity
kind: dyn (crate::si::marker::ConstituentConcentrationKind);
units {
@per_square_kilometer: prefix!(none) / prefix!(kilo) / prefix!(kilo); "km⁻²",
"per square kilometer", "per square kilometer";
@per_square_meter: prefix!(none); "m⁻²", "per square meter", "per square meter";
@per_square_decimeter: prefix!(none) / prefix!(deci) / prefix!(deci); "dm⁻²",
"per square decimeter", "per square decimeter";
@per_square_centimeter: prefix!(none) / prefix!(centi) / prefix!(centi); "cm⁻²",
"per square centimeter", "per square centimeter";
@per_square_millimeter: prefix!(none) / prefix!(milli) / prefix!(milli); "mm⁻²",
"per square millimeter", "per square millimeter";
@per_square_micrometer: prefix!(none) / prefix!(micro) / prefix!(micro); "µm⁻²",
"per square micrometer", "per square micrometer";

@per_acre: prefix!(none) / 4.046_873_E3; "ac⁻²", "per acre", "per acre";
@per_are: prefix!(none) / 1.0_E2; "a⁻²", "per are", "per are";
@per_barn: prefix!(none) / 1.0_E-28; "b⁻²", "per barn", "per barn";
@per_circular_mil: prefix!(none) / 5.067_075_E-10; "cmil⁻²", "per circular mil",
"per circular mil";
@per_hectare: prefix!(none) / 1.0_E4; "ha⁻²", "per hectare", "per hectare";
@per_square_foot: prefix!(none) / 9.290_304_E-2; "ft⁻²", "per square foot",
"per square foot";
@per_square_inch: prefix!(none) / 6.451_6_E-4; "in⁻²", "per square inch", "per square inch";
@per_square_mile: prefix!(none) / 2.589_988_E6; "mi⁻²", "per square mile",
"per square mile";
@per_square_yard: prefix!(none) / 8.361_274_E-1; "yd⁻²", "per square yard",
"per square yard";
}
}

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

#[test]
fn check_dimension() {
let _: ArealNumberDensity<V> = (V::one()
/ Area::new::<a::square_meter>(V::one())).into();
}

#[test]
fn check_units() {
test::<n::per_square_kilometer, a::square_kilometer>();
test::<n::per_square_meter, a::square_meter>();
test::<n::per_square_decimeter, a::square_decimeter>();
test::<n::per_square_centimeter, a::square_centimeter>();
test::<n::per_square_millimeter, a::square_millimeter>();
test::<n::per_square_micrometer, a::square_micrometer>();

test::<n::per_acre, a::acre>();
test::<n::per_are, a::are>();
test::<n::per_barn, a::barn>();
test::<n::per_circular_mil, a::circular_mil>();
test::<n::per_hectare, a::hectare>();
test::<n::per_square_foot, a::square_foot>();
test::<n::per_square_inch, a::square_inch>();
test::<n::per_square_mile, a::square_mile>();
test::<n::per_square_yard, a::square_yard>();

fn test<N: n::Conversion<V>, A: a::Conversion<V>>() {
Test::assert_approx_eq(&ArealNumberDensity::new::<N>(V::one()),
&(V::one() / Area::new::<A>(V::one())).into());
}
}
}
}
65 changes: 65 additions & 0 deletions src/si/linear_number_density.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
//! Linear number density (base unit 1 per meter, m⁻¹).

quantity! {
/// Linear number density (base unit 1 per meter, m⁻¹).
quantity: LinearNumberDensity; "linear number density";
/// Dimension of linear number density, L⁻¹ (base 1 unit per meter, m⁻¹).
dimension: ISQ<
N1, // length
Z0, // mass
Z0, // time
Z0, // electric current
Z0, // thermodynamic temperature
Z0, // amount of substance
Z0>; // luminous intensity
kind: dyn (crate::si::marker::ConstituentConcentrationKind);
units {
@per_kilometer: prefix!(none) / prefix!(kilo); "km⁻¹", "per kilometer", "per kilometer";
@per_meter: prefix!(none); "m⁻¹", "per meter", "per meter";
@per_decimeter: prefix!(none) / prefix!(deci); "dm⁻¹", "per decimeter", "per decimeter";
@per_centimeter: prefix!(none) / prefix!(centi); "cm⁻¹", "per centimeter", "per centimeter";
@per_millimeter: prefix!(none) / prefix!(milli); "mm⁻¹", "per millimeter", "per millimeter";

@per_foot: prefix!(none) / 3.048_E-1; "ft⁻¹", "per foot", "per foot";
@per_foot_survey: prefix!(none) / 3.048_006_E-1; "ft (U.S. survey)", "foot (U.S. survey)",
"foot (U.S. survey)";
@per_inch: prefix!(none) / 2.54_E-2; "in⁻¹", "per inch", "per inch";
@per_mile: prefix!(none) / 1.609_344_E3; "mi⁻¹", "per mile", "per mile";
@per_mile_survey: prefix!(none) / 1.609_347_E3; "mi⁻¹ (U.S. survey)",
"per mile (U.S. survey)", "per mile (U.S. survey)";
@per_nautical_mile: prefix!(none) / 1.852_E3; "M⁻¹", "per nautical mile",
"per nautical mile";
@per_yard: prefix!(none) / 9.144_E-1; "yd⁻¹", "per yard", "per yard";
}
}

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

#[test]
fn check_dimension() {
let _: LinearNumberDensity<V> = (V::one()
/ Length::new::<l::meter>(V::one())).into();
}

#[test]
fn check_units() {
test::<n::per_kilometer, l::kilometer>();
test::<n::per_meter, l::meter>();
test::<n::per_decimeter, l::decimeter>();
test::<n::per_centimeter, l::centimeter>();
test::<n::per_millimeter, l::millimeter>();

fn test<N: n::Conversion<V>, L: l::Conversion<V>>() {
Test::assert_approx_eq(&LinearNumberDensity::new::<N>(V::one()),
&(V::one() / Length::new::<L>(V::one())).into());
}
}
}
}
3 changes: 3 additions & 0 deletions src/si/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ system! {
angular_velocity::AngularVelocity,
area::Area,
areal_mass_density::ArealMassDensity,
areal_number_density::ArealNumberDensity,
available_energy::AvailableEnergy,
capacitance::Capacitance,
catalytic_activity::CatalyticActivity,
Expand Down Expand Up @@ -86,6 +87,7 @@ system! {
jerk::Jerk,
length::Length,
linear_mass_density::LinearMassDensity,
linear_number_density::LinearNumberDensity,
linear_power_density::LinearPowerDensity,
luminance::Luminance,
luminous_intensity::LuminousIntensity,
Expand Down Expand Up @@ -124,6 +126,7 @@ system! {
velocity::Velocity,
volume::Volume,
volume_rate::VolumeRate,
volumetric_number_density::VolumetricNumberDensity,
volumetric_power_density::VolumetricPowerDensity,
}
}
Expand Down
90 changes: 90 additions & 0 deletions src/si/volumetric_number_density.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
//! Volumetric number density (base unit 1 per cubic meter, m⁻³).

quantity! {
/// Volumetric number density (base unit 1 per cubic meter, m⁻³).
quantity: VolumetricNumberDensity; "volumetric number density";
/// Dimension of volumetric number density, L⁻³ (base unit 1 per cubic meter, m⁻³).
dimension: ISQ<
N3, // length
Z0, // mass
Z0, // time
Z0, // electric current
Z0, // thermodynamic temperature
Z0, // amount of substance
Z0>; // luminous intensity
kind: dyn (crate::si::marker::ConstituentConcentrationKind);
units {
@per_cubic_kilometer: prefix!(none) / prefix!(kilo) / prefix!(kilo) / prefix!(kilo); "km⁻³",
"per cubic kilometer", "per cubic kilometer";
@per_cubic_meter: prefix!(none); "m⁻³", "per cubic meter", "per cubic meter";
@per_cubic_decimeter: prefix!(none) / prefix!(deci) / prefix!(deci) / prefix!(deci); "dm⁻³",
"per cubic decimeter", "per cubic decimeter";
@per_cubic_centimeter: prefix!(none) / prefix!(centi) / prefix!(centi) / prefix!(centi);
"cm⁻³", "per cubic centimeter", "per cubic centimeter";
@per_cubic_millimeter: prefix!(none) / prefix!(milli) / prefix!(milli) / prefix!(milli);
"mm⁻³", "per cubic millimeter", "per cubic millimeter";

@per_cubic_foot: prefix!(none) / 2.831_685_E-2; "ft⁻³", "per cubic foot", "per cubic foot";
@per_cubic_inch: prefix!(none) / 1.638_706_E-5; "in⁻³", "per cubic inch", "per cubic inch";
@per_cubic_mile: prefix!(none) / 4.168_182_E9; "mi⁻³", "per cubic mile", "per cubic mile";
@per_cubic_yard: prefix!(none) / 7.645_549_E-1; "yd⁻³", "per cubic yard", "per cubic yard";
@per_fluid_ounce: prefix!(none) / 2.957_353_E-5; "per fl oz", "per fluid ounce",
"per fluid ounce";
@per_fluid_ounce_imperial: prefix!(none) / 2.841_306_E-5; "per fl oz (UK)",
"per Imperial fluid ounce", "per Imperial fluid ounce";
@per_gallon_imperial: prefix!(none) / 4.546_09_E-3; "per gal (UK)", "per Imperial gallon",
"per Imperial gallon";
@per_gallon: prefix!(none) / 3.785_412_E-3; "per gal", "per gallon", "per gallon";
@per_liter: prefix!(none) / prefix!(milli); "L⁻¹", "per liter", "per liter";
@per_deciliter: prefix!(none) / prefix!(milli) / prefix!(deci); "dL⁻¹", "per deciliter",
"per deciliter";
@per_centiliter: prefix!(none) / prefix!(milli) / prefix!(centi); "cL⁻¹",
"per centiliter", "per centiliter";
@per_milliliter: prefix!(none) / prefix!(milli) / prefix!(milli); "mL⁻¹",
"per milliliter", "per milliliter";
}
}

#[cfg(test)]
mod test {
storage_types! {
use crate::num::One;
use crate::si::volume as v;
use crate::si::volumetric_number_density as n;
use crate::si::quantities::*;
use crate::tests::Test;

#[test]
fn check_dimension() {
let _: VolumetricNumberDensity<V> = (V::one()
/ Volume::new::<v::cubic_meter>(V::one())).into();
}

#[test]
fn check_units() {
test::<n::per_cubic_kilometer, v::cubic_kilometer>();
test::<n::per_cubic_meter, v::cubic_meter>();
test::<n::per_cubic_decimeter, v::cubic_decimeter>();
test::<n::per_cubic_centimeter, v::cubic_centimeter>();
test::<n::per_cubic_millimeter, v::cubic_millimeter>();

test::<n::per_cubic_foot, v::cubic_foot>();
test::<n::per_cubic_inch, v::cubic_inch>();
test::<n::per_cubic_mile, v::cubic_mile>();
test::<n::per_cubic_yard, v::cubic_yard>();
test::<n::per_fluid_ounce, v::fluid_ounce>();
test::<n::per_fluid_ounce_imperial, v::fluid_ounce_imperial>();
test::<n::per_gallon_imperial, v::gallon_imperial>();
test::<n::per_gallon, v::gallon>();
test::<n::per_liter, v::liter>();
test::<n::per_deciliter, v::deciliter>();
test::<n::per_centiliter, v::centiliter>();
test::<n::per_milliliter, v::milliliter>();

fn test<N: n::Conversion<V>, U: v::Conversion<V>>() {
Test::assert_approx_eq(&VolumetricNumberDensity::new::<N>(V::one()),
&(V::one() / Volume::new::<U>(V::one())).into());
}
}
}
}