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

Make hypot available for all quantities instead of just SI lengths #186

Merged
merged 1 commit into from
May 13, 2020
Merged

Make hypot available for all quantities instead of just SI lengths #186

merged 1 commit into from
May 13, 2020

Conversation

adamreichold
Copy link
Contributor

No description provided.

Copy link
Owner

@iliekturtles iliekturtles left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! Just one change to tests and we should be good to merge.

src/tests/quantity.rs Outdated Show resolved Hide resolved
@iliekturtles
Copy link
Owner

If you could apply some minor formatting changes from the diff below I'll merge!

diff --git a/src/quantity.rs b/src/quantity.rs
index 0aca8ae..b6aff6f 100644
--- a/src/quantity.rs
+++ b/src/quantity.rs
@@ -389,18 +389,18 @@ macro_rules! quantity {
             /// Calculates the length of the hypotenuse of a right-angle triangle given the legs.
             #[cfg(feature = "std")]
             #[inline(always)]
-            pub fn hypot<U1>(self, other: $quantity<U1, V>) -> Self
+            pub fn hypot<Ur>(self, other: $quantity<Ur, V>) -> Self
             where
                 V: $crate::num::Float,
-                U1: super::Units<V> + ?Sized,
+                Ur: super::Units<V> + ?Sized,
             {
                 Self {
                     dimension: $crate::lib::marker::PhantomData,
                     units: $crate::lib::marker::PhantomData,
-                    value: self.value.hypot(super::change_base::<Dimension, U, U1, V>(&other.value)),
+                    value: self.value.hypot(
+                        super::change_base::<Dimension, U, Ur, V>(&other.value)),
                 }
-            }
-            }
+            }}
 
             not_autoconvert! {
             /// Calculates the length of the hypotenuse of a right-angle triangle given the legs.
@@ -415,8 +415,7 @@ macro_rules! quantity {
                     units: $crate::lib::marker::PhantomData,
                     value: self.value.hypot(other.value),
                 }
-            }
-            }
+            }}
 
             /// Creates a struct that can be used to format a compatible quantity for display.
             ///
diff --git a/src/tests/quantities.rs b/src/tests/quantities.rs
index 6621cc9..2e5e62a 100644
--- a/src/tests/quantities.rs
+++ b/src/tests/quantities.rs
@@ -227,10 +227,8 @@ mod float {
         quickcheck! {
             #[allow(trivial_casts)]
             fn hypot(l: V, r: V) -> bool {
-                Test::eq(
-                    &l.hypot(r),
-                    &Length::new::<meter>(l).hypot(Length::new::<meter>(r)).get::<meter>(),
-                )
+                Test::eq(&l.hypot(r),
+                    &Length::new::<meter>(l).hypot(Length::new::<meter>(r)).get::<meter>())
             }
         }
     }
diff --git a/src/tests/quantity.rs b/src/tests/quantity.rs
index edf81da..d7ed7bd 100644
--- a/src/tests/quantity.rs
+++ b/src/tests/quantity.rs
@@ -457,10 +457,8 @@ mod float {
         quickcheck! {
             #[allow(trivial_casts)]
             fn hypot_same(l: V, r: V) -> bool {
-                Test::eq(
-                    &l.hypot(r),
-                    &f::Length::new::<meter>(l).hypot(f::Length::new::<meter>(r)).get::<meter>(),
-                )
+                Test::eq(&l.hypot(r),
+                    &f::Length::new::<meter>(l).hypot(f::Length::new::<meter>(r)).get::<meter>())
             }
         }
 
@@ -469,19 +467,13 @@ mod float {
         quickcheck! {
             #[allow(trivial_casts)]
             fn hypot_mixed(l: V, r: V) -> bool {
-                let fk = Test::approx_eq(
-                    &l.hypot(r),
-                    &f::Length::new::<meter>(l).hypot(k::Length::new::<meter>(r)).get::<meter>(),
-                );
-
-                let kf = Test::approx_eq(
-                    &l.hypot(r),
-                    &k::Length::new::<meter>(l).hypot(f::Length::new::<meter>(r)).get::<meter>(),
-                );
+                let fk = Test::approx_eq(&l.hypot(r),
+                    &f::Length::new::<meter>(l).hypot(k::Length::new::<meter>(r)).get::<meter>());
+                let kf = Test::approx_eq(&l.hypot(r),
+                    &k::Length::new::<meter>(l).hypot(f::Length::new::<meter>(r)).get::<meter>());
 
                 fk && kf
             }
-        }
-        }
+        }}
     }
 }

@adamreichold
Copy link
Contributor Author

adamreichold commented May 12, 2020

If you could apply some minor formatting changes from the diff below I'll merge!

Done. On a related note, I enabled the "Allow edits by maintainers" checkbox since personally, I have no issue with you doing things like renames or reformats as per the maintainer's prerogative.

@iliekturtles iliekturtles merged commit 861e080 into iliekturtles:master May 13, 2020
@iliekturtles
Copy link
Owner

Thanks again for this PR!

I haven't used the "Allow edits by maintainers" before but will keep an eye on it for future PRs.

@adamreichold adamreichold deleted the generic-hypot branch May 13, 2020 19:55
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.

2 participants