diff --git a/src/angle.rs b/src/angle.rs index df34dbc..169fd8a 100644 --- a/src/angle.rs +++ b/src/angle.rs @@ -16,7 +16,7 @@ //! Angle units for type-safe, self-documenting code. use std::fmt; -use std::num::{One, one, Zero, zero, cast}; +use std::num::{One, one, Zero, zero, cast, Float}; use approx::ApproxEq; use num::BaseFloat; diff --git a/src/approx.rs b/src/approx.rs index 13cc2dc..e412d3a 100644 --- a/src/approx.rs +++ b/src/approx.rs @@ -14,6 +14,7 @@ // limitations under the License. use std::num; +use std::num::Float; pub trait ApproxEq { fn approx_epsilon(_hack: Option) -> T { @@ -34,7 +35,7 @@ macro_rules! approx_float( impl ApproxEq<$S> for $S { #[inline] fn approx_eq_eps(&self, other: &$S, epsilon: &$S) -> bool { - num::abs(*self - *other) < *epsilon + (*self - *other).abs() < *epsilon } } ) diff --git a/src/num.rs b/src/num.rs index 65b4562..72cdb16 100644 --- a/src/num.rs +++ b/src/num.rs @@ -17,6 +17,7 @@ use approx::ApproxEq; use std::cmp; use std::fmt; +use std::num::{FloatMath, Int, Primitive}; /// A trait providing a [partial ordering](http://mathworld.wolfram.com/PartialOrder.html). pub trait PartialOrd { diff --git a/src/quaternion.rs b/src/quaternion.rs index 676210b..62c4a32 100644 --- a/src/quaternion.rs +++ b/src/quaternion.rs @@ -15,7 +15,7 @@ use std::fmt; use std::mem; -use std::num::{zero, one, cast}; +use std::num::{zero, one, cast, Float}; use angle::{Angle, Rad, acos, sin, sin_cos, rad}; use approx::ApproxEq; @@ -266,7 +266,7 @@ impl Quaternion { /// Convert a Quaternion to Eular angles /// This is a polar singularity aware conversion - /// + /// /// Based on: /// - [Maths - Conversion Quaternion to Euler] /// (http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToEuler/) @@ -280,7 +280,7 @@ impl Quaternion { let unit = sqx + sqy + sqz + sqw; let test = qx*qy + qz*qw; - + if test > sig * unit { ( rad(zero::()), diff --git a/src/rotation.rs b/src/rotation.rs index 006826c..fc7c1be 100644 --- a/src/rotation.rs +++ b/src/rotation.rs @@ -138,6 +138,7 @@ pub trait Rotation3: Rotation, Point3> /// use cgmath::{Matrix, ToMatrix2}; /// use cgmath::{Rotation, Rotation2, Basis2}; /// use cgmath::ApproxEq; +/// use std::num::Float; /// /// // For simplicity, we will rotate the unit x vector to the unit y vector -- /// // so the angle is 90 degrees, or π/2. diff --git a/tests/matrix.rs b/tests/matrix.rs index 2e443bb..7a6ad08 100644 --- a/tests/matrix.rs +++ b/tests/matrix.rs @@ -18,6 +18,7 @@ extern crate cgmath; use cgmath::*; +use std::num::Float; pub mod matrix2 { use cgmath::*; diff --git a/tests/quaternion.rs b/tests/quaternion.rs index 781e6fe..a4e948f 100644 --- a/tests/quaternion.rs +++ b/tests/quaternion.rs @@ -23,6 +23,8 @@ use cgmath::Quaternion; use cgmath::{Rad, rad, ApproxEq}; use cgmath::Rotation3; +use std::num::Float; + #[test] fn to_matrix4() { diff --git a/tests/sphere.rs b/tests/sphere.rs index 2651423..05aec67 100644 --- a/tests/sphere.rs +++ b/tests/sphere.rs @@ -18,6 +18,7 @@ extern crate cgmath; use cgmath::*; +use std::num::FloatMath; #[test] fn test_intersection() { diff --git a/tests/vector.rs b/tests/vector.rs index c541ced..0d74a7e 100644 --- a/tests/vector.rs +++ b/tests/vector.rs @@ -18,6 +18,7 @@ extern crate cgmath; use cgmath::*; +use std::num::{Float, FloatMath}; #[test] fn test_from_value() {