diff --git a/.travis.yml b/.travis.yml index 98df6c3..6a7159d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,3 +26,6 @@ after_script: # the doc directory needs to be in the root for rust-ci - mv target/doc doc - curl http://www.rust-ci.org/artifacts/put?t=$RUSTCI_TOKEN | sh + +# http://docs.travis-ci.com/user/workers/container-based-infrastructure/ +sudo: false diff --git a/benches/common/macros.rs b/benches/common/macros.rs index 9c48c73..84f6bc2 100644 --- a/benches/common/macros.rs +++ b/benches/common/macros.rs @@ -1,5 +1,5 @@ // Copyright 2013-2014 The CGMath Developers. For a full listing of the authors, -// refer to the AUTHORS file at the top-level directionectory of this distribution. +// refer to the Cargo.toml file at the top-level directory of this distribution. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -21,8 +21,8 @@ macro_rules! bench_binop( let mut rng = IsaacRng::new_unseeded(); - let elems1: Vec<$t1> = range(0, LEN).map(|_| rng.gen::<$t1>()).collect(); - let elems2: Vec<$t2> = range(0, LEN).map(|_| rng.gen::<$t2>()).collect(); + let elems1: Vec<$t1> = (0..LEN).map(|_| rng.gen::<$t1>()).collect(); + let elems2: Vec<$t2> = (0..LEN).map(|_| rng.gen::<$t2>()).collect(); let mut i = 0; bh.iter(|| { @@ -44,8 +44,8 @@ macro_rules! bench_binop_deref( let mut rng = IsaacRng::new_unseeded(); - let elems1: Vec<$t1> = range(0, LEN).map(|_| rng.gen::<$t1>()).collect(); - let elems2: Vec<$t2> = range(0, LEN).map(|_| rng.gen::<$t2>()).collect(); + let elems1: Vec<$t1> = (0..LEN).map(|_| rng.gen::<$t1>()).collect(); + let elems2: Vec<$t2> = (0..LEN).map(|_| rng.gen::<$t2>()).collect(); let mut i = 0; bh.iter(|| { @@ -67,7 +67,7 @@ macro_rules! bench_unop( let mut rng = IsaacRng::new_unseeded(); - let mut elems: Vec<$t> = range(0, LEN).map(|_| rng.gen::<$t>()).collect(); + let mut elems: Vec<$t> = (0..LEN).map(|_| rng.gen::<$t>()).collect(); let mut i = 0; bh.iter(|| { @@ -89,7 +89,7 @@ macro_rules! bench_construction( let mut rng = IsaacRng::new_unseeded(); - $(let $args: Vec<$types> = range(0, LEN).map(|_| rng.gen::<$types>()).collect();)* + $(let $args: Vec<$types> = (0..LEN).map(|_| rng.gen::<$types>()).collect();)* let mut i = 0; bh.iter(|| { diff --git a/benches/construction.rs b/benches/construction.rs index de96c89..c0ed7c9 100644 --- a/benches/construction.rs +++ b/benches/construction.rs @@ -1,5 +1,5 @@ // Copyright 2013-2014 The CGMath Developers. For a full listing of the authors, -// refer to the AUTHORS file at the top-level directionectory of this distribution. +// refer to the Cargo.toml file at the top-level directory of this distribution. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -20,7 +20,6 @@ extern crate test; extern crate cgmath; use rand::{IsaacRng, Rng}; -use std::iter; use test::Bencher; use cgmath::{Quaternion, Basis2, Basis3, Vector3, Rotation2, Rotation3, Rad}; @@ -32,8 +31,8 @@ fn bench_from_axis_angle>(bh: &mut Bencher) { let mut rng = IsaacRng::new_unseeded(); - let axis: Vec<_> = iter::range(0, LEN).map(|_| rng.gen::>()).collect(); - let angle: Vec<_> = iter::range(0, LEN).map(|_| rng.gen::>()).collect(); + let axis: Vec<_> = (0..LEN).map(|_| rng.gen::>()).collect(); + let angle: Vec<_> = (0..LEN).map(|_| rng.gen::>()).collect(); let mut i = 0; bh.iter(|| { diff --git a/benches/mat.rs b/benches/mat.rs index 8c64ba3..225b98d 100644 --- a/benches/mat.rs +++ b/benches/mat.rs @@ -1,5 +1,5 @@ // Copyright 2013-2014 The CGMath Developers. For a full listing of the authors, -// refer to the AUTHORS file at the top-level directionectory of this distribution. +// refer to the Cargo.toml file at the top-level directory of this distribution. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/benches/quat.rs b/benches/quat.rs index 7474b29..1993609 100644 --- a/benches/quat.rs +++ b/benches/quat.rs @@ -1,5 +1,5 @@ // Copyright 2013-2014 The CGMath Developers. For a full listing of the authors, -// refer to the AUTHORS file at the top-level directionectory of this distribution. +// refer to the Cargo.toml file at the top-level directory of this distribution. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/benches/vec.rs b/benches/vec.rs index ec692bb..028fa30 100644 --- a/benches/vec.rs +++ b/benches/vec.rs @@ -1,5 +1,5 @@ // Copyright 2013-2014 The CGMath Developers. For a full listing of the authors, -// refer to the AUTHORS file at the top-level directionectory of this distribution. +// refer to the Cargo.toml file at the top-level directory of this distribution. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/src/aabb.rs b/src/aabb.rs index b0d1846..5b28ad8 100644 --- a/src/aabb.rs +++ b/src/aabb.rs @@ -1,5 +1,5 @@ // Copyright 2013-2014 The CGMath Developers. For a full listing of the authors, -// refer to the AUTHORS file at the top-level directory of this distribution. +// refer to the Cargo.toml file at the top-level directory of this distribution. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -201,43 +201,40 @@ impl fmt::Debug for Aabb3 { impl Intersect>> for (Ray2, Aabb2) { fn intersection(&self) -> Option> { - match *self { - (ref ray, ref aabb) => { + let (ref ray, ref aabb) = *self; - let mut tmin: S = Float::neg_infinity(); - let mut tmax: S = Float::infinity(); + let mut tmin: S = Float::neg_infinity(); + let mut tmax: S = Float::infinity(); - if ray.direction.x != zero() { - let tx1 = (aabb.min.x - ray.origin.x) / ray.direction.x; - let tx2 = (aabb.max.x - ray.origin.x) / ray.direction.x; - tmin = tmin.max(tx1.min(tx2)); - tmax = tmax.min(tx1.max(tx2)); - } + if ray.direction.x != zero() { + let tx1 = (aabb.min.x - ray.origin.x) / ray.direction.x; + let tx2 = (aabb.max.x - ray.origin.x) / ray.direction.x; + tmin = tmin.max(tx1.min(tx2)); + tmax = tmax.min(tx1.max(tx2)); + } - if ray.direction.y != zero() { - let ty1 = (aabb.min.y - ray.origin.y) / ray.direction.y; - let ty2 = (aabb.max.y - ray.origin.y) / ray.direction.y; - tmin = tmin.max(ty1.min(ty2)); - tmax = tmax.min(ty1.max(ty2)); - } + if ray.direction.y != zero() { + let ty1 = (aabb.min.y - ray.origin.y) / ray.direction.y; + let ty2 = (aabb.max.y - ray.origin.y) / ray.direction.y; + tmin = tmin.max(ty1.min(ty2)); + tmax = tmax.min(ty1.max(ty2)); + } - if tmin < zero() && tmax < zero() { - None - } - else if tmax >= tmin { - if tmin >= zero() { - Some(Point2::new(ray.origin.x + ray.direction.x * tmin, - ray.origin.y + ray.direction.y * tmin)) - } - else { - Some(Point2::new(ray.origin.x + ray.direction.x * tmax, - ray.origin.y + ray.direction.y * tmax)) - } - } - else { - None - } + if tmin < zero() && tmax < zero() { + None + } + else if tmax >= tmin { + if tmin >= zero() { + Some(Point2::new(ray.origin.x + ray.direction.x * tmin, + ray.origin.y + ray.direction.y * tmin)) } + else { + Some(Point2::new(ray.origin.x + ray.direction.x * tmax, + ray.origin.y + ray.direction.y * tmax)) + } + } + else { + None } } } diff --git a/src/angle.rs b/src/angle.rs index eacd671..d5df99f 100644 --- a/src/angle.rs +++ b/src/angle.rs @@ -1,5 +1,5 @@ // Copyright 2013-2014 The CGMath Developers. For a full listing of the authors, -// refer to the AUTHORS file at the top-level directory of this distribution. +// refer to the Cargo.toml file at the top-level directory of this distribution. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/src/approx.rs b/src/approx.rs index fd5c89e..1531850 100644 --- a/src/approx.rs +++ b/src/approx.rs @@ -1,5 +1,5 @@ // Copyright 2014 The CGMath Developers. For a full listing of the authors, -// refer to the AUTHORS file at the top-level directory of this distribution. +// refer to the Cargo.toml file at the top-level directory of this distribution. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/src/array.rs b/src/array.rs index 843d095..f5ce491 100644 --- a/src/array.rs +++ b/src/array.rs @@ -1,5 +1,5 @@ // Copyright 2013 The OMath Developers. For a full listing of the authors, -// refer to the AUTHORS file at the top-level directory of this distribution. +// refer to the Cargo.toml file at the top-level directory of this distribution. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/src/cylinder.rs b/src/cylinder.rs index 22d2dfd..ec0e444 100644 --- a/src/cylinder.rs +++ b/src/cylinder.rs @@ -1,5 +1,5 @@ // Copyright 2013 The CGMath Developers. For a full listing of the authors, -// refer to the AUTHORS file at the top-level directory of this distribution. +// refer to the Cargo.toml file at the top-level directory of this distribution. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/src/frustum.rs b/src/frustum.rs index e9e4468..6580702 100644 --- a/src/frustum.rs +++ b/src/frustum.rs @@ -1,5 +1,5 @@ // Copyright 2013-2014 The CGMath Developers. For a full listing of the authors, -// refer to the AUTHORS file at the top-level directory of this distribution. +// refer to the Cargo.toml file at the top-level directory of this distribution. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/src/intersect.rs b/src/intersect.rs index 51ce852..e3cce18 100644 --- a/src/intersect.rs +++ b/src/intersect.rs @@ -1,5 +1,5 @@ // Copyright 2013 The CGMath Developers. For a full listing of the authors, -// refer to the AUTHORS file at the top-level directory of this distribution. +// refer to the Cargo.toml file at the top-level directory of this distribution. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/src/lib.rs b/src/lib.rs index f1eb8ef..9a49f5b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,5 @@ // Copyright 2013-2014 The CGMath Developers. For a full listing of the authors, -// refer to the AUTHORS file at the top-level directory of this distribution. +// refer to the Cargo.toml file at the top-level directory of this distribution. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/src/line.rs b/src/line.rs index f225071..595faf6 100644 --- a/src/line.rs +++ b/src/line.rs @@ -1,5 +1,5 @@ // Copyright 2013-2014 The CGMath Developers. For a full listing of the authors, -// refer to the AUTHORS file at the top-level directionectory of this distribution. +// refer to the Cargo.toml file at the top-level directory of this distribution. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -38,56 +38,54 @@ impl, P: Point> Line

