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

added Torque #132

Merged
merged 2 commits into from
May 10, 2019
Merged

added Torque #132

merged 2 commits into from
May 10, 2019

Conversation

dunmatt
Copy link

@dunmatt dunmatt commented May 3, 2019

This PR replaces #124 and requires far less drastic changes to the quantities macros. The great part, though, is that the tests both compile and pass now.

@coveralls
Copy link

coveralls commented May 3, 2019

Coverage Status

Coverage increased (+0.09%) to 97.317% when pulling cf9af7d on dunmatt:torqueTakeThree into 565ad5f on iliekturtles:master.

@iliekturtles
Copy link
Owner

Thanks for the updated PR! After some dead ends I think we're getting pretty close now. Should the #124 be closed now that this PR is submitted?

  • AngleKind
    • AngleKind is specific to si and should be moved out of the crate root and into si::marker (or just si?).
    • Since the quantity! macro is not si specific the AngleKind references should be moved into si::marker (or just si?). See the From note below.
    • Temperature should probably be moved into si::marker (or just si?) at the same time. Names should be made consistent. Kind suffix on both?
  • From
    • The From impl can be specified once for AngleKind->Kind and Kind->AngleKind instead of once per quantity. See the code fragment below. The fragment was written in the si module and we may want to move to si::marker to be next to the kinds that are being affected. Also possibly si::convert. Thoughts?
    • I suggest writing one impl in a macro in si::marker (or just si?) that accepts the two Kinds as parameters which can then be called for each direction/kind: impl_from!(AngleKind, Kind); impl_from!(Kind, AngleKind); impl_from!(SomeOtherKind, Kind); ... Doc tests should be added on at least one impl.
  • Torque
    • See the diff at the bottom for some comment updates to account for Aehmlo's recent PR and to adjust the moment warning slightly.
#[cfg_attr(feature = "f32", doc = " ```rust")]
#[cfg_attr(not(feature = "f32"), doc = " ```rust,ignore")]
/// # use uom::si::f32::*;
/// # use uom::si::ratio::ratio;
/// let r: Ratio = Ratio::new::<ratio>(1.0);
/// let a: Angle = r.into();
/// ```
impl<L, M, T, I, Th, N, J, Ul, Ur, V>
    From<Quantity<Dimension<L = L, M = M, T = T, I = I, Th = Th, N = N, J = J, Kind = ::Kind>, Ur, V>>
    for Quantity<Dimension<L = L, M = M, T = T, I = I, Th = Th, N = N, J = J, Kind = AngleKind>, Ul, V>
where
    Ul: Units<V> + ?Sized,
    Ur: Units<V> + ?Sized,
    V: ::num_traits::Num + ::Conversion<V>,
{
    fn from(
        val: Quantity<Dimension<L = L, M = M, T = T, I = I, Th = Th, N = N, J = J, Kind = ::Kind>, Ur, V>
    ) -> Quantity<Dimension<L = L, M = M, T = T, I = I, Th = Th, N = N, J = J, Kind = AngleKind>, Ul, V> {
        Self {
            dimension: ::lib::marker::PhantomData,
            units: ::lib::marker::PhantomData,
            value: change_base::<Dimension<L = L, M = M, T = T, I = I, Th = Th, N = N, J = J, Kind = AngleKind>, Ul, Ur, V>(
                &val.value),
        }
    }
}

#[cfg_attr(feature = "f32", doc = " ```rust")]
#[cfg_attr(not(feature = "f32"), doc = " ```rust,ignore")]
/// # use uom::si::f32::*;
/// # use uom::si::angle::radian;
/// let a: Angle = Angle::new::<radian>(1.0);
/// let r: Ratio = a.into();
/// ```
impl<L, M, T, I, Th, N, J, Ul, Ur, V>
    From<Quantity<Dimension<L = L, M = M, T = T, I = I, Th = Th, N = N, J = J, Kind = AngleKind>, Ur, V>>
    for Quantity<Dimension<L = L, M = M, T = T, I = I, Th = Th, N = N, J = J, Kind = ::Kind>, Ul, V>
