Skip to content

Commit

Permalink
Remove From/Into impls for Angle and SolidAngle.
Browse files Browse the repository at this point in the history
Impls were problematic because they assume the value is always in
radians. Using explicit conversions that include the unit should be used
instead. Impls were likely added when `Angle` was added and adapted from
`Ratio`. Resolves #188.
  • Loading branch information
iliekturtles committed Jul 27, 2020
1 parent 5dca5a6 commit 2cc5deb
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 80 deletions.
40 changes: 0 additions & 40 deletions src/si/angle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,38 +129,6 @@ where
}
}

mod convert {
use super::*;

impl<U, V> ::lib::convert::From<V> for Angle<U, V>
where
U: ::si::Units<V> + ?Sized,
V: ::num::Num + ::Conversion<V>,
{
fn from(t: V) -> Self {
Angle {
dimension: ::lib::marker::PhantomData,
units: ::lib::marker::PhantomData,
value: t,
}
}
}

storage_types! {
use super::*;

impl<U> ::lib::convert::From<Angle<U, V>> for V
where
U: ::si::Units<V> + ?Sized,
V: ::num::Num + ::Conversion<V>,
{
fn from(t: Angle<U, V>) -> Self {
t.value
}
}
}
}

#[cfg(test)]
mod tests {
storage_types! {
Expand All @@ -170,14 +138,6 @@ mod tests {
use si::quantities::*;
use tests::Test;

#[test]
fn from() {
let r1: Angle<V> = Angle::<V>::from(V::one());
let r2: Angle<V> = V::one().into();
let _: V = V::from(r1);
let _: V = r2.into();
}

#[test]
fn check_units() {
Test::assert_eq(&Angle::new::<a::radian>(V::from_f64(2.0 * PI).unwrap()),
Expand Down
40 changes: 0 additions & 40 deletions src/si/solid_angle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,38 +46,6 @@ impl SolidAngle<::si::SI<f64>, f64> {
};
}

mod convert {
use super::*;

impl<U, V> ::lib::convert::From<V> for SolidAngle<U, V>
where
U: ::si::Units<V> + ?Sized,
V: ::num::Num + ::Conversion<V>,
{
fn from(t: V) -> Self {
SolidAngle {
dimension: ::lib::marker::PhantomData,
units: ::lib::marker::PhantomData,
value: t,
}
}
}

storage_types! {
use super::*;

impl<U> ::lib::convert::From<SolidAngle<U, V>> for V
where
U: ::si::Units<V> + ?Sized,
V: ::num::Num + ::Conversion<V>,
{
fn from(t: SolidAngle<U, V>) -> Self {
t.value
}
}
}
}

#[cfg(test)]
mod tests {
storage_types! {
Expand All @@ -87,14 +55,6 @@ mod tests {
use si::quantities::*;
use tests::Test;

#[test]
fn from() {
let r1: SolidAngle<V> = SolidAngle::<V>::from(V::one());
let r2: SolidAngle<V> = V::one().into();
let _: V = V::from(r1);
let _: V = r2.into();
}

#[test]
fn check_units() {
Test::assert_eq(&SolidAngle::new::<sa::steradian>(V::from_f64(4.0 * PI).unwrap()),
Expand Down

0 comments on commit 2cc5deb

Please sign in to comment.