Remove default_eq module

This commit is contained in:
Brendan Zabarauskas 2012-12-07 02:19:48 +10:00
parent 4a0cf79a85
commit 079199c275
6 changed files with 21 additions and 70 deletions

View file

@ -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;
}

View file

@ -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) } }

View file

@ -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
*

View file

@ -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

View file

@ -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<float> = Matrix::identity();
let ident: Mat4<float> = Mat4::identity();

View file

@ -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<T>: Dimensional<T>, ToPtr<T>, Eq, DefaultEq {
pub trait Vector<T>: Dimensional<T>, ToPtr<T>, Eq {
/**
* Construct the vector from a single value, copying it to each component
*/
@ -477,10 +476,11 @@ pub impl<T:Copy Number Exp> Vec2<T>: MutableEuclideanVector<&self/T> {
}
}
pub impl<T:Copy DefaultEq> Vec2<T>: Eq {
pub impl<T:Copy Eq> Vec2<T>: Eq {
#[inline(always)]
pure fn eq(&self, other: &Vec2<T>) -> bool {
self.default_eq(other)
self[0] == other[0] &&
self[1] == other[1]
}
#[inline(always)]
@ -497,14 +497,6 @@ pub impl<T:Copy FuzzyEq> Vec2<T>: FuzzyEq {
}
}
pub impl<T:Copy DefaultEq> Vec2<T>: DefaultEq {
#[inline(always)]
pure fn default_eq(&self, other: &Vec2<T>) -> bool {
self[0].default_eq(&other[0]) &&
self[1].default_eq(&other[1])
}
}
@ -742,10 +734,12 @@ pub impl<T:Copy Number Exp> Vec3<T>: MutableEuclideanVector<&self/T> {
}
}
pub impl<T:Copy DefaultEq> Vec3<T>: Eq {
pub impl<T:Copy Eq> Vec3<T>: Eq {
#[inline(always)]
pure fn eq(&self, other: &Vec3<T>) -> 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<T:Copy FuzzyEq> Vec3<T>: FuzzyEq {
}
}
pub impl<T:Copy DefaultEq> Vec3<T>: DefaultEq {
#[inline(always)]
pure fn default_eq(&self, other: &Vec3<T>) -> 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<T:Copy Number Exp> Vec4<T>: MutableEuclideanVector<&self/T> {
}
}
pub impl<T:Copy DefaultEq> Vec4<T>: Eq {
pub impl<T:Copy Eq> Vec4<T>: Eq {
#[inline(always)]
pure fn eq(&self, other: &Vec4<T>) -> 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<T:Copy FuzzyEq> Vec4<T>: FuzzyEq {
self[2].fuzzy_eq(&other[2]) &&
self[3].fuzzy_eq(&other[3])
}
}
pub impl<T:Copy DefaultEq> Vec4<T>: DefaultEq {
#[inline(always)]
pure fn default_eq(&self, other: &Vec4<T>) -> 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])
}
}