2013-05-19 01:04:03 +08:00
|
|
|
#[test]
|
2013-06-29 05:03:40 +08:00
|
|
|
use std::num::{Real, One, abs};
|
2013-05-19 01:04:03 +08:00
|
|
|
#[test]
|
2013-06-28 00:16:07 +08:00
|
|
|
use std::rand::random;
|
2013-05-19 01:04:03 +08:00
|
|
|
#[test]
|
2013-06-02 02:50:00 +08:00
|
|
|
use std::cmp::ApproxEq;
|
2013-05-19 01:04:03 +08:00
|
|
|
#[test]
|
2013-05-19 05:56:03 +08:00
|
|
|
use traits::inv::Inv;
|
|
|
|
#[test]
|
2013-08-22 23:47:37 +08:00
|
|
|
use traits::rotation::Rotation;
|
2013-06-10 08:09:36 +08:00
|
|
|
#[test]
|
2013-06-29 23:19:21 +08:00
|
|
|
use traits::indexable::Indexable;
|
|
|
|
#[test]
|
|
|
|
use traits::transpose::Transpose;
|
|
|
|
#[test]
|
Rework of the traits for Vectors.
The goal is to make traits less fine-grained for vectors, and reduce the amount of `use`.
- Scalar{Mul, Div} are removed, replaced by Mul<N, V> and Div<N, V>,
- Ring and DivisionRing are removed. Use Num instead.
- VectorSpace, Dot, and Norm are removed, replaced by the new, higher-level traits.
Add four traits:
- Vec: common operations on vectors. Replaces VectorSpace and Dot.
- AlgebraicVec: Vec + the old Norm trait.
- VecExt: Vec + every other traits vectors implement.
- AlgebraicVecExt: AlgebraicVec + VecExt.
2013-08-19 00:33:25 +08:00
|
|
|
use traits::vector::AlgebraicVec;
|
|
|
|
#[test]
|
2013-07-23 17:15:20 +08:00
|
|
|
use vec::{Vec1, Vec3};
|
2013-05-19 19:53:19 +08:00
|
|
|
#[test]
|
2013-07-01 05:19:36 +08:00
|
|
|
use mat::{Mat1, Mat2, Mat3, Mat4, Mat5, Mat6};
|
2013-06-10 08:09:36 +08:00
|
|
|
#[test]
|
2013-05-19 19:53:19 +08:00
|
|
|
use adaptors::rotmat::Rotmat;
|
2013-05-19 01:04:03 +08:00
|
|
|
|
2013-05-22 07:15:03 +08:00
|
|
|
macro_rules! test_inv_mat_impl(
|
2013-06-09 22:04:54 +08:00
|
|
|
($t: ty) => (
|
2013-08-05 16:13:44 +08:00
|
|
|
do 10000.times {
|
2013-05-22 07:15:03 +08:00
|
|
|
let randmat : $t = random();
|
|
|
|
|
2013-07-04 22:23:08 +08:00
|
|
|
assert!((randmat.inverse().unwrap() * randmat).approx_eq(&One::one()));
|
2013-05-22 07:15:03 +08:00
|
|
|
}
|
|
|
|
);
|
|
|
|
)
|
2013-05-19 01:04:03 +08:00
|
|
|
|
2013-07-23 17:15:20 +08:00
|
|
|
macro_rules! test_transpose_mat_impl(
|
|
|
|
($t: ty) => (
|
2013-08-05 16:13:44 +08:00
|
|
|
do 10000.times {
|
2013-07-23 17:15:20 +08:00
|
|
|
let randmat : $t = random();
|
|
|
|
|
|
|
|
assert!(randmat.transposed().transposed().eq(&randmat));
|
|
|
|
}
|
|
|
|
);
|
|
|
|
)
|
|
|
|
|
|
|
|
#[test]
|
2013-08-05 16:13:44 +08:00
|
|
|
fn test_transpose_mat1() {
|
|
|
|
test_transpose_mat_impl!(Mat1<f64>);
|
|
|
|
}
|
2013-07-23 17:15:20 +08:00
|
|
|
|
|
|
|
#[test]
|
2013-08-05 16:13:44 +08:00
|
|
|
fn test_transpose_mat2() {
|
|
|
|
test_transpose_mat_impl!(Mat2<f64>);
|
|
|
|
}
|
2013-07-23 17:15:20 +08:00
|
|
|
|
|
|
|
#[test]
|
2013-08-05 16:13:44 +08:00
|
|
|
fn test_transpose_mat3() {
|
|
|
|
test_transpose_mat_impl!(Mat3<f64>);
|
|
|
|
}
|
2013-07-23 17:15:20 +08:00
|
|
|
|
|
|
|
#[test]
|
2013-08-05 16:13:44 +08:00
|
|
|
fn test_transpose_mat4() {
|
|
|
|
test_transpose_mat_impl!(Mat4<f64>);
|
|
|
|
}
|
2013-07-23 17:15:20 +08:00
|
|
|
|
|
|
|
#[test]
|
2013-08-05 16:13:44 +08:00
|
|
|
fn test_transpose_mat5() {
|
|
|
|
test_transpose_mat_impl!(Mat5<f64>);
|
|
|
|
}
|
2013-07-23 17:15:20 +08:00
|
|
|
|
|
|
|
#[test]
|
2013-08-05 16:13:44 +08:00
|
|
|
fn test_transpose_mat6() {
|
|
|
|
test_transpose_mat_impl!(Mat6<f64>);
|
|
|
|
}
|
2013-07-23 17:15:20 +08:00
|
|
|
|
2013-05-19 01:04:03 +08:00
|
|
|
#[test]
|
2013-08-05 16:13:44 +08:00
|
|
|
fn test_inv_mat1() {
|
|
|
|
test_inv_mat_impl!(Mat1<f64>);
|
|
|
|
}
|
2013-05-19 01:04:03 +08:00
|
|
|
|
|
|
|
#[test]
|
2013-08-05 16:13:44 +08:00
|
|
|
fn test_inv_mat2() {
|
|
|
|
test_inv_mat_impl!(Mat2<f64>);
|
|
|
|
}
|
2013-05-19 01:04:03 +08:00
|
|
|
|
|
|
|
#[test]
|
2013-08-05 16:13:44 +08:00
|
|
|
fn test_inv_mat3() {
|
|
|
|
test_inv_mat_impl!(Mat3<f64>);
|
|
|
|
}
|
2013-05-19 01:04:03 +08:00
|
|
|
|
2013-07-01 05:19:36 +08:00
|
|
|
#[test]
|
2013-08-05 16:13:44 +08:00
|
|
|
fn test_inv_mat4() {
|
|
|
|
test_inv_mat_impl!(Mat4<f64>);
|
|
|
|
}
|
2013-07-01 05:19:36 +08:00
|
|
|
|
|
|
|
#[test]
|
2013-08-05 16:13:44 +08:00
|
|
|
fn test_inv_mat5() {
|
|
|
|
test_inv_mat_impl!(Mat5<f64>);
|
|
|
|
}
|
2013-07-01 05:19:36 +08:00
|
|
|
|
|
|
|
#[test]
|
2013-08-05 16:13:44 +08:00
|
|
|
fn test_inv_mat6() {
|
|
|
|
test_inv_mat_impl!(Mat6<f64>);
|
|
|
|
}
|
2013-05-19 01:04:03 +08:00
|
|
|
|
|
|
|
#[test]
|
2013-08-05 16:13:44 +08:00
|
|
|
fn test_rotation2() {
|
|
|
|
do 10000.times {
|
2013-08-28 20:22:12 +08:00
|
|
|
let randmat: Rotmat<Mat2<f64>> = One::one();
|
Removed occurences of copy/Copy + improved api.
Now, access to vector components are x, y, z, w, a, b, ... instead of at[i].
The method at(i) has the same (read only) effect as the old at[i].
Now, access to matrix components are m11, m12, ... instead of mij[offset(i, j)]...
The method at((i, j)) has the same effect as the old mij[offset(i, j)].
Automatic implementation of all traits the compiler supports has been added on the #[deriving]
clause for both matrices and vectors.
2013-07-20 21:07:49 +08:00
|
|
|
let ang = &Vec1::new(abs::<f64>(random()) % Real::pi());
|
2013-05-19 19:53:19 +08:00
|
|
|
|
2013-05-21 23:25:01 +08:00
|
|
|
assert!(randmat.rotated(ang).rotation().approx_eq(ang));
|
2013-05-19 19:53:19 +08:00
|
|
|
}
|
2013-05-19 01:04:03 +08:00
|
|
|
}
|
2013-06-29 23:19:21 +08:00
|
|
|
|
|
|
|
#[test]
|
2013-08-05 16:13:44 +08:00
|
|
|
fn test_index_mat2() {
|
2013-06-29 23:19:21 +08:00
|
|
|
let mat: Mat2<f64> = random();
|
|
|
|
|
|
|
|
assert!(mat.at((0, 1)) == mat.transposed().at((1, 0)));
|
|
|
|
}
|
2013-07-23 17:15:20 +08:00
|
|
|
|
|
|
|
#[test]
|
2013-08-05 16:13:44 +08:00
|
|
|
fn test_inv_rotation3() {
|
|
|
|
do 10000.times {
|
2013-08-28 20:22:12 +08:00
|
|
|
let randmat: Rotmat<Mat3<f64>> = One::one();
|
2013-07-23 17:15:20 +08:00
|
|
|
let dir: Vec3<f64> = random();
|
Rework of the traits for Vectors.
The goal is to make traits less fine-grained for vectors, and reduce the amount of `use`.
- Scalar{Mul, Div} are removed, replaced by Mul<N, V> and Div<N, V>,
- Ring and DivisionRing are removed. Use Num instead.
- VectorSpace, Dot, and Norm are removed, replaced by the new, higher-level traits.
Add four traits:
- Vec: common operations on vectors. Replaces VectorSpace and Dot.
- AlgebraicVec: Vec + the old Norm trait.
- VecExt: Vec + every other traits vectors implement.
- AlgebraicVecExt: AlgebraicVec + VecExt.
2013-08-19 00:33:25 +08:00
|
|
|
let ang = &(dir.normalized() * (abs::<f64>(random()) % Real::pi()));
|
2013-07-23 17:15:20 +08:00
|
|
|
let rot = randmat.rotated(ang);
|
|
|
|
|
|
|
|
assert!((rot.transposed() * rot).approx_eq(&One::one()));
|
|
|
|
}
|
|
|
|
}
|