{ pub type Line2 = Line>; pub type Line3 = Line>; -/// Determines if an intersection between a ray and a line segments is found. +/// Determines if an intersection between a ray and a line segment is found. impl Intersect>> for (Ray2, Line2) { fn intersection(&self) -> Option> { - match *self { - (ref ray, ref line) => { - let p = ray.origin; - let q = line.origin; - let r = ray.direction; - let s = Vector2::new(line.dest.x - line.origin.x, line.dest.y - line.origin.y); - let zero: S = Zero::zero(); + let (ref ray, ref line) = *self; - let cross_1 = r.perp_dot(&s); - let qmp = Vector2::new(q.x - p.x, q.y - p.y); - let cross_2 = qmp.perp_dot(&r); + let p = ray.origin; + let q = line.origin; + let r = ray.direction; + let s = Vector2::new(line.dest.x - line.origin.x, line.dest.y - line.origin.y); + let zero: S = Zero::zero(); - if cross_1 == zero { - if cross_2 != zero { - // parallel - return None; - } - - // collinear - let q2mp = Vector2::new(line.dest.x - p.x, line.dest.y - p.y); - let dot_1 = qmp.dot(&r); - let dot_2 = q2mp.dot(&r); - if (dot_1 <= zero && dot_2 >= zero) || (dot_1 >= zero && dot_2 <= zero) { - return Some(p); - } - else if dot_1 >= zero && dot_2 >= zero { - if dot_1 <= dot_2 { - return Some(q); - } - else { - return Some(line.dest); - } - } - - // no overlap exists - return None; - } - - let t = qmp.perp_dot(&s) / cross_1; - let u = cross_2 / cross_1; - - if zero <= t && u >= zero && u <= One::one() { - return Some(Point2::new(p.x + t*r.x, p.y + t*r.y)); - } + let cross_1 = r.perp_dot(&s); + let qmp = Vector2::new(q.x - p.x, q.y - p.y); + let cross_2 = qmp.perp_dot(&r); + if cross_1 == zero { + if cross_2 != zero { + // parallel return None; } + + // collinear + let q2mp = Vector2::new(line.dest.x - p.x, line.dest.y - p.y); + let dot_1 = qmp.dot(&r); + let dot_2 = q2mp.dot(&r); + if (dot_1 <= zero && dot_2 >= zero) || (dot_1 >= zero && dot_2 <= zero) { + return Some(p); + } + else if dot_1 >= zero && dot_2 >= zero { + if dot_1 <= dot_2 { + return Some(q); + } + else { + return Some(line.dest); + } + } + + // no overlap exists + return None; } + + let t = qmp.perp_dot(&s) / cross_1; + let u = cross_2 / cross_1; + + if zero <= t && u >= zero && u <= One::one() { + return Some(Point2::new(p.x + t*r.x, p.y + t*r.y)); + } + + return None; } } diff --git a/src/matrix.rs b/src/matrix.rs index 18a1b66..9a10ab6 100644 --- a/src/matrix.rs +++ b/src/matrix.rs @@ -1,5 +1,5 @@ // Copyright 2013-2014 The CGMath Developers. For a full listing of the authors, -// refer to the AUTHORS file at the top-level directory of this distribution. +// refer to the Cargo.toml file at the top-level directory of this distribution. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -1344,43 +1344,39 @@ impl ToQuaternion for Matrix3 { // http://www.cs.ucr.edu/~vbz/resources/quatut.pdf let trace = self.trace(); let half: S = cast(0.5f64).unwrap(); - match () { - () if trace >= zero::() => { - let s = (one::() + trace).sqrt(); - let w = half * s; - let s = half / s; - let x = (self[1][2] - self[2][1]) * s; - let y = (self[2][0] - self[0][2]) * s; - let z = (self[0][1] - self[1][0]) * s; - Quaternion::new(w, x, y, z) - } - () if (self[0][0] > self[1][1]) && (self[0][0] > self[2][2]) => { - let s = (half + (self[0][0] - self[1][1] - self[2][2])).sqrt(); - let w = half * s; - let s = half / s; - let x = (self[0][1] - self[1][0]) * s; - let y = (self[2][0] - self[0][2]) * s; - let z = (self[1][2] - self[2][1]) * s; - Quaternion::new(w, x, y, z) - } - () if self[1][1] > self[2][2] => { - let s = (half + (self[1][1] - self[0][0] - self[2][2])).sqrt(); - let w = half * s; - let s = half / s; - let x = (self[0][1] - self[1][0]) * s; - let y = (self[1][2] - self[2][1]) * s; - let z = (self[2][0] - self[0][2]) * s; - Quaternion::new(w, x, y, z) - } - () => { - let s = (half + (self[2][2] - self[0][0] - self[1][1])).sqrt(); - let w = half * s; - let s = half / s; - let x = (self[2][0] - self[0][2]) * s; - let y = (self[1][2] - self[2][1]) * s; - let z = (self[0][1] - self[1][0]) * s; - Quaternion::new(w, x, y, z) - } + + if trace >= zero::() { + let s = (one::() + trace).sqrt(); + let w = half * s; + let s = half / s; + let x = (self[1][2] - self[2][1]) * s; + let y = (self[2][0] - self[0][2]) * s; + let z = (self[0][1] - self[1][0]) * s; + Quaternion::new(w, x, y, z) + } else if (self[0][0] > self[1][1]) && (self[0][0] > self[2][2]) { + let s = (half + (self[0][0] - self[1][1] - self[2][2])).sqrt(); + let w = half * s; + let s = half / s; + let x = (self[0][1] - self[1][0]) * s; + let y = (self[2][0] - self[0][2]) * s; + let z = (self[1][2] - self[2][1]) * s; + Quaternion::new(w, x, y, z) + } else if self[1][1] > self[2][2] { + let s = (half + (self[1][1] - self[0][0] - self[2][2])).sqrt(); + let w = half * s; + let s = half / s; + let x = (self[0][1] - self[1][0]) * s; + let y = (self[1][2] - self[2][1]) * s; + let z = (self[2][0] - self[0][2]) * s; + Quaternion::new(w, x, y, z) + } else { + let s = (half + (self[2][2] - self[0][0] - self[1][1])).sqrt(); + let w = half * s; + let s = half / s; + let x = (self[2][0] - self[0][2]) * s; + let y = (self[1][2] - self[2][1]) * s; + let z = (self[0][1] - self[1][0]) * s; + Quaternion::new(w, x, y, z) } } } diff --git a/src/num.rs b/src/num.rs index 4839d45..7de7ebf 100644 --- a/src/num.rs +++ b/src/num.rs @@ -1,5 +1,5 @@ // Copyright 2013-2014 The CGMath Developers. For a full listing of the authors, -// refer to the AUTHORS file at the top-level directory of this distribution. +// refer to the Cargo.toml file at the top-level directory of this distribution. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/src/obb.rs b/src/obb.rs index eefe5a4..f5f4e8b 100644 --- a/src/obb.rs +++ b/src/obb.rs @@ -1,5 +1,5 @@ // Copyright 2013 The CGMath Developers. For a full listing of the authors, -// refer to the AUTHORS file at the top-level directory of this distribution. +// refer to the Cargo.toml file at the top-level directory of this distribution. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/src/plane.rs b/src/plane.rs index 909045e..72251ab 100644 --- a/src/plane.rs +++ b/src/plane.rs @@ -1,5 +1,5 @@ // Copyright 2013-2014 The CGMath Developers. For a full listing of the authors, -// refer to the AUTHORS file at the top-level directory of this distribution. +// refer to the Cargo.toml file at the top-level directory of this distribution. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -111,13 +111,11 @@ impl Plane { impl Intersect>> for (Plane, Ray3) { fn intersection(&self) -> Option> { - match *self { - (ref p, ref r) => { - let t = -(p.d + r.origin.dot(&p.n)) / r.direction.dot(&p.n); - if t < Zero::zero() { None } - else { Some(r.origin.add_v(&r.direction.mul_s(t))) } - } - } + let (ref p, ref r) = *self; + + let t = -(p.d + r.origin.dot(&p.n)) / r.direction.dot(&p.n); + if t < Zero::zero() { None } + else { Some(r.origin.add_v(&r.direction.mul_s(t))) } } } diff --git a/src/point.rs b/src/point.rs index ab854dd..27697c0 100644 --- a/src/point.rs +++ b/src/point.rs @@ -1,5 +1,5 @@ // Copyright 2013-2014 The CGMath Developers. For a full listing of the authors, -// refer to the AUTHORS file at the top-level directory of this distribution. +// refer to the Cargo.toml file at the top-level directory of this distribution. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/src/projection.rs b/src/projection.rs index 2ff1553..e1ed503 100644 --- a/src/projection.rs +++ b/src/projection.rs @@ -1,5 +1,5 @@ // Copyright 2013-2014 The CGMath Developers. For a full listing of the authors, -// refer to the AUTHORS file at the top-level directory of this distribution. +// refer to the Cargo.toml file at the top-level directory of this distribution. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/src/quaternion.rs b/src/quaternion.rs index bcc2d26..fdbe73e 100644 --- a/src/quaternion.rs +++ b/src/quaternion.rs @@ -1,5 +1,5 @@ // Copyright 2013-2014 The CGMath Developers. For a full listing of the authors, -// refer to the AUTHORS file at the top-level directory of this distribution. +// refer to the Cargo.toml file at the top-level directory of this distribution. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/src/ray.rs b/src/ray.rs index 4d4e28d..6490e20 100644 --- a/src/ray.rs +++ b/src/ray.rs @@ -1,5 +1,5 @@ // Copyright 2013-2014 The CGMath Developers. For a full listing of the authors, -// refer to the AUTHORS file at the top-level directionectory of this distribution. +// refer to the Cargo.toml file at the top-level directory of this distribution. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/src/rotation.rs b/src/rotation.rs index efb2d11..2a45328 100644 --- a/src/rotation.rs +++ b/src/rotation.rs @@ -1,5 +1,5 @@ // Copyright 2014 The CGMath Developers. For a full listing of the authors, -// refer to the AUTHORS file at the top-level directory of this distribution. +// refer to the Cargo.toml file at the top-level directory of this distribution. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -132,7 +132,7 @@ pub trait Rotation3: Rotation, Point3> /// angle. We can accomplish this quite easily with a two-dimensional rotation /// matrix: /// -/// ~~~ignore +/// ```no_run /// use cgmath::rad; /// use cgmath::Vector2; /// use cgmath::{Matrix, ToMatrix2}; @@ -160,7 +160,7 @@ pub trait Rotation3: Rotation, Point3> /// let rot_half: Basis2 = Rotation2::from_angle(rad(0.25f64 * f64::consts::PI)); /// let unit_y3 = rot_half.concat(&rot_half).rotate_vector(&unit_x); /// assert!(unit_y3.approx_eq(&unit_y2)); -/// ~~~ +/// ``` #[derive(PartialEq, Copy, Clone, RustcEncodable, RustcDecodable)] pub struct Basis2 { mat: Matrix2 diff --git a/src/sphere.rs b/src/sphere.rs index 61565ac..b297aec 100644 --- a/src/sphere.rs +++ b/src/sphere.rs @@ -1,5 +1,5 @@ // Copyright 2013-2014 The CGMath Developers. For a full listing of the authors, -// refer to the AUTHORS file at the top-level directory of this distribution. +// refer to the Cargo.toml file at the top-level directory of this distribution. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -31,17 +31,15 @@ pub struct Sphere { impl Intersect>> for (Sphere, Ray3) { fn intersection(&self) -> Option> { - match *self { - (ref s, ref r) => { - let l = s.center.sub_p(&r.origin); - let tca = l.dot(&r.direction); - if tca < zero() { return None; } - let d2 = l.dot(&l) - tca*tca; - if d2 > s.radius*s.radius { return None; } - let thc = (s.radius*s.radius - d2).sqrt(); - Some(r.origin.add_v(&r.direction.mul_s(tca - thc))) - } - } + let (ref s, ref r) = *self; + + let l = s.center.sub_p(&r.origin); + let tca = l.dot(&r.direction); + if tca < zero() { return None; } + let d2 = l.dot(&l) - tca*tca; + if d2 > s.radius*s.radius { return None; } + let thc = (s.radius*s.radius - d2).sqrt(); + Some(r.origin.add_v(&r.direction.mul_s(tca - thc))) } } diff --git a/src/transform.rs b/src/transform.rs index 48e966e..936b3af 100644 --- a/src/transform.rs +++ b/src/transform.rs @@ -1,5 +1,5 @@ // Copyright 2014 The CGMath Developers. For a full listing of the authors, -// refer to the AUTHORS file at the top-level directory of this distribution. +// refer to the Cargo.toml file at the top-level directory of this distribution. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/src/vector.rs b/src/vector.rs index 897d49f..5b33aa3 100644 --- a/src/vector.rs +++ b/src/vector.rs @@ -1,5 +1,5 @@ // Copyright 2013-2014 The CGMath Developers. For a full listing of the authors, -// refer to the AUTHORS file at the top-level directory of this distribution. +// refer to the Cargo.toml file at the top-level directory of this distribution. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/tests/aabb.rs b/tests/aabb.rs index 41cf0db..63f0449 100644 --- a/tests/aabb.rs +++ b/tests/aabb.rs @@ -1,5 +1,5 @@ // Copyright 2014 The CGMath Developers. For a full listing of the authors, -// refer to the AUTHORS file at the top-level directory of this distribution. +// refer to the Cargo.toml file at the top-level directory of this distribution. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/tests/angle.rs b/tests/angle.rs index 8e2b028..e8a1224 100644 --- a/tests/angle.rs +++ b/tests/angle.rs @@ -1,5 +1,5 @@ // Copyright 2013-2014 The CGMath Developers. For a full listing of the authors, -// refer to the AUTHORS file at the top-level directory of this distribution. +// refer to the Cargo.toml file at the top-level directory of this distribution. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/tests/approx.rs b/tests/approx.rs index c5194cc..2f94a31 100644 --- a/tests/approx.rs +++ b/tests/approx.rs @@ -1,5 +1,5 @@ // Copyright 2014 The CGMath Developers. For a full listing of the authors, -// refer to the AUTHORS file at the top-level directory of this distribution. +// refer to the Cargo.toml file at the top-level directory of this distribution. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -24,7 +24,7 @@ fn macro_assert_approx_eq_eps() { } #[test] -#[should_fail] +#[should_panic] fn macro_assert_approx_eq_eps_fail() { assert_approx_eq_eps!(1.0f32, 1.02, 0.01); } @@ -35,7 +35,7 @@ fn macro_assert_approx_eq() { } #[test] -#[should_fail] +#[should_panic] fn macro_assert_approx_eq_fail() { assert_approx_eq!(1.0f64 / 3.0, 0.333); } diff --git a/tests/line.rs b/tests/line.rs index 280b38a..e9f1c00 100644 --- a/tests/line.rs +++ b/tests/line.rs @@ -1,5 +1,5 @@ // Copyright 2013-2014 The CGMath Developers. For a full listing of the authors, -// refer to the AUTHORS file at the top-level directory of this distribution. +// refer to the Cargo.toml file at the top-level directory of this distribution. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/tests/matrix.rs b/tests/matrix.rs index 5e698cb..08d93cb 100644 --- a/tests/matrix.rs +++ b/tests/matrix.rs @@ -1,5 +1,5 @@ // Copyright 2013-2014 The CGMath Developers. For a full listing of the authors, -// refer to the AUTHORS file at the top-level directory of this distribution. +// refer to the Cargo.toml file at the top-level directory of this distribution. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/tests/plane.rs b/tests/plane.rs index 48ab8b8..9d2e734 100644 --- a/tests/plane.rs +++ b/tests/plane.rs @@ -1,5 +1,5 @@ // Copyright 2013-2014 The CGMath Developers. For a full listing of the authors, -// refer to the AUTHORS file at the top-level directory of this distribution. +// refer to the Cargo.toml file at the top-level directory of this distribution. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/tests/point.rs b/tests/point.rs index 5f65f3c..77385d4 100644 --- a/tests/point.rs +++ b/tests/point.rs @@ -1,5 +1,5 @@ // Copyright 2013-2014 The CGMath Developers. For a full listing of the authors, -// refer to the AUTHORS file at the top-level directory of this distribution. +// refer to the Cargo.toml file at the top-level directory of this distribution. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/tests/projection.rs b/tests/projection.rs index 7e4d788..5d8ff20 100644 --- a/tests/projection.rs +++ b/tests/projection.rs @@ -1,5 +1,5 @@ // Copyright 2013-2014 The CGMath Developers. For a full listing of the authors, -// refer to the AUTHORS file at the top-level directory of this distribution. +// refer to the Cargo.toml file at the top-level directory of this distribution. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/tests/quaternion.rs b/tests/quaternion.rs index b0bb90b..05c46f7 100644 --- a/tests/quaternion.rs +++ b/tests/quaternion.rs @@ -1,5 +1,5 @@ // Copyright 2013-2014 The CGMath Developers. For a full listing of the authors, -// refer to the AUTHORS file at the top-level directory of this distribution. +// refer to the Cargo.toml file at the top-level directory of this distribution. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/tests/rotation.rs b/tests/rotation.rs new file mode 100644 index 0000000..c44df49 --- /dev/null +++ b/tests/rotation.rs @@ -0,0 +1,43 @@ +// Copyright 2015 The CGMath Developers. For a full listing of the authors, +// refer to the Cargo.toml file at the top-level directory of this distribution. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// 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. + +extern crate cgmath; + +use cgmath::*; + +mod rotation { + use super::cgmath::*; + + pub fn a2>() -> R { + Rotation2::from_angle(deg(30.0).to_rad()) + } + + pub fn a3>() -> R { + let axis = Vector3::new(1.0, 1.0, 0.0).normalize(); + Rotation3::from_axis_angle(&axis, deg(30.0).to_rad()) + } +} + +#[test] +fn test_invert_basis2() { + let a: Basis2<_> = rotation::a2(); + assert!(a.concat(&a.invert()).as_matrix2().is_identity()); +} + +#[test] +fn test_invert_basis3() { + let a: Basis3<_> = rotation::a3(); + assert!(a.concat(&a.invert()).as_matrix3().is_identity()); +} diff --git a/tests/sphere.rs b/tests/sphere.rs index a3f61eb..55d8415 100644 --- a/tests/sphere.rs +++ b/tests/sphere.rs @@ -1,5 +1,5 @@ // Copyright 2014 The CGMath Developers. For a full listing of the authors, -// refer to the AUTHORS file at the top-level directory of this distribution. +// refer to the Cargo.toml file at the top-level directory of this distribution. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/tests/transform.rs b/tests/transform.rs index 64683e2..a46f6fb 100644 --- a/tests/transform.rs +++ b/tests/transform.rs @@ -1,5 +1,5 @@ // Copyright 2014 The CGMath Developers. For a full listing of the authors, -// refer to the AUTHORS file at the top-level directory of this distribution. +// refer to the Cargo.toml file at the top-level directory of this distribution. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/tests/vector.rs b/tests/vector.rs index 852b97d..0be7926 100644 --- a/tests/vector.rs +++ b/tests/vector.rs @@ -1,5 +1,5 @@ // Copyright 2013-2014 The CGMath Developers. For a full listing of the authors, -// refer to the AUTHORS file at the top-level directory of this distribution. +// refer to the Cargo.toml file at the top-level directory of this distribution. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License.