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 Jerk, L^1 * T^-3 #128

Merged
merged 1 commit into from
Apr 27, 2019
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
52 changes: 29 additions & 23 deletions src/si/acceleration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ quantity! {
@foot_per_second_squared: 3.048_E-1; "ft/s²", "foot per second squared", "feet per second squared";
@galileo: 1.0_E-2; "Gal", "galileo", "galileos";
@inch_per_second_squared: 2.54_E-2; "in/s²", "inch per second squared", "inches per second squared";
@millimeter_per_minute_squared: 2.777_777_777_777_777_8_E-7; "mm/min²",
"millimeter per minute squared", "millimeters per minute squared";
}
}

Expand All @@ -80,32 +82,36 @@ mod tests {

#[test]
fn check_units() {
test::<l::yottameter, a::yottameter_per_second_squared>();
test::<l::zettameter, a::zettameter_per_second_squared>();
test::<l::exameter, a::exameter_per_second_squared>();
test::<l::petameter, a::petameter_per_second_squared>();
test::<l::terameter, a::terameter_per_second_squared>();
test::<l::gigameter, a::gigameter_per_second_squared>();
test::<l::megameter, a::megameter_per_second_squared>();
test::<l::kilometer, a::kilometer_per_second_squared>();
test::<l::hectometer, a::hectometer_per_second_squared>();
test::<l::decameter, a::decameter_per_second_squared>();
test::<l::meter, a::meter_per_second_squared>();
test::<l::decimeter, a::decimeter_per_second_squared>();
test::<l::centimeter, a::centimeter_per_second_squared>();
test::<l::millimeter, a::millimeter_per_second_squared>();
test::<l::micrometer, a::micrometer_per_second_squared>();
test::<l::nanometer, a::nanometer_per_second_squared>();
test::<l::picometer, a::picometer_per_second_squared>();
test::<l::femtometer, a::femtometer_per_second_squared>();
test::<l::attometer, a::attometer_per_second_squared>();
test::<l::zeptometer, a::zeptometer_per_second_squared>();
test::<l::yoctometer, a::yoctometer_per_second_squared>();
test::<l::yottameter, t::second, a::yottameter_per_second_squared>();
test::<l::zettameter, t::second, a::zettameter_per_second_squared>();
test::<l::exameter, t::second, a::exameter_per_second_squared>();
test::<l::petameter, t::second, a::petameter_per_second_squared>();
test::<l::terameter, t::second, a::terameter_per_second_squared>();
test::<l::gigameter, t::second, a::gigameter_per_second_squared>();
test::<l::megameter, t::second, a::megameter_per_second_squared>();
test::<l::kilometer, t::second, a::kilometer_per_second_squared>();
test::<l::hectometer, t::second, a::hectometer_per_second_squared>();
test::<l::decameter, t::second, a::decameter_per_second_squared>();
test::<l::meter, t::second, a::meter_per_second_squared>();
test::<l::decimeter, t::second, a::decimeter_per_second_squared>();
test::<l::centimeter, t::second, a::centimeter_per_second_squared>();
test::<l::millimeter, t::second, a::millimeter_per_second_squared>();
test::<l::micrometer, t::second, a::micrometer_per_second_squared>();
test::<l::nanometer, t::second, a::nanometer_per_second_squared>();
test::<l::picometer, t::second, a::picometer_per_second_squared>();
test::<l::femtometer, t::second, a::femtometer_per_second_squared>();
test::<l::attometer, t::second, a::attometer_per_second_squared>();
test::<l::zeptometer, t::second, a::zeptometer_per_second_squared>();
test::<l::yoctometer, t::second, a::yoctometer_per_second_squared>();

fn test<L: l::Conversion<V>, A: a::Conversion<V>>() {
test::<l::foot, t::second, a::foot_per_second_squared>();
test::<l::centimeter, t::second, a::galileo>();
test::<l::millimeter, t::minute, a::millimeter_per_minute_squared>();

fn test<L: l::Conversion<V>, T: t::Conversion<V>, A: a::Conversion<V>>() {
Test::assert_eq(&Acceleration::new::<A>(V::one()),
&(Length::new::<L>(V::one()) /
(Time::new::<t::second>(V::one()) * Time::new::<t::second>(V::one()))));
(Time::new::<T>(V::one()) * Time::new::<T>(V::one()))));
}
}
}
Expand Down
121 changes: 121 additions & 0 deletions src/si/jerk.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
//! Jerk (base unit meter per second<sup>3</sup>, m<sup>1</sup> · s<sup>-3</sup>).

