Convert asserts to syntax extension form
This commit is contained in:
parent
ad4ee9c436
commit
1c09618aa4
3 changed files with 474 additions and 474 deletions
|
@ -13,90 +13,90 @@ fn test_mat2() {
|
|||
let v1 = vec2::new(1.0, 2.0);
|
||||
let f1 = 0.5;
|
||||
|
||||
assert a == mat2::new(1.0, 3.0,
|
||||
2.0, 4.0);
|
||||
assert!(a == mat2::new(1.0, 3.0,
|
||||
2.0, 4.0));
|
||||
|
||||
assert a == mat2::from_cols(vec2::new(1.0, 3.0),
|
||||
vec2::new(2.0, 4.0));
|
||||
assert!(a == mat2::from_cols(vec2::new(1.0, 3.0),
|
||||
vec2::new(2.0, 4.0)));
|
||||
|
||||
assert mat2::from_value(4.0) == mat2::new(4.0, 0.0,
|
||||
0.0, 4.0);
|
||||
assert!(mat2::from_value(4.0) == mat2::new(4.0, 0.0,
|
||||
0.0, 4.0));
|
||||
|
||||
assert a[0] == vec2::new(1.0, 3.0);
|
||||
assert a[1] == vec2::new(2.0, 4.0);
|
||||
assert!(a[0] == vec2::new(1.0, 3.0));
|
||||
assert!(a[1] == vec2::new(2.0, 4.0));
|
||||
|
||||
assert a.row(0) == vec2::new(1.0, 2.0);
|
||||
assert a.row(1) == vec2::new(3.0, 4.0);
|
||||
assert!(a.row(0) == vec2::new(1.0, 2.0));
|
||||
assert!(a.row(1) == vec2::new(3.0, 4.0));
|
||||
|
||||
assert a.col(0) == vec2::new(1.0, 3.0);
|
||||
assert a.col(1) == vec2::new(2.0, 4.0);
|
||||
assert!(a.col(0) == vec2::new(1.0, 3.0));
|
||||
assert!(a.col(1) == vec2::new(2.0, 4.0));
|
||||
|
||||
assert mat2::identity() == mat2::new(1.0, 0.0,
|
||||
0.0, 1.0);
|
||||
assert!(mat2::identity() == mat2::new(1.0, 0.0,
|
||||
0.0, 1.0));
|
||||
|
||||
assert mat2::zero() == mat2::new(0.0, 0.0,
|
||||
0.0, 0.0);
|
||||
assert!(mat2::zero() == mat2::new(0.0, 0.0,
|
||||
0.0, 0.0));
|
||||
|
||||
assert a.determinant() == -2.0;
|
||||
assert a.trace() == 5.0;
|
||||
assert!(a.determinant() == -2.0);
|
||||
assert!(a.trace() == 5.0);
|
||||
|
||||
assert a.neg() == mat2::new(-1.0, -3.0,
|
||||
-2.0, -4.0);
|
||||
assert -a == a.neg();
|
||||
assert!(a.neg() == mat2::new(-1.0, -3.0,
|
||||
-2.0, -4.0));
|
||||
assert!(-a == a.neg());
|
||||
|
||||
assert a.mul_t(f1) == mat2::new(0.5, 1.5,
|
||||
1.0, 2.0);
|
||||
assert a.mul_v(&v1) == vec2::new(5.0, 11.0);
|
||||
assert!(a.mul_t(f1) == mat2::new(0.5, 1.5,
|
||||
1.0, 2.0));
|
||||
assert!(a.mul_v(&v1) == vec2::new(5.0, 11.0));
|
||||
|
||||
assert a.add_m(&b) == mat2::new(3.0, 7.0,
|
||||
5.0, 9.0);
|
||||
assert a.sub_m(&b) == mat2::new(-1.0, -1.0,
|
||||
-1.0, -1.0);
|
||||
assert a.mul_m(&b) == mat2::new(10.0, 22.0,
|
||||
13.0, 29.0);
|
||||
assert a.dot(&b) == 40.0;
|
||||
assert!(a.add_m(&b) == mat2::new(3.0, 7.0,
|
||||
5.0, 9.0));
|
||||
assert!(a.sub_m(&b) == mat2::new(-1.0, -1.0,
|
||||
-1.0, -1.0));
|
||||
assert!(a.mul_m(&b) == mat2::new(10.0, 22.0,
|
||||
13.0, 29.0));
|
||||
assert!(a.dot(&b) == 40.0);
|
||||
|
||||
assert a.transpose() == mat2::new(1.0, 2.0,
|
||||
3.0, 4.0);
|
||||
assert!(a.transpose() == mat2::new(1.0, 2.0,
|
||||
3.0, 4.0));
|
||||
|
||||
assert option::unwrap(a.inverse()) == mat2::new(-2.0, 1.5,
|
||||
1.0, -0.5);
|
||||
assert!(option::unwrap(a.inverse()) == mat2::new(-2.0, 1.5,
|
||||
1.0, -0.5));
|
||||
|
||||
assert mat2::new(0.0, 2.0,
|
||||
0.0, 5.0).inverse().is_none();
|
||||
assert!(mat2::new(0.0, 2.0,
|
||||
0.0, 5.0).inverse().is_none());
|
||||
|
||||
let ident = mat2::identity();
|
||||
|
||||
assert ident.is_identity();
|
||||
assert ident.is_symmetric();
|
||||
assert ident.is_diagonal();
|
||||
assert !ident.is_rotated();
|
||||
assert ident.is_invertible();
|
||||
assert!(ident.is_identity());
|
||||
assert!(ident.is_symmetric());
|
||||
assert!(ident.is_diagonal());
|
||||
assert!(!ident.is_rotated());
|
||||
assert!(ident.is_invertible());
|
||||
|
||||
assert !a.is_identity();
|
||||
assert !a.is_symmetric();
|
||||
assert !a.is_diagonal();
|
||||
assert a.is_rotated();
|
||||
assert a.is_invertible();
|
||||
assert!(!a.is_identity());
|
||||
assert!(!a.is_symmetric());
|
||||
assert!(!a.is_diagonal());
|
||||
assert!(a.is_rotated());
|
||||
assert!(a.is_invertible());
|
||||
|
||||
let c = mat2::new(2.0, 1.0,
|
||||
1.0, 2.0);
|
||||
assert !c.is_identity();
|
||||
assert c.is_symmetric();
|
||||
assert !c.is_diagonal();
|
||||
assert c.is_rotated();
|
||||
assert c.is_invertible();
|
||||
assert!(!c.is_identity());
|
||||
assert!(c.is_symmetric());
|
||||
assert!(!c.is_diagonal());
|
||||
assert!(c.is_rotated());
|
||||
assert!(c.is_invertible());
|
||||
|
||||
assert mat2::from_value(6.0).is_diagonal();
|
||||
assert!(mat2::from_value(6.0).is_diagonal());
|
||||
|
||||
assert a.to_mat3() == mat3::new(1.0, 3.0, 0.0,
|
||||
2.0, 4.0, 0.0,
|
||||
0.0, 0.0, 1.0);
|
||||
assert!(a.to_mat3() == mat3::new(1.0, 3.0, 0.0,
|
||||
2.0, 4.0, 0.0,
|
||||
0.0, 0.0, 1.0));
|
||||
|
||||
assert a.to_mat4() == mat4::new(1.0, 3.0, 0.0, 0.0,
|
||||
2.0, 4.0, 0.0, 0.0,
|
||||
0.0, 0.0, 1.0, 0.0,
|
||||
0.0, 0.0, 0.0, 1.0);
|
||||
assert!(a.to_mat4() == mat4::new(1.0, 3.0, 0.0, 0.0,
|
||||
2.0, 4.0, 0.0, 0.0,
|
||||
0.0, 0.0, 1.0, 0.0,
|
||||
0.0, 0.0, 0.0, 1.0));
|
||||
}
|
||||
|
||||
fn test_mat2_mut() {
|
||||
|
@ -110,54 +110,54 @@ fn test_mat2_mut() {
|
|||
let mut mut_a: mat2 = a;
|
||||
|
||||
mut_a.swap_cols(0, 1);
|
||||
assert mut_a.col(0) == a.col(1);
|
||||
assert mut_a.col(1) == a.col(0);
|
||||
assert!(mut_a.col(0) == a.col(1));
|
||||
assert!(mut_a.col(1) == a.col(0));
|
||||
mut_a = a;
|
||||
|
||||
mut_a.swap_rows(0, 1);
|
||||
assert mut_a.row(0) == a.row(1);
|
||||
assert mut_a.row(1) == a.row(0);
|
||||
assert!(mut_a.row(0) == a.row(1));
|
||||
assert!(mut_a.row(1) == a.row(0));
|
||||
mut_a = a;
|
||||
|
||||
mut_a.set(&b);
|
||||
assert mut_a == b;
|
||||
assert!(mut_a == b);
|
||||
mut_a = a;
|
||||
|
||||
mut_a.to_identity();
|
||||
assert mut_a.is_identity();
|
||||
assert!(mut_a.is_identity());
|
||||
mut_a = a;
|
||||
|
||||
mut_a.to_zero();
|
||||
assert mut_a == mat2::zero();
|
||||
assert!(mut_a == mat2::zero());
|
||||
mut_a = a;
|
||||
|
||||
mut_a.mul_self_t(f1);
|
||||
assert mut_a == a.mul_t(f1);
|
||||
assert!(mut_a == a.mul_t(f1));
|
||||
mut_a = a;
|
||||
|
||||
mut_a.add_self_m(&b);
|
||||
assert mut_a == a.add_m(&b);
|
||||
assert!(mut_a == a.add_m(&b));
|
||||
mut_a = a;
|
||||
|
||||
mut_a.sub_self_m(&b);
|
||||
assert mut_a == a.sub_m(&b);
|
||||
assert!(mut_a == a.sub_m(&b));
|
||||
mut_a = a;
|
||||
|
||||
mut_a.invert_self();
|
||||
assert mut_a == option::unwrap(a.inverse());
|
||||
assert!(mut_a == option::unwrap(a.inverse()));
|
||||
mut_a = a;
|
||||
|
||||
mut_a.transpose_self();
|
||||
assert mut_a == a.transpose();
|
||||
assert!(mut_a == a.transpose());
|
||||
// mut_a = a;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_mat2_fuzzy_eq() {
|
||||
assert !mat2::new(0.000001, 0.000001,
|
||||
0.000001, 0.000001).fuzzy_eq(&mat2::zero());
|
||||
assert mat2::new(0.0000001, 0.0000001,
|
||||
0.0000001, 0.0000001).fuzzy_eq(&mat2::zero());
|
||||
assert!(!mat2::new(0.000001, 0.000001,
|
||||
0.000001, 0.000001).fuzzy_eq(&mat2::zero()));
|
||||
assert!(mat2::new(0.0000001, 0.0000001,
|
||||
0.0000001, 0.0000001).fuzzy_eq(&mat2::zero()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -172,102 +172,102 @@ fn test_mat3() {
|
|||
let v1 = vec3::new(1.0, 2.0, 3.0);
|
||||
let f1 = 0.5;
|
||||
|
||||
assert a == mat3::new(1.0, 4.0, 7.0,
|
||||
2.0, 5.0, 8.0,
|
||||
3.0, 6.0, 9.0);
|
||||
assert!(a == mat3::new(1.0, 4.0, 7.0,
|
||||
2.0, 5.0, 8.0,
|
||||
3.0, 6.0, 9.0));
|
||||
|
||||
assert a == mat3::from_cols(vec3::new(1.0, 4.0, 7.0),
|
||||
vec3::new(2.0, 5.0, 8.0),
|
||||
vec3::new(3.0, 6.0, 9.0));
|
||||
assert!(a == mat3::from_cols(vec3::new(1.0, 4.0, 7.0),
|
||||
vec3::new(2.0, 5.0, 8.0),
|
||||
vec3::new(3.0, 6.0, 9.0)));
|
||||
|
||||
assert a[0] == vec3::new(1.0, 4.0, 7.0);
|
||||
assert a[1] == vec3::new(2.0, 5.0, 8.0);
|
||||
assert a[2] == vec3::new(3.0, 6.0, 9.0);
|
||||
assert!(a[0] == vec3::new(1.0, 4.0, 7.0));
|
||||
assert!(a[1] == vec3::new(2.0, 5.0, 8.0));
|
||||
assert!(a[2] == vec3::new(3.0, 6.0, 9.0));
|
||||
|
||||
assert a.row(0) == vec3::new(1.0, 2.0, 3.0);
|
||||
assert a.row(1) == vec3::new(4.0, 5.0, 6.0);
|
||||
assert a.row(2) == vec3::new(7.0, 8.0, 9.0);
|
||||
assert!(a.row(0) == vec3::new(1.0, 2.0, 3.0));
|
||||
assert!(a.row(1) == vec3::new(4.0, 5.0, 6.0));
|
||||
assert!(a.row(2) == vec3::new(7.0, 8.0, 9.0));
|
||||
|
||||
assert a.col(0) == vec3::new(1.0, 4.0, 7.0);
|
||||
assert a.col(1) == vec3::new(2.0, 5.0, 8.0);
|
||||
assert a.col(2) == vec3::new(3.0, 6.0, 9.0);
|
||||
assert!(a.col(0) == vec3::new(1.0, 4.0, 7.0));
|
||||
assert!(a.col(1) == vec3::new(2.0, 5.0, 8.0));
|
||||
assert!(a.col(2) == vec3::new(3.0, 6.0, 9.0));
|
||||
|
||||
assert mat3::identity() == mat3::new(1.0, 0.0, 0.0,
|
||||
0.0, 1.0, 0.0,
|
||||
0.0, 0.0, 1.0);
|
||||
assert!(mat3::identity() == mat3::new(1.0, 0.0, 0.0,
|
||||
0.0, 1.0, 0.0,
|
||||
0.0, 0.0, 1.0));
|
||||
|
||||
assert mat3::zero() == mat3::new(0.0, 0.0, 0.0,
|
||||
0.0, 0.0, 0.0,
|
||||
0.0, 0.0, 0.0);
|
||||
assert!(mat3::zero() == mat3::new(0.0, 0.0, 0.0,
|
||||
0.0, 0.0, 0.0,
|
||||
0.0, 0.0, 0.0));
|
||||
|
||||
assert a.determinant() == 0.0;
|
||||
assert a.trace() == 15.0;
|
||||
assert!(a.determinant() == 0.0);
|
||||
assert!(a.trace() == 15.0);
|
||||
|
||||
assert a.neg() == mat3::new(-1.0, -4.0, -7.0,
|
||||
-2.0, -5.0, -8.0,
|
||||
-3.0, -6.0, -9.0);
|
||||
assert -a == a.neg();
|
||||
assert!(a.neg() == mat3::new(-1.0, -4.0, -7.0,
|
||||
-2.0, -5.0, -8.0,
|
||||
-3.0, -6.0, -9.0));
|
||||
assert!(-a == a.neg());
|
||||
|
||||
assert a.mul_t(f1) == mat3::new(0.5, 2.0, 3.5,
|
||||
1.0, 2.5, 4.0,
|
||||
1.5, 3.0, 4.5);
|
||||
assert a.mul_v(&v1) == vec3::new(14.0, 32.0, 50.0);
|
||||
assert!(a.mul_t(f1) == mat3::new(0.5, 2.0, 3.5,
|
||||
1.0, 2.5, 4.0,
|
||||
1.5, 3.0, 4.5));
|
||||
assert!(a.mul_v(&v1) == vec3::new(14.0, 32.0, 50.0));
|
||||
|
||||
assert a.add_m(&b) == mat3::new(3.0, 9.0, 15.0,
|
||||
5.0, 11.0, 17.0,
|
||||
7.0, 13.0, 19.0);
|
||||
assert a.sub_m(&b) == mat3::new(-1.0, -1.0, -1.0,
|
||||
-1.0, -1.0, -1.0,
|
||||
-1.0, -1.0, -1.0);
|
||||
assert a.mul_m(&b) == mat3::new(36.0, 81.0, 126.0,
|
||||
42.0, 96.0, 150.0,
|
||||
48.0, 111.0, 174.0);
|
||||
assert a.dot(&b) == 330.0;
|
||||
assert!(a.add_m(&b) == mat3::new(3.0, 9.0, 15.0,
|
||||
5.0, 11.0, 17.0,
|
||||
7.0, 13.0, 19.0));
|
||||
assert!(a.sub_m(&b) == mat3::new(-1.0, -1.0, -1.0,
|
||||
-1.0, -1.0, -1.0,
|
||||
-1.0, -1.0, -1.0));
|
||||
assert!(a.mul_m(&b) == mat3::new(36.0, 81.0, 126.0,
|
||||
42.0, 96.0, 150.0,
|
||||
48.0, 111.0, 174.0));
|
||||
assert!(a.dot(&b) == 330.0);
|
||||
|
||||
assert a.transpose() == mat3::new(1.0, 2.0, 3.0,
|
||||
4.0, 5.0, 6.0,
|
||||
7.0, 8.0, 9.0);
|
||||
assert!(a.transpose() == mat3::new(1.0, 2.0, 3.0,
|
||||
4.0, 5.0, 6.0,
|
||||
7.0, 8.0, 9.0));
|
||||
|
||||
assert a.inverse().is_none();
|
||||
assert!(a.inverse().is_none());
|
||||
|
||||
assert option::unwrap(mat3::new(2.0, 4.0, 6.0,
|
||||
0.0, 2.0, 4.0,
|
||||
0.0, 0.0, 1.0).inverse())
|
||||
assert!(option::unwrap(mat3::new(2.0, 4.0, 6.0,
|
||||
0.0, 2.0, 4.0,
|
||||
0.0, 0.0, 1.0).inverse())
|
||||
== mat3::new(0.5, -1.0, 1.0,
|
||||
0.0, 0.5, -2.0,
|
||||
0.0, 0.0, 1.0);
|
||||
0.0, 0.0, 1.0));
|
||||
|
||||
let ident: Mat3<float> = Matrix::identity();
|
||||
|
||||
assert option::unwrap(ident.inverse()) == ident;
|
||||
assert!(option::unwrap(ident.inverse()) == ident);
|
||||
|
||||
assert ident.is_identity();
|
||||
assert ident.is_symmetric();
|
||||
assert ident.is_diagonal();
|
||||
assert !ident.is_rotated();
|
||||
assert ident.is_invertible();
|
||||
assert!(ident.is_identity());
|
||||
assert!(ident.is_symmetric());
|
||||
assert!(ident.is_diagonal());
|
||||
assert!(!ident.is_rotated());
|
||||
assert!(ident.is_invertible());
|
||||
|
||||
assert !a.is_identity();
|
||||
assert !a.is_symmetric();
|
||||
assert !a.is_diagonal();
|
||||
assert a.is_rotated();
|
||||
assert !a.is_invertible();
|
||||
assert!(!a.is_identity());
|
||||
assert!(!a.is_symmetric());
|
||||
assert!(!a.is_diagonal());
|
||||
assert!(a.is_rotated());
|
||||
assert!(!a.is_invertible());
|
||||
|
||||
let c = mat3::new(3.0, 2.0, 1.0,
|
||||
2.0, 3.0, 2.0,
|
||||
1.0, 2.0, 3.0);
|
||||
assert !c.is_identity();
|
||||
assert c.is_symmetric();
|
||||
assert !c.is_diagonal();
|
||||
assert c.is_rotated();
|
||||
assert c.is_invertible();
|
||||
assert!(!c.is_identity());
|
||||
assert!(c.is_symmetric());
|
||||
assert!(!c.is_diagonal());
|
||||
assert!(c.is_rotated());
|
||||
assert!(c.is_invertible());
|
||||
|
||||
assert mat3::from_value(6.0).is_diagonal();
|
||||
assert!(mat3::from_value(6.0).is_diagonal());
|
||||
|
||||
assert a.to_mat4() == mat4::new(1.0, 4.0, 7.0, 0.0,
|
||||
2.0, 5.0, 8.0, 0.0,
|
||||
3.0, 6.0, 9.0, 0.0,
|
||||
0.0, 0.0, 0.0, 1.0);
|
||||
assert!(a.to_mat4() == mat4::new(1.0, 4.0, 7.0, 0.0,
|
||||
2.0, 5.0, 8.0, 0.0,
|
||||
3.0, 6.0, 9.0, 0.0,
|
||||
0.0, 0.0, 0.0, 1.0));
|
||||
|
||||
// to_Quaternion
|
||||
}
|
||||
|
@ -289,66 +289,66 @@ fn test_mat3_mut() {
|
|||
let mut mut_c: mat3 = c;
|
||||
|
||||
mut_a.swap_cols(0, 2);
|
||||
assert mut_a.col(0) == a.col(2);
|
||||
assert mut_a.col(2) == a.col(0);
|
||||
assert!(mut_a.col(0) == a.col(2));
|
||||
assert!(mut_a.col(2) == a.col(0));
|
||||
mut_a = a;
|
||||
|
||||
mut_a.swap_cols(1, 2);
|
||||
assert mut_a.col(1) == a.col(2);
|
||||
assert mut_a.col(2) == a.col(1);
|
||||
assert!(mut_a.col(1) == a.col(2));
|
||||
assert!(mut_a.col(2) == a.col(1));
|
||||
mut_a = a;
|
||||
|
||||
mut_a.swap_rows(0, 2);
|
||||
assert mut_a.row(0) == a.row(2);
|
||||
assert mut_a.row(2) == a.row(0);
|
||||
assert!(mut_a.row(0) == a.row(2));
|
||||
assert!(mut_a.row(2) == a.row(0));
|
||||
mut_a = a;
|
||||
|
||||
mut_a.swap_rows(1, 2);
|
||||
assert mut_a.row(1) == a.row(2);
|
||||
assert mut_a.row(2) == a.row(1);
|
||||
assert!(mut_a.row(1) == a.row(2));
|
||||
assert!(mut_a.row(2) == a.row(1));
|
||||
mut_a = a;
|
||||
|
||||
mut_a.set(&b);
|
||||
assert mut_a == b;
|
||||
assert!(mut_a == b);
|
||||
mut_a = a;
|
||||
|
||||
mut_a.to_identity();
|
||||
assert mut_a.is_identity();
|
||||
assert!(mut_a.is_identity());
|
||||
mut_a = a;
|
||||
|
||||
mut_a.to_zero();
|
||||
assert mut_a == mat3::zero();
|
||||
assert!(mut_a == mat3::zero());
|
||||
mut_a = a;
|
||||
|
||||
mut_a.mul_self_t(f1);
|
||||
assert mut_a == a.mul_t(f1);
|
||||
assert!(mut_a == a.mul_t(f1));
|
||||
mut_a = a;
|
||||
|
||||
mut_a.add_self_m(&b);
|
||||
assert mut_a == a.add_m(&b);
|
||||
assert!(mut_a == a.add_m(&b));
|
||||
mut_a = a;
|
||||
|
||||
mut_a.sub_self_m(&b);
|
||||
assert mut_a == a.sub_m(&b);
|
||||
assert!(mut_a == a.sub_m(&b));
|
||||
mut_a = a;
|
||||
|
||||
mut_c.invert_self();
|
||||
assert mut_c == option::unwrap(c.inverse());
|
||||
assert!(mut_c == option::unwrap(c.inverse()));
|
||||
// mut_c = c;
|
||||
|
||||
mut_a.transpose_self();
|
||||
assert mut_a == a.transpose();
|
||||
assert!(mut_a == a.transpose());
|
||||
// mut_a = a;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_mat3_fuzzy_eq() {
|
||||
assert !mat3::new(0.000001, 0.000001, 0.000001,
|
||||
0.000001, 0.000001, 0.000001,
|
||||
0.000001, 0.000001, 0.000001).fuzzy_eq(&mat3::zero());
|
||||
assert mat3::new(0.0000001, 0.0000001, 0.0000001,
|
||||
0.0000001, 0.0000001, 0.0000001,
|
||||
0.0000001, 0.0000001, 0.0000001).fuzzy_eq(&mat3::zero());
|
||||
assert!(!mat3::new(0.000001, 0.000001, 0.000001,
|
||||
0.000001, 0.000001, 0.000001,
|
||||
0.000001, 0.000001, 0.000001).fuzzy_eq(&mat3::zero()));
|
||||
assert!(mat3::new(0.0000001, 0.0000001, 0.0000001,
|
||||
0.0000001, 0.0000001, 0.0000001,
|
||||
0.0000001, 0.0000001, 0.0000001).fuzzy_eq(&mat3::zero()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -369,113 +369,113 @@ fn test_mat4() {
|
|||
let v1 = vec4::new(1.0, 2.0, 3.0, 4.0);
|
||||
let f1 = 0.5;
|
||||
|
||||
assert a == mat4::new(1.0, 5.0, 9.0, 13.0,
|
||||
2.0, 6.0, 10.0, 14.0,
|
||||
3.0, 7.0, 11.0, 15.0,
|
||||
4.0, 8.0, 12.0, 16.0);
|
||||
assert!(a == mat4::new(1.0, 5.0, 9.0, 13.0,
|
||||
2.0, 6.0, 10.0, 14.0,
|
||||
3.0, 7.0, 11.0, 15.0,
|
||||
4.0, 8.0, 12.0, 16.0));
|
||||
|
||||
assert a == mat4::from_cols(vec4::new(1.0, 5.0, 9.0, 13.0),
|
||||
vec4::new(2.0, 6.0, 10.0, 14.0),
|
||||
vec4::new(3.0, 7.0, 11.0, 15.0),
|
||||
vec4::new(4.0, 8.0, 12.0, 16.0));
|
||||
assert!(a == mat4::from_cols(vec4::new(1.0, 5.0, 9.0, 13.0),
|
||||
vec4::new(2.0, 6.0, 10.0, 14.0),
|
||||
vec4::new(3.0, 7.0, 11.0, 15.0),
|
||||
vec4::new(4.0, 8.0, 12.0, 16.0)));
|
||||
|
||||
assert mat4::from_value(4.0) == mat4::new(4.0, 0.0, 0.0, 0.0,
|
||||
0.0, 4.0, 0.0, 0.0,
|
||||
0.0, 0.0, 4.0, 0.0,
|
||||
0.0, 0.0, 0.0, 4.0);
|
||||
assert!(mat4::from_value(4.0) == mat4::new(4.0, 0.0, 0.0, 0.0,
|
||||
0.0, 4.0, 0.0, 0.0,
|
||||
0.0, 0.0, 4.0, 0.0,
|
||||
0.0, 0.0, 0.0, 4.0));
|
||||
|
||||
assert a[0] == vec4::new(1.0, 5.0, 9.0, 13.0);
|
||||
assert a[1] == vec4::new(2.0, 6.0, 10.0, 14.0);
|
||||
assert a[2] == vec4::new(3.0, 7.0, 11.0, 15.0);
|
||||
assert a[3] == vec4::new(4.0, 8.0, 12.0, 16.0);
|
||||
assert!(a[0] == vec4::new(1.0, 5.0, 9.0, 13.0));
|
||||
assert!(a[1] == vec4::new(2.0, 6.0, 10.0, 14.0));
|
||||
assert!(a[2] == vec4::new(3.0, 7.0, 11.0, 15.0));
|
||||
assert!(a[3] == vec4::new(4.0, 8.0, 12.0, 16.0));
|
||||
|
||||
assert a.row(0) == vec4::new( 1.0, 2.0, 3.0, 4.0);
|
||||
assert a.row(1) == vec4::new( 5.0, 6.0, 7.0, 8.0);
|
||||
assert a.row(2) == vec4::new( 9.0, 10.0, 11.0, 12.0);
|
||||
assert a.row(3) == vec4::new(13.0, 14.0, 15.0, 16.0);
|
||||
assert!(a.row(0) == vec4::new( 1.0, 2.0, 3.0, 4.0));
|
||||
assert!(a.row(1) == vec4::new( 5.0, 6.0, 7.0, 8.0));
|
||||
assert!(a.row(2) == vec4::new( 9.0, 10.0, 11.0, 12.0));
|
||||
assert!(a.row(3) == vec4::new(13.0, 14.0, 15.0, 16.0));
|
||||
|
||||
assert a.col(0) == vec4::new(1.0, 5.0, 9.0, 13.0);
|
||||
assert a.col(1) == vec4::new(2.0, 6.0, 10.0, 14.0);
|
||||
assert a.col(2) == vec4::new(3.0, 7.0, 11.0, 15.0);
|
||||
assert a.col(3) == vec4::new(4.0, 8.0, 12.0, 16.0);
|
||||
assert!(a.col(0) == vec4::new(1.0, 5.0, 9.0, 13.0));
|
||||
assert!(a.col(1) == vec4::new(2.0, 6.0, 10.0, 14.0));
|
||||
assert!(a.col(2) == vec4::new(3.0, 7.0, 11.0, 15.0));
|
||||
assert!(a.col(3) == vec4::new(4.0, 8.0, 12.0, 16.0));
|
||||
|
||||
assert mat4::identity() == mat4::new(1.0, 0.0, 0.0, 0.0,
|
||||
0.0, 1.0, 0.0, 0.0,
|
||||
0.0, 0.0, 1.0, 0.0,
|
||||
0.0, 0.0, 0.0, 1.0);
|
||||
assert!(mat4::identity() == mat4::new(1.0, 0.0, 0.0, 0.0,
|
||||
0.0, 1.0, 0.0, 0.0,
|
||||
0.0, 0.0, 1.0, 0.0,
|
||||
0.0, 0.0, 0.0, 1.0));
|
||||
|
||||
assert mat4::zero() == mat4::new(0.0, 0.0, 0.0, 0.0,
|
||||
0.0, 0.0, 0.0, 0.0,
|
||||
0.0, 0.0, 0.0, 0.0,
|
||||
0.0, 0.0, 0.0, 0.0);
|
||||
assert!(mat4::zero() == mat4::new(0.0, 0.0, 0.0, 0.0,
|
||||
0.0, 0.0, 0.0, 0.0,
|
||||
0.0, 0.0, 0.0, 0.0,
|
||||
0.0, 0.0, 0.0, 0.0));
|
||||
|
||||
assert a.determinant() == 0.0;
|
||||
assert a.trace() == 34.0;
|
||||
assert!(a.determinant() == 0.0);
|
||||
assert!(a.trace() == 34.0);
|
||||
|
||||
assert a.neg() == mat4::new(-1.0, -5.0, -9.0, -13.0,
|
||||
-2.0, -6.0, -10.0, -14.0,
|
||||
-3.0, -7.0, -11.0, -15.0,
|
||||
-4.0, -8.0, -12.0, -16.0);
|
||||
assert -a == a.neg();
|
||||
assert!(a.neg() == mat4::new(-1.0, -5.0, -9.0, -13.0,
|
||||
-2.0, -6.0, -10.0, -14.0,
|
||||
-3.0, -7.0, -11.0, -15.0,
|
||||
-4.0, -8.0, -12.0, -16.0));
|
||||
assert!(-a == a.neg());
|
||||
|
||||
assert a.mul_t(f1) == mat4::new(0.5, 2.5, 4.5, 6.5,
|
||||
1.0, 3.0, 5.0, 7.0,
|
||||
1.5, 3.5, 5.5, 7.5,
|
||||
2.0, 4.0, 6.0, 8.0);
|
||||
assert a.mul_v(&v1) == vec4::new(30.0, 70.0, 110.0, 150.0);
|
||||
assert!(a.mul_t(f1) == mat4::new(0.5, 2.5, 4.5, 6.5,
|
||||
1.0, 3.0, 5.0, 7.0,
|
||||
1.5, 3.5, 5.5, 7.5,
|
||||
2.0, 4.0, 6.0, 8.0));
|
||||
assert!(a.mul_v(&v1) == vec4::new(30.0, 70.0, 110.0, 150.0));
|
||||
|
||||
assert a.add_m(&b) == mat4::new(3.0, 11.0, 19.0, 27.0,
|
||||
5.0, 13.0, 21.0, 29.0,
|
||||
7.0, 15.0, 23.0, 31.0,
|
||||
9.0, 17.0, 25.0, 33.0);
|
||||
assert a.sub_m(&b) == mat4::new(-1.0, -1.0, -1.0, -1.0,
|
||||
-1.0, -1.0, -1.0, -1.0,
|
||||
-1.0, -1.0, -1.0, -1.0,
|
||||
-1.0, -1.0, -1.0, -1.0);
|
||||
assert a.mul_m(&b) == mat4::new(100.0, 228.0, 356.0, 484.0,
|
||||
110.0, 254.0, 398.0, 542.0,
|
||||
120.0, 280.0, 440.0, 600.0,
|
||||
130.0, 306.0, 482.0, 658.0);
|
||||
assert a.dot(&b) == 1632.0;
|
||||
assert!(a.add_m(&b) == mat4::new(3.0, 11.0, 19.0, 27.0,
|
||||
5.0, 13.0, 21.0, 29.0,
|
||||
7.0, 15.0, 23.0, 31.0,
|
||||
9.0, 17.0, 25.0, 33.0));
|
||||
assert!(a.sub_m(&b) == mat4::new(-1.0, -1.0, -1.0, -1.0,
|
||||
-1.0, -1.0, -1.0, -1.0,
|
||||
-1.0, -1.0, -1.0, -1.0,
|
||||
-1.0, -1.0, -1.0, -1.0));
|
||||
assert!(a.mul_m(&b) == mat4::new(100.0, 228.0, 356.0, 484.0,
|
||||
110.0, 254.0, 398.0, 542.0,
|
||||
120.0, 280.0, 440.0, 600.0,
|
||||
130.0, 306.0, 482.0, 658.0));
|
||||
assert!(a.dot(&b) == 1632.0);
|
||||
|
||||
assert a.transpose() == mat4::new( 1.0, 2.0, 3.0, 4.0,
|
||||
5.0, 6.0, 7.0, 8.0,
|
||||
9.0, 10.0, 11.0, 12.0,
|
||||
13.0, 14.0, 15.0, 16.0);
|
||||
assert!(a.transpose() == mat4::new( 1.0, 2.0, 3.0, 4.0,
|
||||
5.0, 6.0, 7.0, 8.0,
|
||||
9.0, 10.0, 11.0, 12.0,
|
||||
13.0, 14.0, 15.0, 16.0));
|
||||
|
||||
assert c.inverse().unwrap()
|
||||
assert!(c.inverse().unwrap()
|
||||
.fuzzy_eq(&mat4::new( 5.0, -4.0, 1.0, 0.0,
|
||||
-4.0, 8.0, -4.0, 0.0,
|
||||
4.0, -8.0, 4.0, 8.0,
|
||||
-3.0, 4.0, 1.0, -8.0).mul_t(0.125));
|
||||
-3.0, 4.0, 1.0, -8.0).mul_t(0.125)));
|
||||
|
||||
let ident = mat4::identity();
|
||||
|
||||
assert ident.inverse().unwrap() == ident;
|
||||
assert!(ident.inverse().unwrap() == ident);
|
||||
|
||||
assert ident.is_identity();
|
||||
assert ident.is_symmetric();
|
||||
assert ident.is_diagonal();
|
||||
assert !ident.is_rotated();
|
||||
assert ident.is_invertible();
|
||||
assert!(ident.is_identity());
|
||||
assert!(ident.is_symmetric());
|
||||
assert!(ident.is_diagonal());
|
||||
assert!(!ident.is_rotated());
|
||||
assert!(ident.is_invertible());
|
||||
|
||||
assert !a.is_identity();
|
||||
assert !a.is_symmetric();
|
||||
assert !a.is_diagonal();
|
||||
assert a.is_rotated();
|
||||
assert !a.is_invertible();
|
||||
assert!(!a.is_identity());
|
||||
assert!(!a.is_symmetric());
|
||||
assert!(!a.is_diagonal());
|
||||
assert!(a.is_rotated());
|
||||
assert!(!a.is_invertible());
|
||||
|
||||
let c = mat4::new(4.0, 3.0, 2.0, 1.0,
|
||||
3.0, 4.0, 3.0, 2.0,
|
||||
2.0, 3.0, 4.0, 3.0,
|
||||
1.0, 2.0, 3.0, 4.0);
|
||||
assert !c.is_identity();
|
||||
assert c.is_symmetric();
|
||||
assert !c.is_diagonal();
|
||||
assert c.is_rotated();
|
||||
assert c.is_invertible();
|
||||
assert!(!c.is_identity());
|
||||
assert!(c.is_symmetric());
|
||||
assert!(!c.is_diagonal());
|
||||
assert!(c.is_rotated());
|
||||
assert!(c.is_invertible());
|
||||
|
||||
assert mat4::from_value(6.0).is_diagonal();
|
||||
assert!(mat4::from_value(6.0).is_diagonal());
|
||||
}
|
||||
|
||||
fn test_mat4_mut() {
|
||||
|
@ -498,66 +498,66 @@ fn test_mat4_mut() {
|
|||
let mut mut_c: mat4 = c;
|
||||
|
||||
mut_a.swap_cols(0, 3);
|
||||
assert mut_a.col(0) == a.col(3);
|
||||
assert mut_a.col(3) == a.col(0);
|
||||
assert!(mut_a.col(0) == a.col(3));
|
||||
assert!(mut_a.col(3) == a.col(0));
|
||||
mut_a = a;
|
||||
|
||||
mut_a.swap_cols(1, 2);
|
||||
assert mut_a.col(1) == a.col(2);
|
||||
assert mut_a.col(2) == a.col(1);
|
||||
assert!(mut_a.col(1) == a.col(2));
|
||||
assert!(mut_a.col(2) == a.col(1));
|
||||
mut_a = a;
|
||||
|
||||
mut_a.swap_rows(0, 3);
|
||||
assert mut_a.row(0) == a.row(3);
|
||||
assert mut_a.row(3) == a.row(0);
|
||||
assert!(mut_a.row(0) == a.row(3));
|
||||
assert!(mut_a.row(3) == a.row(0));
|
||||
mut_a = a;
|
||||
|
||||
mut_a.swap_rows(1, 2);
|
||||
assert mut_a.row(1) == a.row(2);
|
||||
assert mut_a.row(2) == a.row(1);
|
||||
assert!(mut_a.row(1) == a.row(2));
|
||||
assert!(mut_a.row(2) == a.row(1));
|
||||
mut_a = a;
|
||||
|
||||
mut_a.set(&b);
|
||||
assert mut_a == b;
|
||||
assert!(mut_a == b);
|
||||
mut_a = a;
|
||||
|
||||
mut_a.to_identity();
|
||||
assert mut_a.is_identity();
|
||||
assert!(mut_a.is_identity());
|
||||
mut_a = a;
|
||||
|
||||
mut_a.to_zero();
|
||||
assert mut_a == mat4::zero();
|
||||
assert!(mut_a == mat4::zero());
|
||||
mut_a = a;
|
||||
|
||||
mut_a.mul_self_t(f1);
|
||||
assert mut_a == a.mul_t(f1);
|
||||
assert!(mut_a == a.mul_t(f1));
|
||||
mut_a = a;
|
||||
|
||||
mut_a.add_self_m(&b);
|
||||
assert mut_a == a.add_m(&b);
|
||||
assert!(mut_a == a.add_m(&b));
|
||||
mut_a = a;
|
||||
|
||||
mut_a.sub_self_m(&b);
|
||||
assert mut_a == a.sub_m(&b);
|
||||
assert!(mut_a == a.sub_m(&b));
|
||||
mut_a = a;
|
||||
|
||||
mut_c.invert_self();
|
||||
assert mut_c == option::unwrap(c.inverse());
|
||||
assert!(mut_c == option::unwrap(c.inverse()));
|
||||
// mut_c = c;
|
||||
|
||||
mut_a.transpose_self();
|
||||
assert mut_a == a.transpose();
|
||||
assert!(mut_a == a.transpose());
|
||||
// mut_a = a;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_mat4_fuzzy_eq() {
|
||||
assert !mat4::new(0.000001, 0.000001, 0.000001, 0.000001,
|
||||
assert!(!mat4::new(0.000001, 0.000001, 0.000001, 0.000001,
|
||||
0.000001, 0.000001, 0.000001, 0.000001,
|
||||
0.000001, 0.000001, 0.000001, 0.000001,
|
||||
0.000001, 0.000001, 0.000001, 0.000001).fuzzy_eq(&mat4::zero());
|
||||
assert mat4::new(0.0000001, 0.0000001, 0.0000001, 0.0000001,
|
||||
0.000001, 0.000001, 0.000001, 0.000001).fuzzy_eq(&mat4::zero()));
|
||||
assert!(mat4::new(0.0000001, 0.0000001, 0.0000001, 0.0000001,
|
||||
0.0000001, 0.0000001, 0.0000001, 0.0000001,
|
||||
0.0000001, 0.0000001, 0.0000001, 0.0000001,
|
||||
0.0000001, 0.0000001, 0.0000001, 0.0000001).fuzzy_eq(&mat4::zero());
|
||||
0.0000001, 0.0000001, 0.0000001, 0.0000001).fuzzy_eq(&mat4::zero()));
|
||||
}
|
|
@ -10,20 +10,20 @@ use vec::*;
|
|||
fn test_quat() {
|
||||
let a = Quat { s: 1.0, v: Vec3 { x: 2.0, y: 3.0, z: 4.0 } };
|
||||
|
||||
assert a == quat::from_sv(1.0, vec3::new(2.0, 3.0, 4.0));
|
||||
assert a == quat::new(1.0, 2.0, 3.0, 4.0);
|
||||
assert!(a == quat::from_sv(1.0, vec3::new(2.0, 3.0, 4.0)));
|
||||
assert!(a == quat::new(1.0, 2.0, 3.0, 4.0));
|
||||
|
||||
assert quat::zero() == quat::new(0.0, 0.0, 0.0, 0.0);
|
||||
assert quat::identity() == quat::new(1.0, 0.0, 0.0, 0.0);
|
||||
assert!(quat::zero() == quat::new(0.0, 0.0, 0.0, 0.0));
|
||||
assert!(quat::identity() == quat::new(1.0, 0.0, 0.0, 0.0));
|
||||
|
||||
assert a.s == 1.0;
|
||||
assert a.v.x == 2.0;
|
||||
assert a.v.y == 3.0;
|
||||
assert a.v.z == 4.0;
|
||||
assert a[0] == 1.0;
|
||||
assert a[1] == 2.0;
|
||||
assert a[2] == 3.0;
|
||||
assert a[3] == 4.0;
|
||||
assert!(a.s == 1.0);
|
||||
assert!(a.v.x == 2.0);
|
||||
assert!(a.v.y == 3.0);
|
||||
assert!(a.v.z == 4.0);
|
||||
assert!(a[0] == 1.0);
|
||||
assert!(a[1] == 2.0);
|
||||
assert!(a[2] == 3.0);
|
||||
assert!(a[3] == 4.0);
|
||||
// TODO
|
||||
}
|
||||
|
||||
|
@ -34,15 +34,15 @@ fn test_quat_2() {
|
|||
let q = quat::from_angle_axis(radians(-45f32), &vec3::new(0f32, 0f32, -1f32));
|
||||
|
||||
// http://www.wolframalpha.com/input/?i={1,0}+rotate+-45+degrees
|
||||
assert q.mul_v(&v).fuzzy_eq(&vec3::new(1f32/sqrt(2f32), 1f32/sqrt(2f32), 0f32));
|
||||
assert q.mul_v(&v).length() == v.length();
|
||||
assert q.to_mat3().fuzzy_eq(&mat3::new( 1f32/sqrt(2f32), 1f32/sqrt(2f32), 0f32,
|
||||
-1f32/sqrt(2f32), 1f32/sqrt(2f32), 0f32,
|
||||
0f32, 0f32, 1f32));
|
||||
assert!(q.mul_v(&v).fuzzy_eq(&vec3::new(1f32/sqrt(2f32), 1f32/sqrt(2f32), 0f32)));
|
||||
assert!(q.mul_v(&v).length() == v.length());
|
||||
assert!(q.to_mat3().fuzzy_eq(&mat3::new( 1f32/sqrt(2f32), 1f32/sqrt(2f32), 0f32,
|
||||
-1f32/sqrt(2f32), 1f32/sqrt(2f32), 0f32,
|
||||
0f32, 0f32, 1f32)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_quat_fuzzy_eq() {
|
||||
assert !quat::new(0.000001, 0.000001, 0.000001, 0.000001).fuzzy_eq(&quat::new(0.0, 0.0, 0.0, 0.0));
|
||||
assert quat::new(0.0000001, 0.0000001, 0.0000001, 0.0000001).fuzzy_eq(&quat::new(0.0, 0.0, 0.0, 0.0));
|
||||
assert!(!quat::new(0.000001, 0.000001, 0.000001, 0.000001).fuzzy_eq(&quat::new(0.0, 0.0, 0.0, 0.0)));
|
||||
assert!(quat::new(0.0000001, 0.0000001, 0.0000001, 0.0000001).fuzzy_eq(&quat::new(0.0, 0.0, 0.0, 0.0)));
|
||||
}
|
|
@ -8,7 +8,7 @@ use vec::*;
|
|||
|
||||
#[test]
|
||||
fn test_vec2() {
|
||||
// assert vec2::dim == 2;
|
||||
// assert!(vec2::dim == 2);
|
||||
|
||||
let a = Vec2 { x: 1.0, y: 2.0 };
|
||||
let b = Vec2 { x: 3.0, y: 4.0 };
|
||||
|
@ -17,80 +17,80 @@ fn test_vec2() {
|
|||
|
||||
let mut mut_a = a;
|
||||
|
||||
assert vec2::new(1.0, 2.0) == a;
|
||||
assert vec2::from_value(1.0) == vec2::new(1.0, 1.0);
|
||||
assert!(vec2::new(1.0, 2.0) == a);
|
||||
assert!(vec2::from_value(1.0) == vec2::new(1.0, 1.0));
|
||||
|
||||
assert vec2::zero() == vec2::new(0.0, 0.0);
|
||||
assert vec2::unit_x() == vec2::new(1.0, 0.0);
|
||||
assert vec2::unit_y() == vec2::new(0.0, 1.0);
|
||||
assert vec2::identity() == vec2::new(1.0, 1.0);
|
||||
assert!(vec2::zero() == vec2::new(0.0, 0.0));
|
||||
assert!(vec2::unit_x() == vec2::new(1.0, 0.0));
|
||||
assert!(vec2::unit_y() == vec2::new(0.0, 1.0));
|
||||
assert!(vec2::identity() == vec2::new(1.0, 1.0));
|
||||
|
||||
*mut_a.index_mut(0) = 42.0;
|
||||
*mut_a.index_mut(1) = 43.0;
|
||||
assert mut_a == vec2::new(42.0, 43.0);
|
||||
assert!(mut_a == vec2::new(42.0, 43.0));
|
||||
mut_a = a;
|
||||
|
||||
mut_a.swap(0, 1);
|
||||
assert mut_a[0] == a[1];
|
||||
assert mut_a[1] == a[0];
|
||||
assert!(mut_a[0] == a[1]);
|
||||
assert!(mut_a[1] == a[0]);
|
||||
mut_a = a;
|
||||
|
||||
assert a.x == 1.0;
|
||||
assert a.y == 2.0;
|
||||
assert a[0] == 1.0;
|
||||
assert a[1] == 2.0;
|
||||
assert!(a.x == 1.0);
|
||||
assert!(a.y == 2.0);
|
||||
assert!(a[0] == 1.0);
|
||||
assert!(a[1] == 2.0);
|
||||
|
||||
assert -a == vec2::new(-1.0, -2.0);
|
||||
assert a.neg() == vec2::new(-1.0, -2.0);
|
||||
assert!(-a == vec2::new(-1.0, -2.0));
|
||||
assert!(a.neg() == vec2::new(-1.0, -2.0));
|
||||
|
||||
assert vec2::new(0.0, 0.0).is_zero();
|
||||
assert !vec2::new(1.0, 1.0).is_zero();
|
||||
assert!(vec2::new(0.0, 0.0).is_zero());
|
||||
assert!(!vec2::new(1.0, 1.0).is_zero());
|
||||
|
||||
assert a.mul_t(f1) == vec2::new( 1.5, 3.0);
|
||||
assert a.div_t(f2) == vec2::new( 2.0, 4.0);
|
||||
assert!(a.mul_t(f1) == vec2::new( 1.5, 3.0));
|
||||
assert!(a.div_t(f2) == vec2::new( 2.0, 4.0));
|
||||
|
||||
assert a.add_v(&b) == vec2::new( 4.0, 6.0);
|
||||
assert a.sub_v(&b) == vec2::new( -2.0, -2.0);
|
||||
assert a.mul_v(&b) == vec2::new( 3.0, 8.0);
|
||||
assert a.div_v(&b) == vec2::new(1.0/3.0, 2.0/4.0);
|
||||
assert!(a.add_v(&b) == vec2::new( 4.0, 6.0));
|
||||
assert!(a.sub_v(&b) == vec2::new( -2.0, -2.0));
|
||||
assert!(a.mul_v(&b) == vec2::new( 3.0, 8.0));
|
||||
assert!(a.div_v(&b) == vec2::new(1.0/3.0, 2.0/4.0));
|
||||
|
||||
mut_a.neg_self();
|
||||
assert mut_a == -a;
|
||||
assert!(mut_a == -a);
|
||||
mut_a = a;
|
||||
|
||||
mut_a.mul_self_t(&f1);
|
||||
assert mut_a == a.mul_t(f1);
|
||||
assert!(mut_a == a.mul_t(f1));
|
||||
mut_a = a;
|
||||
|
||||
mut_a.div_self_t(&f2);
|
||||
assert mut_a == a.div_t(f2);
|
||||
assert!(mut_a == a.div_t(f2));
|
||||
mut_a = a;
|
||||
|
||||
mut_a.add_self_v(&b);
|
||||
assert mut_a == a.add_v(&b);
|
||||
assert!(mut_a == a.add_v(&b));
|
||||
mut_a = a;
|
||||
|
||||
mut_a.sub_self_v(&b);
|
||||
assert mut_a == a.sub_v(&b);
|
||||
assert!(mut_a == a.sub_v(&b));
|
||||
mut_a = a;
|
||||
|
||||
mut_a.mul_self_v(&b);
|
||||
assert mut_a == a.mul_v(&b);
|
||||
assert!(mut_a == a.mul_v(&b));
|
||||
mut_a = a;
|
||||
|
||||
mut_a.div_self_v(&b);
|
||||
assert mut_a == a.div_v(&b);
|
||||
assert!(mut_a == a.div_v(&b));
|
||||
// mut_a = a;
|
||||
|
||||
// assert c.abs() == vec2::new( 2.0, 1.0);
|
||||
// assert c.min(&d) == vec2::new(-2.0, -1.0);
|
||||
// assert c.max(&d) == vec2::new( 1.0, 0.0);
|
||||
// assert!(c.abs() == vec2::new( 2.0, 1.0));
|
||||
// assert!(c.min(&d) == vec2::new(-2.0, -1.0));
|
||||
// assert!(c.max(&d) == vec2::new( 1.0, 0.0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_vec2_fuzzy_eq() {
|
||||
assert !vec2::new(0.000001, 0.000001).fuzzy_eq(&vec2::new(0.0, 0.0));
|
||||
assert vec2::new(0.0000001, 0.0000001).fuzzy_eq(&vec2::new(0.0, 0.0));
|
||||
assert!(!vec2::new(0.000001, 0.000001).fuzzy_eq(&vec2::new(0.0, 0.0)));
|
||||
assert!(vec2::new(0.0000001, 0.0000001).fuzzy_eq(&vec2::new(0.0, 0.0)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -99,30 +99,30 @@ fn test_vec2_euclidean() {
|
|||
let b0 = vec2::new(3.0, 4.0); // (3, 4, 5) Pythagorean triple
|
||||
let b = a.add_v(&b0);
|
||||
|
||||
assert a.length() == 13.0;
|
||||
assert a.length2() == 13.0 * 13.0;
|
||||
assert!(a.length() == 13.0);
|
||||
assert!(a.length2() == 13.0 * 13.0);
|
||||
|
||||
assert b0.length() == 5.0;
|
||||
assert b0.length2() == 5.0 * 5.0;
|
||||
assert!(b0.length() == 5.0);
|
||||
assert!(b0.length2() == 5.0 * 5.0);
|
||||
|
||||
assert a.distance(&b) == 5.0;
|
||||
assert a.distance2(&b) == 5.0 * 5.0;
|
||||
assert!(a.distance(&b) == 5.0);
|
||||
assert!(a.distance2(&b) == 5.0 * 5.0);
|
||||
|
||||
assert vec2::new(1.0, 0.0).angle(&vec2::new(0.0, 1.0)).fuzzy_eq(&Float::frac_pi_2());
|
||||
assert vec2::new(10.0, 0.0).angle(&vec2::new(0.0, 5.0)).fuzzy_eq(&Float::frac_pi_2());
|
||||
assert vec2::new(-1.0, 0.0).angle(&vec2::new(0.0, 1.0)).fuzzy_eq(&Float::frac_pi_2());
|
||||
assert!(vec2::new(1.0, 0.0).angle(&vec2::new(0.0, 1.0)).fuzzy_eq(&Float::frac_pi_2()));
|
||||
assert!(vec2::new(10.0, 0.0).angle(&vec2::new(0.0, 5.0)).fuzzy_eq(&Float::frac_pi_2()));
|
||||
assert!(vec2::new(-1.0, 0.0).angle(&vec2::new(0.0, 1.0)).fuzzy_eq(&Float::frac_pi_2()));
|
||||
|
||||
assert vec2::new(3.0, 4.0).normalize().fuzzy_eq(&vec2::new(3.0/5.0, 4.0/5.0));
|
||||
assert!(vec2::new(3.0, 4.0).normalize().fuzzy_eq(&vec2::new(3.0/5.0, 4.0/5.0)));
|
||||
// TODO: test normalize_to, normalize_self, and normalize_self_to
|
||||
|
||||
let c = vec2::new(-2.0, -1.0);
|
||||
let d = vec2::new( 1.0, 0.0);
|
||||
|
||||
assert c.lerp(&d, 0.75) == vec2::new(0.250, -0.250);
|
||||
assert!(c.lerp(&d, 0.75) == vec2::new(0.250, -0.250));
|
||||
|
||||
let mut mut_c = c;
|
||||
mut_c.lerp_self(&d, &0.75);
|
||||
assert mut_c == c.lerp(&d, 0.75);
|
||||
assert!(mut_c == c.lerp(&d, 0.75));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -131,22 +131,22 @@ fn test_vec2_boolean() {
|
|||
let ff = bvec2::new(false, false);
|
||||
let tt = bvec2::new(true, true);
|
||||
|
||||
assert tf.any() == true;
|
||||
assert tf.all() == false;
|
||||
assert tf.not() == bvec2::new(false, true);
|
||||
assert!(tf.any() == true);
|
||||
assert!(tf.all() == false);
|
||||
assert!(tf.not() == bvec2::new(false, true));
|
||||
|
||||
assert ff.any() == false;
|
||||
assert ff.all() == false;
|
||||
assert ff.not() == bvec2::new(true, true);
|
||||
assert!(ff.any() == false);
|
||||
assert!(ff.all() == false);
|
||||
assert!(ff.not() == bvec2::new(true, true));
|
||||
|
||||
assert tt.any() == true;
|
||||
assert tt.all() == true;
|
||||
assert tt.not() == bvec2::new(false, false);
|
||||
assert!(tt.any() == true);
|
||||
assert!(tt.all() == true);
|
||||
assert!(tt.not() == bvec2::new(false, false));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_vec3() {
|
||||
// assert Vec3::dim == 3;
|
||||
// assert!(Vec3::dim == 3);
|
||||
|
||||
let a = Vec3 { x: 1.0, y: 2.0, z: 3.0 };
|
||||
let b = Vec3 { x: 4.0, y: 5.0, z: 6.0 };
|
||||
|
@ -155,99 +155,99 @@ fn test_vec3() {
|
|||
|
||||
let mut mut_a = a;
|
||||
|
||||
assert vec3::new(1.0, 2.0, 3.0) == a;
|
||||
assert vec3::from_value(1.0) == vec3::new(1.0, 1.0, 1.0);
|
||||
assert!(vec3::new(1.0, 2.0, 3.0) == a);
|
||||
assert!(vec3::from_value(1.0) == vec3::new(1.0, 1.0, 1.0));
|
||||
|
||||
assert vec3::zero() == vec3::new(0.0, 0.0, 0.0);
|
||||
assert vec3::unit_x() == vec3::new(1.0, 0.0, 0.0);
|
||||
assert vec3::unit_y() == vec3::new(0.0, 1.0, 0.0);
|
||||
assert vec3::unit_z() == vec3::new(0.0, 0.0, 1.0);
|
||||
assert vec3::identity() == vec3::new(1.0, 1.0, 1.0);
|
||||
assert!(vec3::zero() == vec3::new(0.0, 0.0, 0.0));
|
||||
assert!(vec3::unit_x() == vec3::new(1.0, 0.0, 0.0));
|
||||
assert!(vec3::unit_y() == vec3::new(0.0, 1.0, 0.0));
|
||||
assert!(vec3::unit_z() == vec3::new(0.0, 0.0, 1.0));
|
||||
assert!(vec3::identity() == vec3::new(1.0, 1.0, 1.0));
|
||||
|
||||
*mut_a.index_mut(0) = 42.0;
|
||||
*mut_a.index_mut(1) = 43.0;
|
||||
*mut_a.index_mut(2) = 44.0;
|
||||
assert mut_a == vec3::new(42.0, 43.0, 44.0);
|
||||
assert!(mut_a == vec3::new(42.0, 43.0, 44.0));
|
||||
mut_a = a;
|
||||
|
||||
mut_a.swap(0, 2);
|
||||
assert mut_a[0] == a[2];
|
||||
assert mut_a[2] == a[0];
|
||||
assert!(mut_a[0] == a[2]);
|
||||
assert!(mut_a[2] == a[0]);
|
||||
mut_a = a;
|
||||
|
||||
mut_a.swap(1, 2);
|
||||
assert mut_a[1] == a[2];
|
||||
assert mut_a[2] == a[1];
|
||||
assert!(mut_a[1] == a[2]);
|
||||
assert!(mut_a[2] == a[1]);
|
||||
mut_a = a;
|
||||
|
||||
assert a.x == 1.0;
|
||||
assert a.y == 2.0;
|
||||
assert a.z == 3.0;
|
||||
assert a[0] == 1.0;
|
||||
assert a[1] == 2.0;
|
||||
assert a[2] == 3.0;
|
||||
assert!(a.x == 1.0);
|
||||
assert!(a.y == 2.0);
|
||||
assert!(a.z == 3.0);
|
||||
assert!(a[0] == 1.0);
|
||||
assert!(a[1] == 2.0);
|
||||
assert!(a[2] == 3.0);
|
||||
|
||||
assert a.cross(&b) == vec3::new(-3.0, 6.0, -3.0);
|
||||
assert!(a.cross(&b) == vec3::new(-3.0, 6.0, -3.0));
|
||||
|
||||
mut_a.cross_self(&b);
|
||||
assert mut_a == a.cross(&b);
|
||||
assert!(mut_a == a.cross(&b));
|
||||
mut_a = a;
|
||||
|
||||
assert -a == vec3::new(-1.0, -2.0, -3.0);
|
||||
assert a.neg() == vec3::new(-1.0, -2.0, -3.0);
|
||||
assert!(-a == vec3::new(-1.0, -2.0, -3.0));
|
||||
assert!(a.neg() == vec3::new(-1.0, -2.0, -3.0));
|
||||
|
||||
assert vec3::new(0.0, 0.0, 0.0).is_zero();
|
||||
assert !vec3::new(1.0, 1.0, 1.0).is_zero();
|
||||
assert!(vec3::new(0.0, 0.0, 0.0).is_zero());
|
||||
assert!(!vec3::new(1.0, 1.0, 1.0).is_zero());
|
||||
|
||||
assert a.mul_t(f1) == vec3::new( 1.5, 3.0, 4.5);
|
||||
assert a.div_t(f2) == vec3::new( 2.0, 4.0, 6.0);
|
||||
assert!(a.mul_t(f1) == vec3::new( 1.5, 3.0, 4.5));
|
||||
assert!(a.div_t(f2) == vec3::new( 2.0, 4.0, 6.0));
|
||||
|
||||
assert a.add_v(&b) == vec3::new( 5.0, 7.0, 9.0);
|
||||
assert a.sub_v(&b) == vec3::new( -3.0, -3.0, -3.0);
|
||||
assert a.mul_v(&b) == vec3::new( 4.0, 10.0, 18.0);
|
||||
assert a.div_v(&b) == vec3::new(1.0/4.0, 2.0/5.0, 3.0/6.0);
|
||||
assert!(a.add_v(&b) == vec3::new( 5.0, 7.0, 9.0));
|
||||
assert!(a.sub_v(&b) == vec3::new( -3.0, -3.0, -3.0));
|
||||
assert!(a.mul_v(&b) == vec3::new( 4.0, 10.0, 18.0));
|
||||
assert!(a.div_v(&b) == vec3::new(1.0/4.0, 2.0/5.0, 3.0/6.0));
|
||||
|
||||
mut_a.neg_self();
|
||||
assert mut_a == -a;
|
||||
assert!(mut_a == -a);
|
||||
mut_a = a;
|
||||
|
||||
mut_a.mul_self_t(&f1);
|
||||
assert mut_a == a.mul_t(f1);
|
||||
assert!(mut_a == a.mul_t(f1));
|
||||
mut_a = a;
|
||||
|
||||
mut_a.div_self_t(&f2);
|
||||
assert mut_a == a.div_t(f2);
|
||||
assert!(mut_a == a.div_t(f2));
|
||||
mut_a = a;
|
||||
|
||||
mut_a.add_self_v(&b);
|
||||
assert mut_a == a.add_v(&b);
|
||||
assert!(mut_a == a.add_v(&b));
|
||||
mut_a = a;
|
||||
|
||||
mut_a.sub_self_v(&b);
|
||||
assert mut_a == a.sub_v(&b);
|
||||
assert!(mut_a == a.sub_v(&b));
|
||||
mut_a = a;
|
||||
|
||||
mut_a.mul_self_v(&b);
|
||||
assert mut_a == a.mul_v(&b);
|
||||
assert!(mut_a == a.mul_v(&b));
|
||||
mut_a = a;
|
||||
|
||||
mut_a.div_self_v(&b);
|
||||
assert mut_a == a.div_v(&b);
|
||||
assert!(mut_a == a.div_v(&b));
|
||||
// mut_a = a;
|
||||
|
||||
// exact_eq
|
||||
// fuzzy_eq
|
||||
// eq
|
||||
|
||||
// assert c.abs() == vec3::new( 2.0, 1.0, 1.0);
|
||||
// assert c.min(&d) == vec3::new(-2.0, -1.0, 0.5);
|
||||
// assert c.max(&d) == vec3::new( 1.0, 0.0, 1.0);
|
||||
// assert!(c.abs() == vec3::new( 2.0, 1.0, 1.0));
|
||||
// assert!(c.min(&d) == vec3::new(-2.0, -1.0, 0.5));
|
||||
// assert!(c.max(&d) == vec3::new( 1.0, 0.0, 1.0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_vec3_fuzzy_eq() {
|
||||
assert !vec3::new(0.000001, 0.000001, 0.000001).fuzzy_eq(&vec3::new(0.0, 0.0, 0.0));
|
||||
assert vec3::new(0.0000001, 0.0000001, 0.0000001).fuzzy_eq(&vec3::new(0.0, 0.0, 0.0));
|
||||
assert!(!vec3::new(0.000001, 0.000001, 0.000001).fuzzy_eq(&vec3::new(0.0, 0.0, 0.0)));
|
||||
assert!(vec3::new(0.0000001, 0.0000001, 0.0000001).fuzzy_eq(&vec3::new(0.0, 0.0, 0.0)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -256,30 +256,30 @@ fn test_vec3_euclidean() {
|
|||
let b0 = vec3::new(1.0, 4.0, 8.0); // (1, 4, 8, 9) Pythagorean quadruple
|
||||
let b = a.add_v(&b0);
|
||||
|
||||
assert a.length() == 7.0;
|
||||
assert a.length2() == 7.0 * 7.0;
|
||||
assert!(a.length() == 7.0);
|
||||
assert!(a.length2() == 7.0 * 7.0);
|
||||
|
||||
assert b0.length() == 9.0;
|
||||
assert b0.length2() == 9.0 * 9.0;
|
||||
assert!(b0.length() == 9.0);
|
||||
assert!(b0.length2() == 9.0 * 9.0);
|
||||
|
||||
assert a.distance(&b) == 9.0;
|
||||
assert a.distance2(&b) == 9.0 * 9.0;
|
||||
assert!(a.distance(&b) == 9.0);
|
||||
assert!(a.distance2(&b) == 9.0 * 9.0);
|
||||
|
||||
assert vec3::new(1.0, 0.0, 1.0).angle(&vec3::new(1.0, 1.0, 0.0)).fuzzy_eq(&Float::frac_pi_3());
|
||||
assert vec3::new(10.0, 0.0, 10.0).angle(&vec3::new(5.0, 5.0, 0.0)).fuzzy_eq(&Float::frac_pi_3());
|
||||
assert vec3::new(-1.0, 0.0, -1.0).angle(&vec3::new(1.0, -1.0, 0.0)).fuzzy_eq(&(2.0 * Float::frac_pi_3()));
|
||||
assert!(vec3::new(1.0, 0.0, 1.0).angle(&vec3::new(1.0, 1.0, 0.0)).fuzzy_eq(&Float::frac_pi_3()));
|
||||
assert!(vec3::new(10.0, 0.0, 10.0).angle(&vec3::new(5.0, 5.0, 0.0)).fuzzy_eq(&Float::frac_pi_3()));
|
||||
assert!(vec3::new(-1.0, 0.0, -1.0).angle(&vec3::new(1.0, -1.0, 0.0)).fuzzy_eq(&(2.0 * Float::frac_pi_3())));
|
||||
|
||||
assert vec3::new(2.0, 3.0, 6.0).normalize().fuzzy_eq(&vec3::new(2.0/7.0, 3.0/7.0, 6.0/7.0));
|
||||
assert!(vec3::new(2.0, 3.0, 6.0).normalize().fuzzy_eq(&vec3::new(2.0/7.0, 3.0/7.0, 6.0/7.0)));
|
||||
// TODO: test normalize_to, normalize_self, and normalize_self_to
|
||||
|
||||
let c = vec3::new(-2.0, -1.0, 1.0);
|
||||
let d = vec3::new( 1.0, 0.0, 0.5);
|
||||
|
||||
assert c.lerp(&d, 0.75) == vec3::new(0.250, -0.250, 0.625);
|
||||
assert!(c.lerp(&d, 0.75) == vec3::new(0.250, -0.250, 0.625));
|
||||
|
||||
let mut mut_c = c;
|
||||
mut_c.lerp_self(&d, &0.75);
|
||||
assert mut_c == c.lerp(&d, 0.75);
|
||||
assert!(mut_c == c.lerp(&d, 0.75));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -288,22 +288,22 @@ fn test_vec3_boolean() {
|
|||
let fff = bvec3::new(false, false, false);
|
||||
let ttt = bvec3::new(true, true, true);
|
||||
|
||||
assert tft.any() == true;
|
||||
assert tft.all() == false;
|
||||
assert tft.not() == bvec3::new(false, true, false);
|
||||
assert!(tft.any() == true);
|
||||
assert!(tft.all() == false);
|
||||
assert!(tft.not() == bvec3::new(false, true, false));
|
||||
|
||||
assert fff.any() == false;
|
||||
assert fff.all() == false;
|
||||
assert fff.not() == bvec3::new(true, true, true);
|
||||
assert!(fff.any() == false);
|
||||
assert!(fff.all() == false);
|
||||
assert!(fff.not() == bvec3::new(true, true, true));
|
||||
|
||||
assert ttt.any() == true;
|
||||
assert ttt.all() == true;
|
||||
assert ttt.not() == bvec3::new(false, false, false);
|
||||
assert!(ttt.any() == true);
|
||||
assert!(ttt.all() == true);
|
||||
assert!(ttt.not() == bvec3::new(false, false, false));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_vec4() {
|
||||
// assert Vec4::dim == 4;
|
||||
// assert!(Vec4::dim == 4);
|
||||
|
||||
let a = Vec4 { x: 1.0, y: 2.0, z: 3.0, w: 4.0 };
|
||||
let b = Vec4 { x: 5.0, y: 6.0, z: 7.0, w: 8.0 };
|
||||
|
@ -312,95 +312,95 @@ fn test_vec4() {
|
|||
|
||||
let mut mut_a = a;
|
||||
|
||||
assert vec4::new(1.0, 2.0, 3.0, 4.0) == a;
|
||||
assert vec4::from_value(1.0) == vec4::new(1.0, 1.0, 1.0, 1.0);
|
||||
assert!(vec4::new(1.0, 2.0, 3.0, 4.0) == a);
|
||||
assert!(vec4::from_value(1.0) == vec4::new(1.0, 1.0, 1.0, 1.0));
|
||||
|
||||
*mut_a.index_mut(0) = 42.0;
|
||||
*mut_a.index_mut(1) = 43.0;
|
||||
*mut_a.index_mut(2) = 44.0;
|
||||
*mut_a.index_mut(3) = 45.0;
|
||||
assert mut_a == vec4::new(42.0, 43.0, 44.0, 45.0);
|
||||
assert!(mut_a == vec4::new(42.0, 43.0, 44.0, 45.0));
|
||||
mut_a = a;
|
||||
|
||||
mut_a.swap(0, 3);
|
||||
assert mut_a[0] == a[3];
|
||||
assert mut_a[3] == a[0];
|
||||
assert!(mut_a[0] == a[3]);
|
||||
assert!(mut_a[3] == a[0]);
|
||||
mut_a = a;
|
||||
|
||||
mut_a.swap(1, 2);
|
||||
assert mut_a[1] == a[2];
|
||||
assert mut_a[2] == a[1];
|
||||
assert!(mut_a[1] == a[2]);
|
||||
assert!(mut_a[2] == a[1]);
|
||||
mut_a = a;
|
||||
|
||||
assert vec4::zero() == vec4::new(0.0, 0.0, 0.0, 0.0);
|
||||
assert vec4::unit_x() == vec4::new(1.0, 0.0, 0.0, 0.0);
|
||||
assert vec4::unit_y() == vec4::new(0.0, 1.0, 0.0, 0.0);
|
||||
assert vec4::unit_z() == vec4::new(0.0, 0.0, 1.0, 0.0);
|
||||
assert vec4::unit_w() == vec4::new(0.0, 0.0, 0.0, 1.0);
|
||||
assert vec4::identity() == vec4::new(1.0, 1.0, 1.0, 1.0);
|
||||
assert!(vec4::zero() == vec4::new(0.0, 0.0, 0.0, 0.0));
|
||||
assert!(vec4::unit_x() == vec4::new(1.0, 0.0, 0.0, 0.0));
|
||||
assert!(vec4::unit_y() == vec4::new(0.0, 1.0, 0.0, 0.0));
|
||||
assert!(vec4::unit_z() == vec4::new(0.0, 0.0, 1.0, 0.0));
|
||||
assert!(vec4::unit_w() == vec4::new(0.0, 0.0, 0.0, 1.0));
|
||||
assert!(vec4::identity() == vec4::new(1.0, 1.0, 1.0, 1.0));
|
||||
|
||||
assert a.x == 1.0;
|
||||
assert a.y == 2.0;
|
||||
assert a.z == 3.0;
|
||||
assert a.w == 4.0;
|
||||
assert a[0] == 1.0;
|
||||
assert a[1] == 2.0;
|
||||
assert a[2] == 3.0;
|
||||
assert a[3] == 4.0;
|
||||
assert!(a.x == 1.0);
|
||||
assert!(a.y == 2.0);
|
||||
assert!(a.z == 3.0);
|
||||
assert!(a.w == 4.0);
|
||||
assert!(a[0] == 1.0);
|
||||
assert!(a[1] == 2.0);
|
||||
assert!(a[2] == 3.0);
|
||||
assert!(a[3] == 4.0);
|
||||
|
||||
assert -a == vec4::new(-1.0, -2.0, -3.0, -4.0);
|
||||
assert a.neg() == vec4::new(-1.0, -2.0, -3.0, -4.0);
|
||||
assert!(-a == vec4::new(-1.0, -2.0, -3.0, -4.0));
|
||||
assert!(a.neg() == vec4::new(-1.0, -2.0, -3.0, -4.0));
|
||||
|
||||
assert vec4::new(0.0, 0.0, 0.0, 0.0).is_zero();
|
||||
assert !vec4::new(1.0, 1.0, 1.0, 1.0).is_zero();
|
||||
assert!(vec4::new(0.0, 0.0, 0.0, 0.0).is_zero());
|
||||
assert!(!vec4::new(1.0, 1.0, 1.0, 1.0).is_zero());
|
||||
|
||||
assert a.mul_t(f1) == vec4::new( 1.5, 3.0, 4.5, 6.0);
|
||||
assert a.div_t(f2) == vec4::new( 2.0, 4.0, 6.0, 8.0);
|
||||
assert!(a.mul_t(f1) == vec4::new( 1.5, 3.0, 4.5, 6.0));
|
||||
assert!(a.div_t(f2) == vec4::new( 2.0, 4.0, 6.0, 8.0));
|
||||
|
||||
assert a.add_v(&b) == vec4::new( 6.0, 8.0, 10.0, 12.0);
|
||||
assert a.sub_v(&b) == vec4::new( -4.0, -4.0, -4.0, -4.0);
|
||||
assert a.mul_v(&b) == vec4::new( 5.0, 12.0, 21.0, 32.0);
|
||||
assert a.div_v(&b) == vec4::new(1.0/5.0, 2.0/6.0, 3.0/7.0, 4.0/8.0);
|
||||
assert!(a.add_v(&b) == vec4::new( 6.0, 8.0, 10.0, 12.0));
|
||||
assert!(a.sub_v(&b) == vec4::new( -4.0, -4.0, -4.0, -4.0));
|
||||
assert!(a.mul_v(&b) == vec4::new( 5.0, 12.0, 21.0, 32.0));
|
||||
assert!(a.div_v(&b) == vec4::new(1.0/5.0, 2.0/6.0, 3.0/7.0, 4.0/8.0));
|
||||
|
||||
assert a.dot(&b) == 70.0;
|
||||
assert!(a.dot(&b) == 70.0);
|
||||
|
||||
mut_a.neg_self();
|
||||
assert mut_a == -a;
|
||||
assert!(mut_a == -a);
|
||||
mut_a = a;
|
||||
|
||||
mut_a.mul_self_t(&f1);
|
||||
assert mut_a == a.mul_t(f1);
|
||||
assert!(mut_a == a.mul_t(f1));
|
||||
mut_a = a;
|
||||
|
||||
mut_a.div_self_t(&f2);
|
||||
assert mut_a == a.div_t(f2);
|
||||
assert!(mut_a == a.div_t(f2));
|
||||
mut_a = a;
|
||||
|
||||
mut_a.add_self_v(&b);
|
||||
assert mut_a == a.add_v(&b);
|
||||
assert!(mut_a == a.add_v(&b));
|
||||
mut_a = a;
|
||||
|
||||
mut_a.sub_self_v(&b);
|
||||
assert mut_a == a.sub_v(&b);
|
||||
assert!(mut_a == a.sub_v(&b));
|
||||
mut_a = a;
|
||||
|
||||
mut_a.mul_self_v(&b);
|
||||
assert mut_a == a.mul_v(&b);
|
||||
assert!(mut_a == a.mul_v(&b));
|
||||
mut_a = a;
|
||||
|
||||
mut_a.div_self_v(&b);
|
||||
assert mut_a == a.div_v(&b);
|
||||
assert!(mut_a == a.div_v(&b));
|
||||
// mut_a = a;
|
||||
|
||||
// assert c.abs() == vec4::new( 2.0, 1.0, 1.0, 2.0);
|
||||
// assert c.min(&d) == vec4::new(-2.0, -1.0, 0.5, 1.0);
|
||||
// assert c.max(&d) == vec4::new( 1.0, 0.0, 1.0, 2.0);
|
||||
// assert!(c.abs() == vec4::new( 2.0, 1.0, 1.0, 2.0));
|
||||
// assert!(c.min(&d) == vec4::new(-2.0, -1.0, 0.5, 1.0));
|
||||
// assert!(c.max(&d) == vec4::new( 1.0, 0.0, 1.0, 2.0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_vec4_fuzzy_eq() {
|
||||
assert !vec4::new(0.000001, 0.000001, 0.000001, 0.000001).fuzzy_eq(&vec4::new(0.0, 0.0, 0.0, 0.0));
|
||||
assert vec4::new(0.0000001, 0.0000001, 0.0000001, 0.0000001).fuzzy_eq(&vec4::new(0.0, 0.0, 0.0, 0.0));
|
||||
assert!(!vec4::new(0.000001, 0.000001, 0.000001, 0.000001).fuzzy_eq(&vec4::new(0.0, 0.0, 0.0, 0.0)));
|
||||
assert!(vec4::new(0.0000001, 0.0000001, 0.0000001, 0.0000001).fuzzy_eq(&vec4::new(0.0, 0.0, 0.0, 0.0)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -409,30 +409,30 @@ fn test_vec4_euclidean() {
|
|||
let b0 = vec4::new(1.0, 2.0, 8.0, 10.0); // (1, 2, 8, 10, 13) Pythagorean quintuple
|
||||
let b = a.add_v(&b0);
|
||||
|
||||
assert a.length() == 11.0;
|
||||
assert a.length2() == 11.0 * 11.0;
|
||||
assert!(a.length() == 11.0);
|
||||
assert!(a.length2() == 11.0 * 11.0);
|
||||
|
||||
assert b0.length() == 13.0;
|
||||
assert b0.length2() == 13.0 * 13.0;
|
||||
assert!(b0.length() == 13.0);
|
||||
assert!(b0.length2() == 13.0 * 13.0);
|
||||
|
||||
assert a.distance(&b) == 13.0;
|
||||
assert a.distance2(&b) == 13.0 * 13.0;
|
||||
assert!(a.distance(&b) == 13.0);
|
||||
assert!(a.distance2(&b) == 13.0 * 13.0);
|
||||
|
||||
assert vec4::new(1.0, 0.0, 1.0, 0.0).angle(&vec4::new(0.0, 1.0, 0.0, 1.0)).fuzzy_eq(&Float::frac_pi_2());
|
||||
assert vec4::new(10.0, 0.0, 10.0, 0.0).angle(&vec4::new(0.0, 5.0, 0.0, 5.0)).fuzzy_eq(&Float::frac_pi_2());
|
||||
assert vec4::new(-1.0, 0.0, -1.0, 0.0).angle(&vec4::new(0.0, 1.0, 0.0, 1.0)).fuzzy_eq(&Float::frac_pi_2());
|
||||
assert!(vec4::new(1.0, 0.0, 1.0, 0.0).angle(&vec4::new(0.0, 1.0, 0.0, 1.0)).fuzzy_eq(&Float::frac_pi_2()));
|
||||
assert!(vec4::new(10.0, 0.0, 10.0, 0.0).angle(&vec4::new(0.0, 5.0, 0.0, 5.0)).fuzzy_eq(&Float::frac_pi_2()));
|
||||
assert!(vec4::new(-1.0, 0.0, -1.0, 0.0).angle(&vec4::new(0.0, 1.0, 0.0, 1.0)).fuzzy_eq(&Float::frac_pi_2()));
|
||||
|
||||
assert vec4::new(1.0, 2.0, 4.0, 10.0).normalize().fuzzy_eq(&vec4::new(1.0/11.0, 2.0/11.0, 4.0/11.0, 10.0/11.0));
|
||||
assert!(vec4::new(1.0, 2.0, 4.0, 10.0).normalize().fuzzy_eq(&vec4::new(1.0/11.0, 2.0/11.0, 4.0/11.0, 10.0/11.0)));
|
||||
// TODO: test normalize_to, normalize_self, and normalize_self_to
|
||||
|
||||
let c = vec4::new(-2.0, -1.0, 1.0, 2.0);
|
||||
let d = vec4::new( 1.0, 0.0, 0.5, 1.0);
|
||||
|
||||
assert c.lerp(&d, 0.75) == vec4::new(0.250, -0.250, 0.625, 1.250);
|
||||
assert!(c.lerp(&d, 0.75) == vec4::new(0.250, -0.250, 0.625, 1.250));
|
||||
|
||||
let mut mut_c = c;
|
||||
mut_c.lerp_self(&d, &0.75);
|
||||
assert mut_c == c.lerp(&d, 0.75);
|
||||
assert!(mut_c == c.lerp(&d, 0.75));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -441,15 +441,15 @@ fn test_vec4_boolean() {
|
|||
let ffff = bvec4::new(false, false, false, false);
|
||||
let tttt = bvec4::new(true, true, true, true);
|
||||
|
||||
assert tftf.any() == true;
|
||||
assert tftf.all() == false;
|
||||
assert tftf.not() == bvec4::new(false, true, false, true);
|
||||
assert!(tftf.any() == true);
|
||||
assert!(tftf.all() == false);
|
||||
assert!(tftf.not() == bvec4::new(false, true, false, true));
|
||||
|
||||
assert ffff.any() == false;
|
||||
assert ffff.all() == false;
|
||||
assert ffff.not() == bvec4::new(true, true, true, true);
|
||||
assert!(ffff.any() == false);
|
||||
assert!(ffff.all() == false);
|
||||
assert!(ffff.not() == bvec4::new(true, true, true, true));
|
||||
|
||||
assert tttt.any() == true;
|
||||
assert tttt.all() == true;
|
||||
assert tttt.not() == bvec4::new(false, false, false, false);
|
||||
assert!(tttt.any() == true);
|
||||
assert!(tttt.all() == true);
|
||||
assert!(tttt.not() == bvec4::new(false, false, false, false));
|
||||
}
|
Loading…
Reference in a new issue