-
Notifications
You must be signed in to change notification settings - Fork 98
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
added Torque #132
Conversation
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?
#[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"; |
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. |
|
You have a very good eye for detail. :-) Fixed. |
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 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);
} |
…rom that converts between Kinds.
…turtles#117 (and finishes the request in iliekturtles#114).
Done! Thanks for all your help with this! |
Merged! Thanks so much for all the work that went into this. |
No sense cutting a new version just yet, I'll have AngularVelocity and AngularAcceleration PRs for you very soon. |
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.