quantity! {
/// Jerk (base unit meter per second<sup>3</sup>, m<sup>1</sup> · s<sup>-3</sup>).
quantity: Jerk; "jerk";
/// Jerk dimension, m<sup>1</sup> · s<sup>-3</sup>.
dimension: ISQ<
P1, // length
Z0, // mass
N3, // time
Z0, // electric current
Z0, // thermodynamic temperature
Z0, // amount of substance
Z0>; // luminous intensity
units {
@yottameter_per_second_cubed: prefix!(yotta); "Ym/s³", "yottameter per second cubed",
"yottameters per second cubed";
@zettameter_per_second_cubed: prefix!(zetta); "Zm/s³", "zettameter per second cubed",
"zettameters per second cubed";
@exameter_per_second_cubed: prefix!(exa); "Em/s³", "exameter per second cubed",
"exameters per second cubed";
@petameter_per_second_cubed: prefix!(peta); "Pm/s³", "petameter per second cubed",
"petameters per second cubed";
@terameter_per_second_cubed: prefix!(tera); "Tm/s³", "terameter per second cubed",
"terameters per second cubed";
@gigameter_per_second_cubed: prefix!(giga); "Gm/s³", "gigameter per second cubed",
"gigameters per second cubed";
@megameter_per_second_cubed: prefix!(mega); "Mm/s³", "megameter per second cubed",
"megameters per second cubed";
@kilometer_per_second_cubed: prefix!(kilo); "km/s³", "kilometer per second cubed",
"kilometers per second cubed";
@hectometer_per_second_cubed: prefix!(hecto); "hm/s³", "hectometer per second cubed",
"hectometers per second cubed";
@decameter_per_second_cubed: prefix!(deca); "dam/s³", "decameter per second cubed",
"decameters per second cubed";
@meter_per_second_cubed: prefix!(none); "m/s³", "meter per second cubed",
"meters per second cubed";
@decimeter_per_second_cubed: prefix!(deci); "dm/s³", "decimeter per second cubed",
"decimeters per second cubed";
@centimeter_per_second_cubed: prefix!(centi); "cm/s³", "centimeter per second cubed",
"centimeters per second cubed";
@millimeter_per_second_cubed: prefix!(milli); "mm/s³", "millimeter per second cubed",
"millimeters per second cubed";
@micrometer_per_second_cubed: prefix!(micro); "µm/s³", "micrometer per second cubed",
"micrometers per second cubed";
@nanometer_per_second_cubed: prefix!(nano); "nm/s³", "nanometer per second cubed",
"nanometers per second cubed";
@picometer_per_second_cubed: prefix!(pico); "pm/s³", "picometer per second cubed",
"picometers per second cubed";
@femtometer_per_second_cubed: prefix!(femto); "fm/s³", "femtometer per second cubed",
"femtometers per second cubed";
@attometer_per_second_cubed: prefix!(atto); "am/s³", "attometer per second cubed",
"attometers per second cubed";
@zeptometer_per_second_cubed: prefix!(zepto); "zm/s³", "zeptometer per second cubed",
"zeptometers per second cubed";
@yoctometer_per_second_cubed: prefix!(yocto); "ym/s³", "yoctometer per second cubed",
"yoctometers per second cubed";

@foot_per_second_cubed: 3.048_E-1; "ft/s³", "foot per second cubed", "feet per second cubed";
@inch_per_second_cubed: 2.54_E-2; "in/s³", "inch per second cubed", "inches per second cubed";
@kilometer_per_minute_cubed: 4.629_629_629_629_629_E-3; "km/min³",
"kilometer per minute cubed", "kilometers per minute cubed";
}
}

