Don't use index operator in tests
This commit is contained in:
parent
a913be0373
commit
36039228b6
3 changed files with 71 additions and 77 deletions
|
@ -15,7 +15,6 @@
|
||||||
|
|
||||||
use mat::*;
|
use mat::*;
|
||||||
use vec::*;
|
use vec::*;
|
||||||
use std::cmp::FuzzyEq;
|
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
|
|
||||||
|
@ -38,8 +37,8 @@ fn test_mat2() {
|
||||||
assert!(mat2::from_value(4.0) == mat2::new(4.0, 0.0,
|
assert!(mat2::from_value(4.0) == mat2::new(4.0, 0.0,
|
||||||
0.0, 4.0));
|
0.0, 4.0));
|
||||||
|
|
||||||
assert!(a[0] == vec2::new(1.0, 3.0));
|
assert!(*a.col(0) == vec2::new(1.0, 3.0));
|
||||||
assert!(a[1] == vec2::new(2.0, 4.0));
|
assert!(*a.col(1) == vec2::new(2.0, 4.0));
|
||||||
|
|
||||||
assert!(a.row(0) == vec2::new(1.0, 2.0));
|
assert!(a.row(0) == vec2::new(1.0, 2.0));
|
||||||
assert!(a.row(1) == vec2::new(3.0, 4.0));
|
assert!(a.row(1) == vec2::new(3.0, 4.0));
|
||||||
|
@ -169,11 +168,11 @@ fn test_mat2_mut() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_mat2_fuzzy_eq() {
|
fn test_mat2_approx_eq() {
|
||||||
assert!(!mat2::new(0.000001, 0.000001,
|
assert!(!mat2::new(0.000001, 0.000001,
|
||||||
0.000001, 0.000001).fuzzy_eq(&mat2::zero()));
|
0.000001, 0.000001).approx_eq(&mat2::zero()));
|
||||||
assert!(mat2::new(0.0000001, 0.0000001,
|
assert!(mat2::new(0.0000001, 0.0000001,
|
||||||
0.0000001, 0.0000001).fuzzy_eq(&mat2::zero()));
|
0.0000001, 0.0000001).approx_eq(&mat2::zero()));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -196,9 +195,9 @@ fn test_mat3() {
|
||||||
vec3::new(2.0, 5.0, 8.0),
|
vec3::new(2.0, 5.0, 8.0),
|
||||||
vec3::new(3.0, 6.0, 9.0)));
|
vec3::new(3.0, 6.0, 9.0)));
|
||||||
|
|
||||||
assert!(a[0] == vec3::new(1.0, 4.0, 7.0));
|
assert!(*a.col(0) == vec3::new(1.0, 4.0, 7.0));
|
||||||
assert!(a[1] == vec3::new(2.0, 5.0, 8.0));
|
assert!(*a.col(1) == vec3::new(2.0, 5.0, 8.0));
|
||||||
assert!(a[2] == vec3::new(3.0, 6.0, 9.0));
|
assert!(*a.col(2) == vec3::new(3.0, 6.0, 9.0));
|
||||||
|
|
||||||
assert!(a.row(0) == vec3::new(1.0, 2.0, 3.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(1) == vec3::new(4.0, 5.0, 6.0));
|
||||||
|
@ -358,13 +357,13 @@ fn test_mat3_mut() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_mat3_fuzzy_eq() {
|
fn test_mat3_approx_eq() {
|
||||||
assert!(!mat3::new(0.000001, 0.000001, 0.000001,
|
assert!(!mat3::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).fuzzy_eq(&mat3::zero()));
|
0.000001, 0.000001, 0.000001).approx_eq(&mat3::zero()));
|
||||||
assert!(mat3::new(0.0000001, 0.0000001, 0.0000001,
|
assert!(mat3::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).fuzzy_eq(&mat3::zero()));
|
0.0000001, 0.0000001, 0.0000001).approx_eq(&mat3::zero()));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -400,10 +399,10 @@ fn test_mat4() {
|
||||||
0.0, 0.0, 4.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, 4.0));
|
||||||
|
|
||||||
assert!(a[0] == vec4::new(1.0, 5.0, 9.0, 13.0));
|
assert!(*a.col(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.col(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.col(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.col(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(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(1) == vec4::new( 5.0, 6.0, 7.0, 8.0));
|
||||||
|
@ -460,7 +459,7 @@ fn test_mat4() {
|
||||||
13.0, 14.0, 15.0, 16.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,
|
.approx_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, 0.0,
|
||||||
4.0, -8.0, 4.0, 8.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)));
|
||||||
|
@ -567,13 +566,13 @@ fn test_mat4_mut() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_mat4_fuzzy_eq() {
|
fn test_mat4_approx_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,
|
0.000001, 0.000001, 0.000001, 0.000001,
|
||||||
0.000001, 0.000001, 0.000001, 0.000001).fuzzy_eq(&mat4::zero()));
|
0.000001, 0.000001, 0.000001, 0.000001).approx_eq(&mat4::zero()));
|
||||||
assert!(mat4::new(0.0000001, 0.0000001, 0.0000001, 0.0000001,
|
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,
|
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).approx_eq(&mat4::zero()));
|
||||||
}
|
}
|
|
@ -13,8 +13,6 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
use std::cmp::FuzzyEq;
|
|
||||||
|
|
||||||
use mat::*;
|
use mat::*;
|
||||||
use quat::*;
|
use quat::*;
|
||||||
use vec::*;
|
use vec::*;
|
||||||
|
@ -35,10 +33,10 @@ fn test_quat() {
|
||||||
assert!(a.v.x == 2.0);
|
assert!(a.v.x == 2.0);
|
||||||
assert!(a.v.y == 3.0);
|
assert!(a.v.y == 3.0);
|
||||||
assert!(a.v.z == 4.0);
|
assert!(a.v.z == 4.0);
|
||||||
assert!(a[0] == 1.0);
|
assert!(*a.index(0) == 1.0);
|
||||||
assert!(a[1] == 2.0);
|
assert!(*a.index(1) == 2.0);
|
||||||
assert!(a[2] == 3.0);
|
assert!(*a.index(2) == 3.0);
|
||||||
assert!(a[3] == 4.0);
|
assert!(*a.index(3) == 4.0);
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,15 +47,15 @@ fn test_quat_2() {
|
||||||
let q = quat::from_angle_axis((-45f32).radians(), &vec3::new(0f32, 0f32, -1f32));
|
let q = quat::from_angle_axis((-45f32).radians(), &vec3::new(0f32, 0f32, -1f32));
|
||||||
|
|
||||||
// http://www.wolframalpha.com/input/?i={1,0}+rotate+-45+degrees
|
// http://www.wolframalpha.com/input/?i={1,0}+rotate+-45+degrees
|
||||||
assert!(q.mul_v(&v).fuzzy_eq(&vec3::new(1f32/2f32.sqrt(), 1f32/2f32.sqrt(), 0f32)));
|
assert!(q.mul_v(&v).approx_eq(&vec3::new(1f32/2f32.sqrt(), 1f32/2f32.sqrt(), 0f32)));
|
||||||
assert!(q.mul_v(&v).length() == v.length());
|
assert!(q.mul_v(&v).length() == v.length());
|
||||||
assert!(q.to_mat3().fuzzy_eq(&mat3::new( 1f32/2f32.sqrt(), 1f32/2f32.sqrt(), 0f32,
|
assert!(q.to_mat3().approx_eq(&mat3::new(1f32/2f32.sqrt(), 1f32/2f32.sqrt(), 0f32,
|
||||||
-1f32/2f32.sqrt(), 1f32/2f32.sqrt(), 0f32,
|
-1f32/2f32.sqrt(), 1f32/2f32.sqrt(), 0f32,
|
||||||
0f32, 0f32, 1f32)));
|
0f32, 0f32, 1f32)));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_quat_fuzzy_eq() {
|
fn test_quat_approx_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.000001, 0.000001, 0.000001, 0.000001).approx_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.0000001, 0.0000001, 0.0000001, 0.0000001).approx_eq(&quat::new(0.0, 0.0, 0.0, 0.0)));
|
||||||
}
|
}
|
|
@ -13,9 +13,6 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
use std::cmp::FuzzyEq;
|
|
||||||
use std::num::Real::{frac_pi_2, frac_pi_3};
|
|
||||||
|
|
||||||
use vec::*;
|
use vec::*;
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
|
@ -45,14 +42,14 @@ fn test_vec2() {
|
||||||
mut_a = a;
|
mut_a = a;
|
||||||
|
|
||||||
mut_a.swap(0, 1);
|
mut_a.swap(0, 1);
|
||||||
assert!(mut_a[0] == a[1]);
|
assert!(*mut_a.index(0) == *a.index(1));
|
||||||
assert!(mut_a[1] == a[0]);
|
assert!(*mut_a.index(1) == *a.index(0));
|
||||||
mut_a = a;
|
mut_a = a;
|
||||||
|
|
||||||
assert!(a.x == 1.0);
|
assert!(a.x == 1.0);
|
||||||
assert!(a.y == 2.0);
|
assert!(a.y == 2.0);
|
||||||
assert!(a[0] == 1.0);
|
assert!(*a.index(0) == 1.0);
|
||||||
assert!(a[1] == 2.0);
|
assert!(*a.index(1) == 2.0);
|
||||||
|
|
||||||
assert!(-a == vec2::new(-1.0, -2.0));
|
assert!(-a == vec2::new(-1.0, -2.0));
|
||||||
assert!(a.neg() == vec2::new(-1.0, -2.0));
|
assert!(a.neg() == vec2::new(-1.0, -2.0));
|
||||||
|
@ -102,9 +99,9 @@ fn test_vec2() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_vec2_fuzzy_eq() {
|
fn test_vec2_approx_eq() {
|
||||||
assert!(!vec2::new(0.000001, 0.000001).fuzzy_eq(&vec2::new(0.0, 0.0)));
|
assert!(!vec2::new(0.000001, 0.000001).approx_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.0000001, 0.0000001).approx_eq(&vec2::new(0.0, 0.0)));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -122,11 +119,11 @@ fn test_vec2_euclidean() {
|
||||||
assert!(a.distance(&b) == 5.0);
|
assert!(a.distance(&b) == 5.0);
|
||||||
assert!(a.distance2(&b) == 5.0 * 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(&frac_pi_2()));
|
assert!(vec2::new(1.0, 0.0).angle(&vec2::new(0.0, 1.0)).approx_eq(&Real::frac_pi_2()));
|
||||||
assert!(vec2::new(10.0, 0.0).angle(&vec2::new(0.0, 5.0)).fuzzy_eq(&frac_pi_2()));
|
assert!(vec2::new(10.0, 0.0).angle(&vec2::new(0.0, 5.0)).approx_eq(&Real::frac_pi_2()));
|
||||||
assert!(vec2::new(-1.0, 0.0).angle(&vec2::new(0.0, 1.0)).fuzzy_eq(&-frac_pi_2::<f32>()));
|
assert!(vec2::new(-1.0, 0.0).angle(&vec2::new(0.0, 1.0)).approx_eq(&-frac_pi_2::<f32>()));
|
||||||
|
|
||||||
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().approx_eq(&vec2::new(3.0/5.0, 4.0/5.0)));
|
||||||
// TODO: test normalize_to, normalize_self, and normalize_self_to
|
// TODO: test normalize_to, normalize_self, and normalize_self_to
|
||||||
|
|
||||||
let c = vec2::new(-2.0, -1.0);
|
let c = vec2::new(-2.0, -1.0);
|
||||||
|
@ -185,21 +182,21 @@ fn test_vec3() {
|
||||||
mut_a = a;
|
mut_a = a;
|
||||||
|
|
||||||
mut_a.swap(0, 2);
|
mut_a.swap(0, 2);
|
||||||
assert!(mut_a[0] == a[2]);
|
assert!(*mut_a.index(0) == *a.index(2));
|
||||||
assert!(mut_a[2] == a[0]);
|
assert!(*mut_a.index(2) == *a.index(0));
|
||||||
mut_a = a;
|
mut_a = a;
|
||||||
|
|
||||||
mut_a.swap(1, 2);
|
mut_a.swap(1, 2);
|
||||||
assert!(mut_a[1] == a[2]);
|
assert!(*mut_a.index(1) == *a.index(2));
|
||||||
assert!(mut_a[2] == a[1]);
|
assert!(*mut_a.index(2) == *a.index(1));
|
||||||
mut_a = a;
|
mut_a = a;
|
||||||
|
|
||||||
assert!(a.x == 1.0);
|
assert!(a.x == 1.0);
|
||||||
assert!(a.y == 2.0);
|
assert!(a.y == 2.0);
|
||||||
assert!(a.z == 3.0);
|
assert!(a.z == 3.0);
|
||||||
assert!(a[0] == 1.0);
|
assert!(*a.index(0) == 1.0);
|
||||||
assert!(a[1] == 2.0);
|
assert!(*a.index(1) == 2.0);
|
||||||
assert!(a[2] == 3.0);
|
assert!(*a.index(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));
|
||||||
|
|
||||||
|
@ -250,7 +247,7 @@ fn test_vec3() {
|
||||||
// mut_a = a;
|
// mut_a = a;
|
||||||
|
|
||||||
// exact_eq
|
// exact_eq
|
||||||
// fuzzy_eq
|
// approx_eq
|
||||||
// eq
|
// eq
|
||||||
|
|
||||||
// assert!(c.abs() == vec3::new( 2.0, 1.0, 1.0));
|
// assert!(c.abs() == vec3::new( 2.0, 1.0, 1.0));
|
||||||
|
@ -259,9 +256,9 @@ fn test_vec3() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_vec3_fuzzy_eq() {
|
fn test_vec3_approx_eq() {
|
||||||
assert!(!vec3::new(0.000001, 0.000001, 0.000001).fuzzy_eq(&vec3::new(0.0, 0.0, 0.0)));
|
assert!(!vec3::new(0.000001, 0.000001, 0.000001).approx_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.0000001, 0.0000001, 0.0000001).approx_eq(&vec3::new(0.0, 0.0, 0.0)));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -279,11 +276,11 @@ fn test_vec3_euclidean() {
|
||||||
assert!(a.distance(&b) == 9.0);
|
assert!(a.distance(&b) == 9.0);
|
||||||
assert!(a.distance2(&b) == 9.0 * 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(&frac_pi_3()));
|
assert!(vec3::new(1.0, 0.0, 1.0).angle(&vec3::new(1.0, 1.0, 0.0)).approx_eq(&Real::frac_pi_3()));
|
||||||
assert!(vec3::new(10.0, 0.0, 10.0).angle(&vec3::new(5.0, 5.0, 0.0)).fuzzy_eq(&frac_pi_3()));
|
assert!(vec3::new(10.0, 0.0, 10.0).angle(&vec3::new(5.0, 5.0, 0.0)).approx_eq(&Real::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 * frac_pi_3())));
|
assert!(vec3::new(-1.0, 0.0, -1.0).angle(&vec3::new(1.0, -1.0, 0.0)).approx_eq(&(2.0 * Real::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().approx_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
|
// TODO: test normalize_to, normalize_self, and normalize_self_to
|
||||||
|
|
||||||
let c = vec3::new(-2.0, -1.0, 1.0);
|
let c = vec3::new(-2.0, -1.0, 1.0);
|
||||||
|
@ -337,13 +334,13 @@ fn test_vec4() {
|
||||||
mut_a = a;
|
mut_a = a;
|
||||||
|
|
||||||
mut_a.swap(0, 3);
|
mut_a.swap(0, 3);
|
||||||
assert!(mut_a[0] == a[3]);
|
assert!(*mut_a.index(0) == *a.index(3));
|
||||||
assert!(mut_a[3] == a[0]);
|
assert!(*mut_a.index(3) == *a.index(0));
|
||||||
mut_a = a;
|
mut_a = a;
|
||||||
|
|
||||||
mut_a.swap(1, 2);
|
mut_a.swap(1, 2);
|
||||||
assert!(mut_a[1] == a[2]);
|
assert!(*mut_a.index(1) == *a.index(2));
|
||||||
assert!(mut_a[2] == a[1]);
|
assert!(*mut_a.index(2) == *a.index(1));
|
||||||
mut_a = a;
|
mut_a = a;
|
||||||
|
|
||||||
assert!(vec4::zero() == vec4::new(0.0, 0.0, 0.0, 0.0));
|
assert!(vec4::zero() == vec4::new(0.0, 0.0, 0.0, 0.0));
|
||||||
|
@ -357,10 +354,10 @@ fn test_vec4() {
|
||||||
assert!(a.y == 2.0);
|
assert!(a.y == 2.0);
|
||||||
assert!(a.z == 3.0);
|
assert!(a.z == 3.0);
|
||||||
assert!(a.w == 4.0);
|
assert!(a.w == 4.0);
|
||||||
assert!(a[0] == 1.0);
|
assert!(*a.index(0) == 1.0);
|
||||||
assert!(a[1] == 2.0);
|
assert!(*a.index(1) == 2.0);
|
||||||
assert!(a[2] == 3.0);
|
assert!(*a.index(2) == 3.0);
|
||||||
assert!(a[3] == 4.0);
|
assert!(*a.index(3) == 4.0);
|
||||||
|
|
||||||
assert!(-a == 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!(a.neg() == vec4::new(-1.0, -2.0, -3.0, -4.0));
|
||||||
|
@ -412,9 +409,9 @@ fn test_vec4() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_vec4_fuzzy_eq() {
|
fn test_vec4_approx_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.000001, 0.000001, 0.000001, 0.000001).approx_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.0000001, 0.0000001, 0.0000001, 0.0000001).approx_eq(&vec4::new(0.0, 0.0, 0.0, 0.0)));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -432,11 +429,11 @@ fn test_vec4_euclidean() {
|
||||||
assert!(a.distance(&b) == 13.0);
|
assert!(a.distance(&b) == 13.0);
|
||||||
assert!(a.distance2(&b) == 13.0 * 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(&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)).approx_eq(&Real::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(&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)).approx_eq(&Real::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(&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)).approx_eq(&Real::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().approx_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
|
// TODO: test normalize_to, normalize_self, and normalize_self_to
|
||||||
|
|
||||||
let c = vec4::new(-2.0, -1.0, 1.0, 2.0);
|
let c = vec4::new(-2.0, -1.0, 1.0, 2.0);
|
||||||
|
|
Loading…
Reference in a new issue