Skip to content

Commit

Permalink
fixup! Add NumberDensity quantities: Volumetric, Areal, and Linear.
Browse files Browse the repository at this point in the history
  • Loading branch information
iliekturtles committed Sep 1, 2022
1 parent 518abbb commit 3b41059
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 25 deletions.
34 changes: 26 additions & 8 deletions src/si/areal_number_density.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,29 @@ quantity! {
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_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 millimeter", "per square millimeter";
@per_square_micrometer: prefix!(none) / prefix!(micro) / prefix!(micro); "µm⁻²",
"per square micrometer", "per square micrometer";

@per_square_mile: prefix!(none) / 2.589_988_E6; "mi⁻²",
"per square mile", "per square mile";
"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";
}
}

Expand All @@ -55,8 +65,16 @@ mod test {
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_square_mile, a::square_mile>();

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()),
Expand Down
26 changes: 16 additions & 10 deletions src/si/linear_number_density.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,22 @@ quantity! {
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_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";
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/si/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ system! {
torque::Torque,
velocity::Velocity,
volume::Volume,
volumetric_number_density::VolumetricNumberDensity,
volume_rate::VolumeRate,
volumetric_number_density::VolumetricNumberDensity,
}
}

Expand Down
43 changes: 37 additions & 6 deletions src/si/volumetric_number_density.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,32 @@ quantity! {
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_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_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";
}
}

Expand All @@ -50,6 +68,19 @@ mod test {
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());
Expand Down

0 comments on commit 3b41059

Please sign in to comment.