#[cfg(test)]
mod tests {
storage_types! {
use num::One;
use si::quantities::*;
use si::jerk as j;
use si::length as l;
use si::time as t;
use tests::Test;

#[test]
fn check_dimension() {
let _: Jerk<V> = Length::new::<l::meter>(V::one())
/ (Time::new::<t::second>(V::one())
* Time::new::<t::second>(V::one())
* Time::new::<t::second>(V::one()));
}

#[test]
fn check_units() {
test::<l::yottameter, t::second, j::yottameter_per_second_cubed>();
test::<l::zettameter, t::second, j::zettameter_per_second_cubed>();
test::<l::exameter, t::second, j::exameter_per_second_cubed>();
test::<l::petameter, t::second, j::petameter_per_second_cubed>();
test::<l::terameter, t::second, j::terameter_per_second_cubed>();
test::<l::gigameter, t::second, j::gigameter_per_second_cubed>();
test::<l::megameter, t::second, j::megameter_per_second_cubed>();
test::<l::kilometer, t::second, j::kilometer_per_second_cubed>();
test::<l::hectometer, t::second, j::hectometer_per_second_cubed>();
test::<l::decameter, t::second, j::decameter_per_second_cubed>();
test::<l::meter, t::second, j::meter_per_second_cubed>();
test::<l::decimeter, t::second, j::decimeter_per_second_cubed>();
test::<l::centimeter, t::second, j::centimeter_per_second_cubed>();
test::<l::millimeter, t::second, j::millimeter_per_second_cubed>();
test::<l::micrometer, t::second, j::micrometer_per_second_cubed>();
test::<l::nanometer, t::second, j::nanometer_per_second_cubed>();
test::<l::picometer, t::second, j::picometer_per_second_cubed>();
test::<l::femtometer, t::second, j::femtometer_per_second_cubed>();
test::<l::attometer, t::second, j::attometer_per_second_cubed>();
test::<l::zeptometer, t::second, j::zeptometer_per_second_cubed>();
test::<l::yoctometer, t::second, j::yoctometer_per_second_cubed>();
test::<l::foot, t::second, j::foot_per_second_cubed>();
test::<l::inch, t::second, j::inch_per_second_cubed>();
test::<l::kilometer, t::minute, j::kilometer_per_minute_cubed>();

nicodemus26 marked this conversation as resolved.
Show resolved Hide resolved
fn test<L: l::Conversion<V>, T: t::Conversion<V>, J: j::Conversion<V>>() {
Test::assert_eq(
&Jerk::new::<J>(V::one()),
&(Length::new::<L>(V::one()) /
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Start next line with / operator. Do the same for the * operators. Tab in the contents of the inner-most ()s where the time^3 factor is calculated.

            fn test<L: l::Conversion<V>, T: t::Conversion<V>, J: j::Conversion<V>>() {
                Test::assert_eq(
                    &Jerk::new::<J>(V::one()),
                    &(Length::new::<L>(V::one())
                        / (Time::new::<T>(V::one())
                            * Time::new::<T>(V::one())
                            * Time::new::<T>(V::one()))));
            }

(Time::new::<T>(V::one()) *
Time::new::<T>(V::one()) *
Time::new::<T>(V::one()))));
}
}
}
}
1 change: 1 addition & 0 deletions src/si/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ system! {
force::Force,
frequency::Frequency,
inductance::Inductance,
jerk::Jerk,
length::Length,
luminance::Luminance,
luminous_intensity::LuminousIntensity,
Expand Down
62 changes: 37 additions & 25 deletions src/si/velocity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,18 @@ quantity! {
@yoctometer_per_second: prefix!(yocto); "ym/s", "yoctometer per second",
"yoctometers per second";

@foot_per_hour: 8.466_667_E-5; "ft/h", "foot per hour", "feet per hour";
@foot_per_hour: 8.466_666_666_666_667_E-5; "ft/h", "foot per hour", "feet per hour";
@foot_per_minute: 5.08_E-3; "ft/min", "foot per minute", "feet per minute";
@foot_per_second: 3.048_E-1; "ft/s", "foot per second", "feet per second";
@inch_per_second: 2.54_E-2; "in/s", "inch per second", "inches per second";
@kilometer_per_hour: 2.777_778_E-1; "km/h", "kilometer per hour", "kilometers per hour";
@kilometer_per_hour: 2.777_777_777_777_778_E-1; "km/h", "kilometer per hour",
"kilometers per hour";
@knot: 5.144_444_E-1; "kn", "knot", "knots";
@mile_per_hour: 4.470_4_E-1; "mi/h", "mile per hour", "miles per hour";
@mile_per_minute: 2.682_24_E1; "mi/min", "mile per minute", "miles per minute";
@mile_per_second: 1.609_344_E3; "mi/s", "mile per second", "miles per second";
@millimeter_per_minute: 1.666_666_666_666_666_667_E-5; "mm/min", "millimeter per minute",
"millimeters per minute";
}
}

