diff --git a/src/angle.rs b/src/angle.rs index da928f0..fa7191e 100644 --- a/src/angle.rs +++ b/src/angle.rs @@ -23,7 +23,7 @@ use std::ops::*; use rand::{Rand, Rng}; use rand::distributions::range::SampleRange; -use rust_num::{One, Zero, one, zero}; +use rust_num::{Float, One, Zero, one, zero}; use approx::ApproxEq; use num::BaseFloat; @@ -52,11 +52,27 @@ pub trait ToDeg { fn to_deg(&self) -> Deg; } -impl ToRad for Rad { #[inline] fn to_rad(&self) -> Rad { self.clone() } } -impl ToRad for Deg { #[inline] fn to_rad(&self) -> Rad { rad(self.s.to_radians()) } } +impl ToRad for Rad { + #[inline] + fn to_rad(&self) -> Rad { self.clone() } +} +impl ToRad for Deg { + #[inline] + fn to_rad(&self) -> Rad { + rad(self.s * cast(f64::consts::PI / 180.0).unwrap()) + } +} -impl ToDeg for Rad { #[inline] fn to_deg(&self) -> Deg { deg(self.s.to_degrees()) } } -impl ToDeg for Deg { #[inline] fn to_deg(&self) -> Deg { self.clone() } } +impl ToDeg for Rad { + #[inline] + fn to_deg(&self) -> Deg { + deg(self.s * cast(180.0 / f64::consts::PI).unwrap()) + } +} +impl ToDeg for Deg { + #[inline] + fn to_deg(&self) -> Deg { self.clone() } +} /// Private utility functions for converting to/from scalars trait ScalarConv { diff --git a/src/approx.rs b/src/approx.rs index f391c7e..5a12903 100644 --- a/src/approx.rs +++ b/src/approx.rs @@ -13,10 +13,10 @@ // See the License for the specific language governing permissions and // limitations under the License. -use std::num::cast; +use std::num::{NumCast, cast}; use rust_num::Float; -pub trait ApproxEq: Sized { +pub trait ApproxEq: Sized { fn approx_epsilon(_hack: Option) -> T { cast(1.0e-5f64).unwrap() } diff --git a/src/lib.rs b/src/lib.rs index c44f878..6d578ea 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -15,7 +15,7 @@ #![crate_type = "rlib"] #![crate_type = "dylib"] -#![feature(plugin, core, std_misc, custom_derive)] +#![feature(plugin, core, custom_derive)] //! Computer graphics-centric math. //! diff --git a/src/num.rs b/src/num.rs index e2e4a32..9d68a2d 100644 --- a/src/num.rs +++ b/src/num.rs @@ -17,9 +17,9 @@ use approx::ApproxEq; use std::cmp; use std::fmt; -use std::ops::*; +use std::num::NumCast; -use rust_num::{Float, Num, NumCast}; +use rust_num::{Float, Num}; /// A trait providing a [partial ordering](http://mathworld.wolfram.com/PartialOrder.html). pub trait PartialOrd { diff --git a/src/vector.rs b/src/vector.rs index af2ee69..03a9da3 100644 --- a/src/vector.rs +++ b/src/vector.rs @@ -98,11 +98,12 @@ use std::fmt; use std::mem; +use std::num::NumCast; use std::ops::*; use rand::{Rand, Rng}; -use rust_num::{NumCast, Zero, One, zero, one}; +use rust_num::{Zero, One, zero, one}; use angle::{Rad, atan2, acos}; use approx::ApproxEq;