From 079199c275e6c3ee33ede7e3865e7b4c57f36be0 Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Fri, 7 Dec 2012 02:19:48 +1000 Subject: [PATCH] Remove default_eq module --- src/lmath.rc | 2 -- src/num/default_eq.rs | 24 --------------------- src/num/kinds.rs | 3 +-- src/test/test_angle.rs | 6 +++--- src/test/test_mat.rs | 8 +++---- src/vec.rs | 48 ++++++++++++------------------------------ 6 files changed, 21 insertions(+), 70 deletions(-) delete mode 100644 src/num/default_eq.rs diff --git a/src/lmath.rc b/src/lmath.rc index a9d2b38..da5c4f7 100644 --- a/src/lmath.rc +++ b/src/lmath.rc @@ -66,8 +66,6 @@ pub mod funs { pub mod num { #[path = "num/conv.rs"] pub mod conv; - #[path = "num/default_eq.rs"] - pub mod default_eq; #[path = "num/kinds.rs"] pub mod kinds; } diff --git a/src/num/default_eq.rs b/src/num/default_eq.rs deleted file mode 100644 index 0566a0c..0000000 --- a/src/num/default_eq.rs +++ /dev/null @@ -1,24 +0,0 @@ -use std::cmp::FuzzyEq; - - -pub trait DefaultEq { - pure fn default_eq(&self, other: &self) -> bool; -} - -pub impl bool: DefaultEq { #[inline(always)] pure fn default_eq(&self, other: &bool) -> bool { (*self) == (*other) } } - -pub impl u8: DefaultEq { #[inline(always)] pure fn default_eq(&self, other: &u8) -> bool { (*self) == (*other) } } -pub impl u16: DefaultEq { #[inline(always)] pure fn default_eq(&self, other: &u16) -> bool { (*self) == (*other) } } -pub impl u32: DefaultEq { #[inline(always)] pure fn default_eq(&self, other: &u32) -> bool { (*self) == (*other) } } -pub impl u64: DefaultEq { #[inline(always)] pure fn default_eq(&self, other: &u64) -> bool { (*self) == (*other) } } -pub impl uint: DefaultEq { #[inline(always)] pure fn default_eq(&self, other: &uint) -> bool { (*self) == (*other) } } - -pub impl i8: DefaultEq { #[inline(always)] pure fn default_eq(&self, other: &i8) -> bool { (*self) == (*other) } } -pub impl i16: DefaultEq { #[inline(always)] pure fn default_eq(&self, other: &i16) -> bool { (*self) == (*other) } } -pub impl i32: DefaultEq { #[inline(always)] pure fn default_eq(&self, other: &i32) -> bool { (*self) == (*other) } } -pub impl i64: DefaultEq { #[inline(always)] pure fn default_eq(&self, other: &i64) -> bool { (*self) == (*other) } } -pub impl int: DefaultEq { #[inline(always)] pure fn default_eq(&self, other: &int) -> bool { (*self) == (*other) } } - -pub impl f32: DefaultEq { #[inline(always)] pure fn default_eq(&self, other: &f32) -> bool { self.fuzzy_eq(other) } } -pub impl f64: DefaultEq { #[inline(always)] pure fn default_eq(&self, other: &f64) -> bool { self.fuzzy_eq(other) } } -pub impl float: DefaultEq { #[inline(always)] pure fn default_eq(&self, other: &float) -> bool { self.fuzzy_eq(other) } } \ No newline at end of file diff --git a/src/num/kinds.rs b/src/num/kinds.rs index d2c5619..f658032 100644 --- a/src/num/kinds.rs +++ b/src/num/kinds.rs @@ -2,10 +2,9 @@ use core::cmp::{Eq, Ord}; use std::cmp::FuzzyEq; use num::conv::NumConv; -use num::default_eq::DefaultEq; -pub trait Number: DefaultEq, Eq, Num, NumConv, Ord { +pub trait Number: Eq, Num, NumConv, Ord { /** * Cast a number to the type surrounding the static method * diff --git a/src/test/test_angle.rs b/src/test/test_angle.rs index 9dd9812..b19a48b 100644 --- a/src/test/test_angle.rs +++ b/src/test/test_angle.rs @@ -90,7 +90,7 @@ fn test_rotation() { let newpos = rot.to_mat4().mul_v(&pos); let expected_pos = Vec4::new(-1.0, 0.0, 0.0, 1.0); - assert newpos == expected_pos; + assert newpos.fuzzy_eq(&expected_pos); } { let pos = Vec4::new(4f32, 0f32, 0f32, 1f32); @@ -111,8 +111,8 @@ fn test_rotation() { let expected_pos_a = Vec4::new(0f32, 0f32, -4f32, 1f32); let expected_pos_b = Vec4::new(0f32, 0f32, 4f32, 1f32); - assert newpos_a == expected_pos_a; - assert newpos_b == expected_pos_b; + assert newpos_a.fuzzy_eq(&expected_pos_a); + assert newpos_b.fuzzy_eq(&expected_pos_b); } // TODO: test to_quat diff --git a/src/test/test_mat.rs b/src/test/test_mat.rs index 70003a6..904b0f3 100644 --- a/src/test/test_mat.rs +++ b/src/test/test_mat.rs @@ -458,10 +458,10 @@ fn test_Mat4() { 13f, 14f, 15f, 16f); assert option::unwrap(c.inverse()) - == Mat4::new( 5f, -4f, 1f, 0f, - -4f, 8f, -4f, 0f, - 4f, -8f, 4f, 8f, - -3f, 4f, 1f, -8f).mul_t(0.125f); + .fuzzy_eq(&Mat4::new( 5f, -4f, 1f, 0f, + -4f, 8f, -4f, 0f, + 4f, -8f, 4f, 8f, + -3f, 4f, 1f, -8f).mul_t(0.125f)); // let ident: Mat4 = Matrix::identity(); let ident: Mat4 = Mat4::identity(); diff --git a/src/vec.rs b/src/vec.rs index 61d376d..9ae671b 100644 --- a/src/vec.rs +++ b/src/vec.rs @@ -8,7 +8,6 @@ use std::cmp::FuzzyEq; use dim::{Dimensional, ToPtr}; use funs::exponential::Exp; -use num::default_eq::DefaultEq; use num::kinds::Number; /** @@ -19,7 +18,7 @@ use num::kinds::Number; * * `T` - The type of the components. This is intended to support boolean, * integer, unsigned integer, and floating point types. */ -pub trait Vector: Dimensional, ToPtr, Eq, DefaultEq { +pub trait Vector: Dimensional, ToPtr, Eq { /** * Construct the vector from a single value, copying it to each component */ @@ -477,10 +476,11 @@ pub impl Vec2: MutableEuclideanVector<&self/T> { } } -pub impl Vec2: Eq { +pub impl Vec2: Eq { #[inline(always)] pure fn eq(&self, other: &Vec2) -> bool { - self.default_eq(other) + self[0] == other[0] && + self[1] == other[1] } #[inline(always)] @@ -497,14 +497,6 @@ pub impl Vec2: FuzzyEq { } } -pub impl Vec2: DefaultEq { - #[inline(always)] - pure fn default_eq(&self, other: &Vec2) -> bool { - self[0].default_eq(&other[0]) && - self[1].default_eq(&other[1]) - } -} - @@ -742,10 +734,12 @@ pub impl Vec3: MutableEuclideanVector<&self/T> { } } -pub impl Vec3: Eq { +pub impl Vec3: Eq { #[inline(always)] pure fn eq(&self, other: &Vec3) -> bool { - self.default_eq(other) + self[0] == other[0] && + self[1] == other[1] && + self[2] == other[2] } #[inline(always)] @@ -763,15 +757,6 @@ pub impl Vec3: FuzzyEq { } } -pub impl Vec3: DefaultEq { - #[inline(always)] - pure fn default_eq(&self, other: &Vec3) -> bool { - self[0].default_eq(&other[0]) && - self[1].default_eq(&other[1]) && - self[2].default_eq(&other[2]) - } -} - @@ -1007,10 +992,13 @@ pub impl Vec4: MutableEuclideanVector<&self/T> { } } -pub impl Vec4: Eq { +pub impl Vec4: Eq { #[inline(always)] pure fn eq(&self, other: &Vec4) -> bool { - self.default_eq(other) + self[0] == other[0] && + self[1] == other[1] && + self[2] == other[2] && + self[3] == other[3] } #[inline(always)] @@ -1027,14 +1015,4 @@ pub impl Vec4: FuzzyEq { self[2].fuzzy_eq(&other[2]) && self[3].fuzzy_eq(&other[3]) } -} - -pub impl Vec4: DefaultEq { - #[inline(always)] - pure fn default_eq(&self, other: &Vec4) -> bool { - self[0].default_eq(&other[0]) && - self[1].default_eq(&other[1]) && - self[2].default_eq(&other[2]) && - self[3].default_eq(&other[3]) - } } \ No newline at end of file