Expand All @@ -85,31 +88,40 @@ mod test {

#[test]
fn check_units() {
test::<l::yottameter, v::yottameter_per_second>();
test::<l::zettameter, v::zettameter_per_second>();
test::<l::exameter, v::exameter_per_second>();
test::<l::petameter, v::petameter_per_second>();
test::<l::terameter, v::terameter_per_second>();
test::<l::gigameter, v::gigameter_per_second>();
test::<l::megameter, v::megameter_per_second>();
test::<l::kilometer, v::kilometer_per_second>();
test::<l::hectometer, v::hectometer_per_second>();
test::<l::decameter, v::decameter_per_second>();
test::<l::meter, v::meter_per_second>();
test::<l::decimeter, v::decimeter_per_second>();
test::<l::centimeter, v::centimeter_per_second>();
test::<l::millimeter, v::millimeter_per_second>();
test::<l::micrometer, v::micrometer_per_second>();
test::<l::nanometer, v::nanometer_per_second>();
test::<l::picometer, v::picometer_per_second>();
test::<l::femtometer, v::femtometer_per_second>();
test::<l::attometer, v::attometer_per_second>();
test::<l::zeptometer, v::zeptometer_per_second>();
test::<l::yoctometer, v::yoctometer_per_second>();
test::<l::yottameter, t::second, v::yottameter_per_second>();
test::<l::zettameter, t::second, v::zettameter_per_second>();
test::<l::exameter, t::second, v::exameter_per_second>();
test::<l::petameter, t::second, v::petameter_per_second>();
test::<l::terameter, t::second, v::terameter_per_second>();
test::<l::gigameter, t::second, v::gigameter_per_second>();
test::<l::megameter, t::second, v::megameter_per_second>();
test::<l::kilometer, t::second, v::kilometer_per_second>();
test::<l::hectometer, t::second, v::hectometer_per_second>();
test::<l::decameter, t::second, v::decameter_per_second>();
test::<l::meter, t::second, v::meter_per_second>();
test::<l::decimeter, t::second, v::decimeter_per_second>();
test::<l::centimeter, t::second, v::centimeter_per_second>();
test::<l::millimeter, t::second, v::millimeter_per_second>();
test::<l::micrometer, t::second, v::micrometer_per_second>();
test::<l::nanometer, t::second, v::nanometer_per_second>();
test::<l::picometer, t::second, v::picometer_per_second>();
test::<l::femtometer, t::second, v::femtometer_per_second>();
test::<l::attometer, t::second, v::attometer_per_second>();
test::<l::zeptometer, t::second, v::zeptometer_per_second>();
test::<l::yoctometer, t::second, v::yoctometer_per_second>();

fn test<L: l::Conversion<V>, E: v::Conversion<V>>() {
test::<l::foot, t::hour, v::foot_per_hour>();
test::<l::foot, t::minute, v::foot_per_minute>();
test::<l::foot, t::second, v::foot_per_second>();
test::<l::inch, t::second, v::inch_per_second>();
test::<l::kilometer, t::hour, v::kilometer_per_hour>();
test::<l::mile, t::hour, v::mile_per_hour>();
test::<l::mile, t::second, v::mile_per_second>();
test::<l::millimeter, t::minute, v::millimeter_per_minute>();

fn test<L: l::Conversion<V>, T: t::Conversion<V>, E: v::Conversion<V>>() {
Test::assert_eq(&Velocity::new::<E>(V::one()),
&(Length::new::<L>(V::one()) / Time::new::<t::second>(V::one())));
&(Length::new::<L>(V::one()) / Time::new::<T>(V::one())));
}
}
}
Expand Down