Merge pull request #193 from neuschaefer/dev

Various little changes.
This commit is contained in:
Dzmitry Malyshau 2015-03-19 21:37:33 +03:00
commit 182f7b41dc
40 changed files with 213 additions and 181 deletions

View file

@ -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

View file

@ -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(|| {

View file

@ -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<T: Rotation3<f32>>(bh: &mut Bencher) {
let mut rng = IsaacRng::new_unseeded();
let axis: Vec<_> = iter::range(0, LEN).map(|_| rng.gen::<Vector3<f32>>()).collect();
let angle: Vec<_> = iter::range(0, LEN).map(|_| rng.gen::<Rad<f32>>()).collect();
let axis: Vec<_> = (0..LEN).map(|_| rng.gen::<Vector3<f32>>()).collect();
let angle: Vec<_> = (0..LEN).map(|_| rng.gen::<Rad<f32>>()).collect();
let mut i = 0;
bh.iter(|| {

View file

@ -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.

View file

@ -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.

View file

@ -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.

View file

@ -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<S: BaseNum> fmt::Debug for Aabb3<S> {
impl<S: BaseFloat> Intersect<Option<Point2<S>>> for (Ray2<S>, Aabb2<S>) {
fn intersection(&self) -> Option<Point2<S>> {
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
}
}
}

View file

@ -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.

View file

@ -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.

View file

@ -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.

View file

@ -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.

View file

@ -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.

View file

@ -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.

View file

@ -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.

View file

@ -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<S: BaseNum, V: Vector<S>, P: Point<S, V>> Line<P> {
pub type Line2<S> = Line<Point2<S>>;
pub type Line3<S> = Line<Point3<S>>;
/// 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<S: BaseFloat> Intersect<Option<Point2<S>>> for (Ray2<S>, Line2<S>) {
fn intersection(&self) -> Option<Point2<S>> {
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;
}
}

View file

@ -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<S: BaseFloat + 'static> ToQuaternion<S> for Matrix3<S> {
// http://www.cs.ucr.edu/~vbz/resources/quatut.pdf
let trace = self.trace();
let half: S = cast(0.5f64).unwrap();
match () {
() if trace >= zero::<S>() => {
let s = (one::<S>() + 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::<S>() {
let s = (one::<S>() + 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)
}
}
}

View file

@ -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.

View file

@ -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.

View file

@ -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<S: BaseFloat> Plane<S> {
impl<S: BaseFloat> Intersect<Option<Point3<S>>> for (Plane<S>, Ray3<S>) {
fn intersection(&self) -> Option<Point3<S>> {
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))) }
}
}

View file

@ -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.

View file

@ -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.

View file

@ -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.

View file

@ -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.

View file

@ -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<S: BaseNum>: Rotation<S, Vector3<S>, Point3<S>>
/// 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<S: BaseNum>: Rotation<S, Vector3<S>, Point3<S>>
/// let rot_half: Basis2<f64> = 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<S> {
mat: Matrix2<S>

View file

@ -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<S> {
impl<S: BaseFloat> Intersect<Option<Point3<S>>> for (Sphere<S>, Ray3<S>) {
fn intersection(&self) -> Option<Point3<S>> {
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)))
}
}

View file

@ -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.

View file

@ -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.

View file

@ -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.

View file

@ -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.

View file

@ -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);
}

View file

@ -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.

View file

@ -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.

View file

@ -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.

View file

@ -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.

View file

@ -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.

View file

@ -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.

43
tests/rotation.rs Normal file
View file

@ -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<f64>>() -> R {
Rotation2::from_angle(deg(30.0).to_rad())
}
pub fn a3<R: Rotation3<f64>>() -> 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());
}

View file

@ -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.

View file

@ -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.

View file

@ -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.