where
    Ul: Units<V> + ?Sized,
    Ur: Units<V> + ?Sized,
    V: ::num_traits::Num + ::Conversion<V>,
{
    fn from(
        val: Quantity<Dimension<L = L, M = M, T = T, I = I, Th = Th, N = N, J = J, Kind = AngleKind>, Ur, V>
    ) -> Quantity<Dimension<L = L, M = M, T = T, I = I, Th = Th, N = N, J = J, Kind = ::Kind>, Ul, V> {
        Self {
            dimension: ::lib::marker::PhantomData,
            units: ::lib::marker::PhantomData,
            value: change_base::<Dimension<L = L, M = M, T = T, I = I, Th = Th, N = N, J = J, Kind = ::Kind>, Ul, Ur, V>(
                &val.value),
        }
    }
}
diff --git a/src/si/torque.rs b/src/si/torque.rs
index 05c7f34..e885020 100644
--- a/src/si/torque.rs
+++ b/src/si/torque.rs
@@ -1,16 +1,14 @@
-//! Torque (aka moment of force) (base unit newton meter, kg · m<sup>2</sup> · s<sup>-2</sup>).
+//! Torque (aka moment of force) (base unit newton meter, kg · m² · s⁻²).
 
 quantity! {
-    /// Torque magnitude (base unit newton meter, kg · m<sup>2</sup> · s<sup>-2</sup>).
+    /// Torque (aka moment of force) (base unit newton meter, kg · m² · s⁻²).
     ///
-    /// Torques are moments, which means they inherently depend on a distance to a frame of
-    /// reference. If instead you talk about the magnitude of the torque about some point you can
-    /// externalize the frame of reference for the sake of fitting torques into a framework of
-    /// quantities and dimensional analysis. Note that as a consequence of this the compile time
-    /// guarantees of this library are weaker for torques than other quantities; it is very possible
-    /// to combine torques in nonsensical ways and still have your code typecheck. Be careful.
+    /// Torque is a moment, the product of distance and force. Moments are inherently dependent on
+    /// the distance from a fixed reference point. This library does not capture this dependency.
+    /// As a consequence, there are *no compile time guarantees that only moments of the same frame
+    /// can be combined*.
     quantity: Torque; "Torque";
-    /// Torque dimension, kg · m<sup>2</sup> · s<sup>-2</sup>.
+    /// Dimension of torque, L²MT⁻² (base unit newton meter, kg · m² · s⁻²).
     dimension: ISQ<
         P2,     // length
         P1,     // mass
@@ -19,7 +17,7 @@ quantity! {
         Z0,     // thermodynamic temperature
         Z0,     // amount of substance
         Z0>;    // luminous intensity
-    @angle_kind;
+    kind: super::AngleKind;
     units {
         @yottanewton_meter: prefix!(yotta); "YN · m", "yottanewton meter", "yottanewton meters";
         @zettanewton_meter: prefix!(zetta); "ZN · m", "zettanewton meter", "zettanewton meters";

@dunmatt dunmatt force-pushed the torqueTakeThree branch from 5d916e1 to 09cc279 Compare May 5, 2019 17:58
@dunmatt
Copy link
Author

dunmatt commented May 5, 2019

Feedback makes sense. Thanks for the implementation, I would have never, ever, come up with that! In any case, it's looking like the tests are going to pass, so major attempt at adding Torque # 4 is ready for review.

@iliekturtles
Copy link
Owner

  • si.rs
    • Can you put mod quantities and the storage_types! invocation next to each other instead of with mod marker in the middle.
    • Doc comment on impl_from invocations doesn't seem to work. I suggest moving to AngleKind.
  • torque.rs
    • Change description to be lower case: quantity: Torque; "torque";

@dunmatt
Copy link
Author

dunmatt commented May 8, 2019

You have a very good eye for detail. :-) Fixed.

@iliekturtles
Copy link
Owner

Could you apply the following diff and then squash/rebase into two commits: one for the kind/from changes and one to add torque. I'll plan to merge after that!

Move doc test to AngleKind. When on the impl_from invocation it doesn't seem to get run.

diff --git a/src/si/mod.rs b/src/si/mod.rs
index 9bfe7c8..79f689f 100644
--- a/src/si/mod.rs
+++ b/src/si/mod.rs
@@ -72,7 +72,7 @@ storage_types! {
     ISQ!(si, V);
 }

-/// A place for things pertaining to SI specific Kinds.
+/// Primitive traits and types representing basic properties of types specific to the SI.
 pub mod marker {
     use si::{change_base, Dimension, Quantity, Units};
     use Kind;
@@ -80,6 +80,14 @@ pub mod marker {
     /// AngleKind is a `Kind` for separating angular quantities from their indentically dimensioned
     /// non-angular quantity counterparts. Conversions to and from `AngleKind` quantities is
     /// supported through implementations of the `From` trait.
+    ///
+    #[cfg_attr(feature = "f32", doc = " ```rust")]
+    #[cfg_attr(not(feature = "f32"), doc = " ```rust,ignore")]
+    /// # use uom::si::f32::*;
+    /// # use uom::si::angle::radian;
+    /// let a: Angle = Angle::new::<radian>(1.0);
+    /// let r: Ratio = a.into();
+    /// ```
     pub trait AngleKind: ::Kind {}

     /// Kind of thermodynamic temperature.
@@ -141,13 +149,6 @@ pub mod marker {
         };
     }

-    #[cfg_attr(feature = "f32", doc = " ```rust")]
-    #[cfg_attr(not(feature = "f32"), doc = " ```rust,ignore")]
-    /// # use uom::si::f32::*;
-    /// # use uom::si::angle::radian;
-    /// let a: Angle = Angle::new::<radian>(1.0);
-    /// let r: Ratio = a.into();
-    /// ```
     impl_from!(AngleKind, Kind);
     impl_from!(Kind, AngleKind);
 }

@dunmatt dunmatt force-pushed the torqueTakeThree branch from 4140760 to cf9af7d Compare May 8, 2019 20:48
@dunmatt
Copy link
Author

dunmatt commented May 8, 2019

Done! Thanks for all your help with this!

@iliekturtles iliekturtles merged commit ff50eab into iliekturtles:master May 10, 2019
@iliekturtles
Copy link
Owner

Merged! Thanks so much for all the work that went into this.

@dunmatt dunmatt deleted the torqueTakeThree branch May 10, 2019 18:19
@dunmatt
Copy link
Author

dunmatt commented May 10, 2019

No sense cutting a new version just yet, I'll have AngularVelocity and AngularAcceleration PRs for you very soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants