From 3ee67019dd48ea4962289786e9390ec0c7318d84 Mon Sep 17 00:00:00 2001 From: ozkriff Date: Wed, 2 Apr 2014 13:24:04 +0400 Subject: [PATCH] Updated to latest Rust: math changes --- src/cgmath/angle.rs | 3 --- src/cgmath/matrix.rs | 10 +++++----- src/cgmath/quaternion.rs | 4 ++-- src/cgmath/sphere.rs | 2 +- src/cgmath/vector.rs | 4 ++-- src/test/sphere.rs | 5 ++--- src/test/test.rs | 4 ++-- 7 files changed, 14 insertions(+), 18 deletions(-) diff --git a/src/cgmath/angle.rs b/src/cgmath/angle.rs index 46e72e1..b80d363 100644 --- a/src/cgmath/angle.rs +++ b/src/cgmath/angle.rs @@ -15,9 +15,6 @@ //! Angle units for type-safe, self-documenting code. -pub use std::num::{sinh, cosh, tanh}; -pub use std::num::{asinh, acosh, atanh}; - use std::fmt; use std::num::{One, one, Zero, zero, cast}; diff --git a/src/cgmath/matrix.rs b/src/cgmath/matrix.rs index c1b4f60..e7596a7 100644 --- a/src/cgmath/matrix.rs +++ b/src/cgmath/matrix.rs @@ -16,7 +16,7 @@ //! Column major, square matrix types and traits. use std::fmt; -use std::num::{Zero, zero, One, one, cast, sqrt}; +use std::num::{Zero, zero, One, one, cast}; use angle::{Rad, sin, cos, sin_cos}; use approx::ApproxEq; @@ -684,7 +684,7 @@ ToQuat for Mat3 { let half: S = cast(0.5).unwrap(); match () { () if trace >= zero::() => { - let s = sqrt(one::() + trace); + let s = (one::() + trace).sqrt(); let w = half * s; let s = half / s; let x = (*self.cr(1, 2) - *self.cr(2, 1)) * s; @@ -693,7 +693,7 @@ ToQuat for Mat3 { Quat::new(w, x, y, z) } () if (*self.cr(0, 0) > *self.cr(1, 1)) && (*self.cr(0, 0) > *self.cr(2, 2)) => { - let s = sqrt(half + (*self.cr(0, 0) - *self.cr(1, 1) - *self.cr(2, 2))); + let s = (half + (*self.cr(0, 0) - *self.cr(1, 1) - *self.cr(2, 2))).sqrt(); let w = half * s; let s = half / s; let x = (*self.cr(0, 1) - *self.cr(1, 0)) * s; @@ -702,7 +702,7 @@ ToQuat for Mat3 { Quat::new(w, x, y, z) } () if *self.cr(1, 1) > *self.cr(2, 2) => { - let s = sqrt(half + (*self.cr(1, 1) - *self.cr(0, 0) - *self.cr(2, 2))); + let s = (half + (*self.cr(1, 1) - *self.cr(0, 0) - *self.cr(2, 2))).sqrt(); let w = half * s; let s = half / s; let x = (*self.cr(0, 1) - *self.cr(1, 0)) * s; @@ -711,7 +711,7 @@ ToQuat for Mat3 { Quat::new(w, x, y, z) } () => { - let s = sqrt(half + (*self.cr(2, 2) - *self.cr(0, 0) - *self.cr(1, 1))); + let s = (half + (*self.cr(2, 2) - *self.cr(0, 0) - *self.cr(1, 1))).sqrt(); let w = half * s; let s = half / s; let x = (*self.cr(2, 0) - *self.cr(0, 2)) * s; diff --git a/src/cgmath/quaternion.rs b/src/cgmath/quaternion.rs index d1807aa..10be2a1 100644 --- a/src/cgmath/quaternion.rs +++ b/src/cgmath/quaternion.rs @@ -14,7 +14,7 @@ // limitations under the License. use std::fmt; -use std::num::{zero, one, cast, sqrt}; +use std::num::{zero, one, cast}; use angle::{Angle, Rad, acos, sin, sin_cos}; use approx::ApproxEq; @@ -155,7 +155,7 @@ Quat { /// it is advisable to use the `magnitude2` method instead. #[inline] pub fn magnitude(&self) -> S { - sqrt(self.magnitude2()) + self.magnitude2().sqrt() } /// The normalized quaternion diff --git a/src/cgmath/sphere.rs b/src/cgmath/sphere.rs index 652e03a..191e1fd 100644 --- a/src/cgmath/sphere.rs +++ b/src/cgmath/sphere.rs @@ -43,7 +43,7 @@ impl> Intersect>> for (Sphere, Ray3) { if tca < cast(0.0) { return None; } let d2 = l.dot(&l) - tca*tca; if d2 > s.radius*s.radius { return None; } - let thc = num::sqrt(s.radius*s.radius - d2); + let thc = (s.radius*s.radius - d2).sqrt(); Some(r.origin.add_v(&r.direction.mul_s(tca - thc))) } } diff --git a/src/cgmath/vector.rs b/src/cgmath/vector.rs index eac8f4c..c95824f 100644 --- a/src/cgmath/vector.rs +++ b/src/cgmath/vector.rs @@ -14,7 +14,7 @@ // limitations under the License. use std::fmt; -use std::num::{Zero, zero, One, one, sqrt}; +use std::num::{Zero, zero, One, one}; use angle::{Rad, atan2, acos}; use approx::ApproxEq; @@ -230,7 +230,7 @@ pub trait EuclideanVector /// The norm of the vector. #[inline] fn length(&self) -> S { - sqrt(self.dot(self)) + self.dot(self).sqrt() } /// The angle between the vector and `other`. diff --git a/src/test/sphere.rs b/src/test/sphere.rs index a5a203e..f53d58b 100644 --- a/src/test/sphere.rs +++ b/src/test/sphere.rs @@ -4,17 +4,16 @@ use cgmath::vector::*; use cgmath::ray::*; use cgmath::approx::ApproxEq; use cgmath::intersect::Intersect; -use std::num; #[test] fn test_intersection() { let sphere = Sphere {center: Point3::new(0f64,0f64,0f64), radius: 1f64}; let r0 = Ray::new(Point3::new(0f64, 0f64, 5f64), Vec3::new(0f64, 0f64, -5f64).normalize()); - let r1 = Ray::new(Point3::new(num::cos(1f64), 0f64, 5f64), Vec3::new(0f64, 0f64, -5f64).normalize()); + let r1 = Ray::new(Point3::new(1f64.cos(), 0f64, 5f64), Vec3::new(0f64, 0f64, -5f64).normalize()); let r2 = Ray::new(Point3::new(1f64, 0f64, 5f64), Vec3::new(0f64, 0f64, -5f64).normalize()); let r3 = Ray::new(Point3::new(2f64, 0f64, 5f64), Vec3::new(0f64, 0f64, -5f64).normalize()); assert_eq!((sphere,r0).intersection(), Some(Point3::new(0f64, 0f64, 1f64))); - assert!((sphere,r1).intersection().unwrap().approx_eq( &Point3::new(num::cos(1f64), 0f64, num::sin(1f64)) )); + assert!((sphere,r1).intersection().unwrap().approx_eq( &Point3::new(1f64.cos(), 0f64, 1f64.sin()) )); assert_eq!((sphere,r2).intersection(), Some(Point3::new(1f64, 0f64, 0f64))); assert_eq!((sphere,r3).intersection(), None); } diff --git a/src/test/test.rs b/src/test/test.rs index 11db0c2..9449f1d 100644 --- a/src/test/test.rs +++ b/src/test/test.rs @@ -12,9 +12,9 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -#[feature(globs)]; +#![feature(globs)] -#[feature(globs)]; +#![feature(globs)] extern crate cgmath;