Skip to content

Commit

Permalink
Merge pull request #135 from dunmatt/angular
Browse files Browse the repository at this point in the history
Add `AngularVelocity`.
  • Loading branch information
iliekturtles committed May 12, 2019
2 parents bc5a344 + 0a730a7 commit 5050d98
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/si/angle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ mod convert {
mod tests {
storage_types! {
use ::lib::f64::consts::PI;
use num::One;
use num_traits::FromPrimitive;
use num::{FromPrimitive, One};
use si::angle as a;
use si::quantities::*;
use tests::Test;
Expand Down
54 changes: 54 additions & 0 deletions src/si/angular_velocity.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//! Angular velocity (base unit radian per second, s⁻¹).

quantity! {
/// Angular velocity (base unit radian per second, s⁻¹).
quantity: AngularVelocity; "angular velocity";
/// Dimension of angular velocity, T⁻¹ (base unit radian per second, s⁻¹).
dimension: ISQ<
Z0, // length
Z0, // mass
N1, // time
Z0, // electric current
Z0, // thermodynamic temperature
Z0, // amount of substance
Z0>; // luminous intensity
kind: ::si::marker::AngleKind;
units {
/// Derived unit of angular velocity.
@radian_per_second: 1.0_E0; "rad/s", "radian per second", "radians per second";
@degree_per_second: 1.745_329_251_994_329_5_E-2; "°/s", "degree per second",
"degrees per second";
@revolution_per_second: 6.283_185_307_179_586_E0; "rps", "revolution per second",
"revolutions per second";
@revolution_per_minute: 1.047_197_551_196_597_7_E-1; "rpm", "revolution per minute",
"revolutions per minute";
@revolution_per_hour: 1.745_329_251_994_329_6_E-3; "rph", "revolution per hour",
"revolutions per hour";
}
}

#[cfg(test)]
mod tests {
storage_types! {
use num::One;
use si::angle as a;
use si::angular_velocity as v;
use si::quantities::*;
use si::time as t;
use tests::Test;

#[test]
fn check_units() {
test::<a::radian, t::second, v::radian_per_second>();
test::<a::degree, t::second, v::degree_per_second>();
test::<a::revolution, t::second, v::revolution_per_second>();
test::<a::revolution, t::minute, v::revolution_per_minute>();
test::<a::revolution, t::hour, v::revolution_per_hour>();

fn test<A: a::Conversion<V>, T: t::Conversion<V>, R: v::Conversion<V>>() {
Test::assert_approx_eq(&AngularVelocity::new::<R>(V::one()),
&(Angle::new::<A>(V::one()) / Time::new::<T>(V::one())).into());
}
}
}
}
1 change: 1 addition & 0 deletions src/si/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ system! {
amount_of_substance::AmountOfSubstance,
angle::Angle,
angular_acceleration::AngularAcceleration,
angular_velocity::AngularVelocity,
area::Area,
available_energy::AvailableEnergy,
capacitance::Capacitance,
Expand Down

0 comments on commit 5050d98

Please sign in to comment.