2013-05-19 01:04:03 +08:00
|
|
|
#[test]
|
2013-06-09 20:09:22 +08:00
|
|
|
use std::iterator::IteratorUtil;
|
|
|
|
#[test]
|
2013-06-02 02:50:00 +08:00
|
|
|
use std::num::{Zero, One};
|
2013-05-19 01:04:03 +08:00
|
|
|
#[test]
|
2013-06-02 02:50:00 +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-06-29 08:34:45 +08:00
|
|
|
use vec::{Vec1, Vec2, Vec3, Vec4, Vec5, Vec6};
|
2013-05-19 01:04:03 +08:00
|
|
|
#[test]
|
|
|
|
use traits::basis::Basis;
|
2013-05-19 05:56:03 +08:00
|
|
|
#[test]
|
|
|
|
use traits::cross::Cross;
|
|
|
|
#[test]
|
|
|
|
use traits::dot::Dot;
|
|
|
|
#[test]
|
|
|
|
use traits::norm::Norm;
|
2013-06-10 08:09:36 +08:00
|
|
|
#[test]
|
2013-06-29 05:03:40 +08:00
|
|
|
use traits::iterable::{Iterable, IterableMut};
|
2013-06-19 18:26:59 +08:00
|
|
|
#[test]
|
|
|
|
use traits::scalar_op::{ScalarMul, ScalarDiv, ScalarAdd, ScalarSub};
|
2013-05-19 05:56:03 +08:00
|
|
|
|
2013-06-29 05:03:40 +08:00
|
|
|
macro_rules! test_iterator_impl(
|
|
|
|
($t: ty, $n: ty) => (
|
|
|
|
for 10000.times
|
|
|
|
{
|
|
|
|
let v: $t = random();
|
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 mut mv: $t = v.clone();
|
2013-06-29 05:03:40 +08:00
|
|
|
let n: $n = random();
|
|
|
|
|
|
|
|
let nv: $t = v.iter().transform(|e| e * n).collect();
|
|
|
|
|
|
|
|
for mv.mut_iter().advance |e|
|
|
|
|
{ *e = *e * n }
|
|
|
|
|
|
|
|
assert!(nv == mv && nv == v.scalar_mul(&n));
|
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2013-05-22 07:15:03 +08:00
|
|
|
macro_rules! test_commut_dot_impl(
|
2013-06-09 22:04:54 +08:00
|
|
|
($t: ty) => (
|
2013-06-02 02:50:00 +08:00
|
|
|
for 10000.times
|
2013-05-22 07:15:03 +08:00
|
|
|
{
|
|
|
|
let v1 : $t = random();
|
|
|
|
let v2 : $t = random();
|
|
|
|
|
|
|
|
assert!(v1.dot(&v2).approx_eq(&v2.dot(&v1)));
|
|
|
|
}
|
|
|
|
);
|
|
|
|
)
|
|
|
|
|
2013-06-19 18:26:59 +08:00
|
|
|
macro_rules! test_scalar_op_impl(
|
|
|
|
($t: ty, $n: ty) => (
|
|
|
|
for 10000.times
|
|
|
|
{
|
|
|
|
let v1 : $t = random();
|
|
|
|
let n : $n = random();
|
|
|
|
|
|
|
|
assert!(v1.scalar_mul(&n).scalar_div(&n).approx_eq(&v1));
|
|
|
|
assert!(v1.scalar_div(&n).scalar_mul(&n).approx_eq(&v1));
|
|
|
|
assert!(v1.scalar_sub(&n).scalar_add(&n).approx_eq(&v1));
|
|
|
|
assert!(v1.scalar_add(&n).scalar_sub(&n).approx_eq(&v1));
|
|
|
|
|
|
|
|
let mut v1 : $t = random();
|
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 v0 : $t = v1.clone();
|
2013-06-19 18:26:59 +08:00
|
|
|
let n : $n = random();
|
|
|
|
|
|
|
|
v1.scalar_mul_inplace(&n);
|
|
|
|
v1.scalar_div_inplace(&n);
|
|
|
|
|
|
|
|
assert!(v1.approx_eq(&v0));
|
|
|
|
}
|
|
|
|
);
|
|
|
|
)
|
|
|
|
|
2013-05-22 07:15:03 +08:00
|
|
|
macro_rules! test_basis_impl(
|
2013-06-09 22:04:54 +08:00
|
|
|
($t: ty) => (
|
2013-06-02 02:50:00 +08:00
|
|
|
for 10000.times
|
2013-05-22 07:15:03 +08:00
|
|
|
{
|
2013-07-02 00:33:22 +08:00
|
|
|
do Basis::canonical_basis::<$t> |e1|
|
|
|
|
{
|
|
|
|
do Basis::canonical_basis::<$t> |e2|
|
|
|
|
{ assert!(e1 == e2 || e1.dot(&e2).approx_eq(&Zero::zero())) }
|
2013-05-22 07:15:03 +08:00
|
|
|
|
2013-07-02 00:33:22 +08:00
|
|
|
assert!(e1.norm().approx_eq(&One::one()));
|
|
|
|
}
|
2013-05-22 07:15:03 +08:00
|
|
|
}
|
|
|
|
);
|
|
|
|
)
|
|
|
|
|
|
|
|
macro_rules! test_subspace_basis_impl(
|
2013-06-09 22:04:54 +08:00
|
|
|
($t: ty) => (
|
2013-06-02 02:50:00 +08:00
|
|
|
for 10000.times
|
2013-05-22 07:15:03 +08:00
|
|
|
{
|
2013-06-19 18:26:59 +08:00
|
|
|
let v : $t = random();
|
|
|
|
let v1 = v.normalized();
|
2013-05-22 07:15:03 +08:00
|
|
|
|
2013-07-02 00:33:22 +08:00
|
|
|
do v1.orthonormal_subspace_basis() |e1|
|
|
|
|
{
|
|
|
|
// check vectors are orthogonal to v1
|
|
|
|
assert!(v1.dot(&e1).approx_eq(&Zero::zero()));
|
|
|
|
// check vectors form an orthonormal basis
|
|
|
|
assert!(e1.norm().approx_eq(&One::one()));
|
|
|
|
// check vectors form an ortogonal basis
|
|
|
|
do v1.orthonormal_subspace_basis() |e2|
|
|
|
|
{ assert!(e1 == e2 || e1.dot(&e2).approx_eq(&Zero::zero())) }
|
|
|
|
}
|
2013-05-22 07:15:03 +08:00
|
|
|
}
|
|
|
|
);
|
|
|
|
)
|
2013-05-19 01:04:03 +08:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_cross_vec3()
|
|
|
|
{
|
2013-06-02 02:50:00 +08:00
|
|
|
for 10000.times
|
2013-05-19 01:04:03 +08:00
|
|
|
{
|
|
|
|
let v1 : Vec3<f64> = random();
|
|
|
|
let v2 : Vec3<f64> = random();
|
|
|
|
let v3 : Vec3<f64> = v1.cross(&v2);
|
|
|
|
|
2013-05-21 23:25:01 +08:00
|
|
|
assert!(v3.dot(&v2).approx_eq(&Zero::zero()));
|
|
|
|
assert!(v3.dot(&v1).approx_eq(&Zero::zero()));
|
2013-05-19 01:04:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2013-05-22 07:15:03 +08:00
|
|
|
fn test_commut_dot_nvec()
|
2013-06-29 08:34:45 +08:00
|
|
|
{ test_commut_dot_impl!(Vec6<f64>); }
|
2013-06-19 18:26:59 +08:00
|
|
|
|
2013-05-19 01:04:03 +08:00
|
|
|
#[test]
|
|
|
|
fn test_commut_dot_vec3()
|
2013-05-22 07:15:03 +08:00
|
|
|
{ test_commut_dot_impl!(Vec3<f64>); }
|
2013-05-19 01:04:03 +08:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_commut_dot_vec2()
|
2013-05-22 07:15:03 +08:00
|
|
|
{ test_commut_dot_impl!(Vec2<f64>); }
|
2013-05-19 01:04:03 +08:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_commut_dot_vec1()
|
2013-05-22 07:15:03 +08:00
|
|
|
{ test_commut_dot_impl!(Vec1<f64>); }
|
2013-05-19 01:04:03 +08:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_basis_vec1()
|
2013-05-22 07:15:03 +08:00
|
|
|
{ test_basis_impl!(Vec1<f64>); }
|
2013-05-19 01:04:03 +08:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_basis_vec2()
|
2013-05-22 07:15:03 +08:00
|
|
|
{ test_basis_impl!(Vec2<f64>); }
|
2013-05-19 01:04:03 +08:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_basis_vec3()
|
2013-05-22 07:15:03 +08:00
|
|
|
{ test_basis_impl!(Vec3<f64>); }
|
2013-05-19 01:04:03 +08:00
|
|
|
|
|
|
|
#[test]
|
2013-06-29 08:34:45 +08:00
|
|
|
fn test_basis_vec4()
|
|
|
|
{ test_basis_impl!(Vec4<f64>); }
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_basis_vec5()
|
|
|
|
{ test_basis_impl!(Vec5<f64>); }
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_basis_vec6()
|
|
|
|
{ test_basis_impl!(Vec6<f64>); }
|
2013-05-19 01:04:03 +08:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_subspace_basis_vec1()
|
2013-05-22 07:15:03 +08:00
|
|
|
{ test_subspace_basis_impl!(Vec1<f64>); }
|
2013-05-19 01:04:03 +08:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_subspace_basis_vec2()
|
2013-05-22 07:15:03 +08:00
|
|
|
{ test_subspace_basis_impl!(Vec2<f64>); }
|
2013-05-19 01:04:03 +08:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_subspace_basis_vec3()
|
2013-05-22 07:15:03 +08:00
|
|
|
{ test_subspace_basis_impl!(Vec3<f64>); }
|
2013-05-19 01:04:03 +08:00
|
|
|
|
2013-05-22 07:15:03 +08:00
|
|
|
#[test]
|
2013-06-29 08:34:45 +08:00
|
|
|
fn test_subspace_basis_vec4()
|
|
|
|
{ test_subspace_basis_impl!(Vec4<f64>); }
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_subspace_basis_vec5()
|
|
|
|
{ test_subspace_basis_impl!(Vec5<f64>); }
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_subspace_basis_vec6()
|
|
|
|
{ test_subspace_basis_impl!(Vec6<f64>); }
|
2013-06-10 08:09:36 +08:00
|
|
|
|
2013-06-19 18:26:59 +08:00
|
|
|
#[test]
|
|
|
|
fn test_scalar_op_vec1()
|
|
|
|
{ test_scalar_op_impl!(Vec1<f64>, f64); }
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_scalar_op_vec2()
|
|
|
|
{ test_scalar_op_impl!(Vec2<f64>, f64); }
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_scalar_op_vec3()
|
|
|
|
{ test_scalar_op_impl!(Vec3<f64>, f64); }
|
2013-06-29 08:34:45 +08:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_scalar_op_vec4()
|
|
|
|
{ test_scalar_op_impl!(Vec4<f64>, f64); }
|
|
|
|
|
2013-06-19 18:26:59 +08:00
|
|
|
#[test]
|
2013-06-29 08:34:45 +08:00
|
|
|
fn test_scalar_op_vec5()
|
|
|
|
{ test_scalar_op_impl!(Vec5<f64>, f64); }
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_scalar_op_vec6()
|
|
|
|
{ test_scalar_op_impl!(Vec6<f64>, f64); }
|
2013-06-29 05:03:40 +08:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_iterator_vec1()
|
|
|
|
{ test_iterator_impl!(Vec1<f64>, f64); }
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_iterator_vec2()
|
|
|
|
{ test_iterator_impl!(Vec2<f64>, f64); }
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_iterator_vec3()
|
|
|
|
{ test_iterator_impl!(Vec3<f64>, f64); }
|
2013-06-29 08:34:45 +08:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_iterator_vec4()
|
|
|
|
{ test_iterator_impl!(Vec4<f64>, f64); }
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_iterator_vec5()
|
|
|
|
{ test_iterator_impl!(Vec5<f64>, f64); }
|
|
|
|
|
2013-06-29 05:03:40 +08:00
|
|
|
#[test]
|
2013-06-29 08:34:45 +08:00
|
|
|
fn test_iterator_vec6()
|
|
|
|
{ test_iterator_impl!(Vec6<f64>, f64); }
|