From 53fc6d15ab9d8603f1c928508b59a1ba93f76fc5 Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Tue, 4 Dec 2012 08:23:13 +1000 Subject: [PATCH] Remove default eq implementations and use fuzzy_eq instead --- src/mat.rs | 146 +++++++++++++++++++++------------------------------- src/quat.rs | 13 +---- 2 files changed, 60 insertions(+), 99 deletions(-) diff --git a/src/mat.rs b/src/mat.rs index 7e786dd..fb74619 100644 --- a/src/mat.rs +++ b/src/mat.rs @@ -10,7 +10,6 @@ use dim::{Dimensional, ToPtr}; use funs::common::*; use funs::exponential::*; use num::cast::*; -use num::default_eq::DefaultEq; use num::kinds::{Float, Number}; use quat::{Quat, ToQuat}; use vec::{NumericVector, Vec2, Vec3, Vec4}; @@ -18,7 +17,7 @@ use vec::{NumericVector, Vec2, Vec3, Vec4}; /** * An N x N Matrix */ -pub trait Matrix: Dimensional, ToPtr, Eq, DefaultEq, Neg { +pub trait Matrix: Dimensional, ToPtr, Eq, Neg { pure fn col(&self, i: uint) -> V; pure fn row(&self, i: uint) -> V; @@ -181,7 +180,7 @@ pub impl Mat2: Matrix> { pure fn inverse(&self) -> Option> { let _0 = cast(0); let d = self.determinant(); - if d.default_eq(&_0) { + if d.fuzzy_eq(&_0) { None } else { Some(Mat2::new( self[1][1]/d, -self[0][1]/d, @@ -197,33 +196,33 @@ pub impl Mat2: Matrix> { #[inline(always)] pure fn is_identity(&self) -> bool { - // self.default_eq(&Matrix::identity()) // FIXME: there's something wrong with static functions here! - self.default_eq(&Mat2::identity()) + // self.fuzzy_eq(&Matrix::identity()) // FIXME: there's something wrong with static functions here! + self.fuzzy_eq(&Mat2::identity()) } #[inline(always)] pure fn is_diagonal(&self) -> bool { let _0 = cast(0); - self[0][1].default_eq(&_0) && - self[1][0].default_eq(&_0) + self[0][1].fuzzy_eq(&_0) && + self[1][0].fuzzy_eq(&_0) } #[inline(always)] pure fn is_rotated(&self) -> bool { - // !self.default_eq(&Matrix::identity()) // FIXME: there's something wrong with static functions here! - !self.default_eq(&Mat2::identity()) + // !self.fuzzy_eq(&Matrix::identity()) // FIXME: there's something wrong with static functions here! + !self.fuzzy_eq(&Mat2::identity()) } #[inline(always)] pure fn is_symmetric(&self) -> bool { - self[0][1].default_eq(&self[1][0]) && - self[1][0].default_eq(&self[0][1]) + self[0][1].fuzzy_eq(&self[1][0]) && + self[1][0].fuzzy_eq(&self[0][1]) } #[inline(always)] pure fn is_invertible(&self) -> bool { let _0 = cast(0); - !self.determinant().default_eq(&_0) + !self.determinant().fuzzy_eq(&_0) } } @@ -292,14 +291,6 @@ pub impl Mat2: FuzzyEq { } } -pub impl Mat2: DefaultEq { - #[inline(always)] - pure fn default_eq(&self, other: &Mat2) -> bool { - self[0].default_eq(&other[0]) && - self[1].default_eq(&other[1]) - } -} - @@ -443,7 +434,7 @@ pub impl Mat3: Matrix> { pure fn inverse(&self) -> Option> { let d = self.determinant(); let _0 = cast(0); - if d.default_eq(&_0) { + if d.fuzzy_eq(&_0) { None } else { Some(Mat3::from_cols(self[1].cross(&self[2]).div_t(d), @@ -462,45 +453,45 @@ pub impl Mat3: Matrix> { #[inline(always)] pure fn is_identity(&self) -> bool { - // self.default_eq(&Matrix::identity()) // FIXME: there's something wrong with static functions here! - self.default_eq(&Mat3::identity()) + // self.fuzzy_eq(&Matrix::identity()) // FIXME: there's something wrong with static functions here! + self.fuzzy_eq(&Mat3::identity()) } #[inline(always)] pure fn is_diagonal(&self) -> bool { let _0 = cast(0); - self[0][1].default_eq(&_0) && - self[0][2].default_eq(&_0) && + self[0][1].fuzzy_eq(&_0) && + self[0][2].fuzzy_eq(&_0) && - self[1][0].default_eq(&_0) && - self[1][2].default_eq(&_0) && + self[1][0].fuzzy_eq(&_0) && + self[1][2].fuzzy_eq(&_0) && - self[2][0].default_eq(&_0) && - self[2][1].default_eq(&_0) + self[2][0].fuzzy_eq(&_0) && + self[2][1].fuzzy_eq(&_0) } #[inline(always)] pure fn is_rotated(&self) -> bool { - // !self.default_eq(&Matrix::identity()) // FIXME: there's something wrong with static functions here! - !self.default_eq(&Mat3::identity()) + // !self.fuzzy_eq(&Matrix::identity()) // FIXME: there's something wrong with static functions here! + !self.fuzzy_eq(&Mat3::identity()) } #[inline(always)] pure fn is_symmetric(&self) -> bool { - self[0][1].default_eq(&self[1][0]) && - self[0][2].default_eq(&self[2][0]) && + self[0][1].fuzzy_eq(&self[1][0]) && + self[0][2].fuzzy_eq(&self[2][0]) && - self[1][0].default_eq(&self[0][1]) && - self[1][2].default_eq(&self[2][1]) && + self[1][0].fuzzy_eq(&self[0][1]) && + self[1][2].fuzzy_eq(&self[2][1]) && - self[2][0].default_eq(&self[0][2]) && - self[2][1].default_eq(&self[1][2]) + self[2][0].fuzzy_eq(&self[0][2]) && + self[2][1].fuzzy_eq(&self[1][2]) } #[inline(always)] pure fn is_invertible(&self) -> bool { let _0 = cast(0); - !self.determinant().default_eq(&_0) + !self.determinant().fuzzy_eq(&_0) } } @@ -612,15 +603,6 @@ pub impl Mat3: FuzzyEq { } } -pub impl Mat3: DefaultEq { - #[inline(always)] - pure fn default_eq(&self, other: &Mat3) -> bool { - self[0].default_eq(&other[0]) && - self[1].default_eq(&other[1]) && - self[2].default_eq(&other[2]) - } -} - @@ -802,7 +784,7 @@ pub impl Mat4: Matrix> { pure fn inverse(&self) -> Option> { let d = self.determinant(); let _0 = cast(0); - if d.default_eq(&_0) { + if d.fuzzy_eq(&_0) { None } else { @@ -866,59 +848,59 @@ pub impl Mat4: Matrix> { #[inline(always)] pure fn is_identity(&self) -> bool { - // self.default_eq(&Matrix::identity()) // FIXME: there's something wrong with static functions here! - self.default_eq(&Mat4::identity()) + // self.fuzzy_eq(&Matrix::identity()) // FIXME: there's something wrong with static functions here! + self.fuzzy_eq(&Mat4::identity()) } #[inline(always)] pure fn is_diagonal(&self) -> bool { let _0 = cast(0); - self[0][1].default_eq(&_0) && - self[0][2].default_eq(&_0) && - self[0][3].default_eq(&_0) && + self[0][1].fuzzy_eq(&_0) && + self[0][2].fuzzy_eq(&_0) && + self[0][3].fuzzy_eq(&_0) && - self[1][0].default_eq(&_0) && - self[1][2].default_eq(&_0) && - self[1][3].default_eq(&_0) && + self[1][0].fuzzy_eq(&_0) && + self[1][2].fuzzy_eq(&_0) && + self[1][3].fuzzy_eq(&_0) && - self[2][0].default_eq(&_0) && - self[2][1].default_eq(&_0) && - self[2][3].default_eq(&_0) && + self[2][0].fuzzy_eq(&_0) && + self[2][1].fuzzy_eq(&_0) && + self[2][3].fuzzy_eq(&_0) && - self[3][0].default_eq(&_0) && - self[3][1].default_eq(&_0) && - self[3][2].default_eq(&_0) + self[3][0].fuzzy_eq(&_0) && + self[3][1].fuzzy_eq(&_0) && + self[3][2].fuzzy_eq(&_0) } #[inline(always)] pure fn is_rotated(&self) -> bool { - // !self.default_eq(&Matrix::identity()) // FIXME: there's something wrong with static functions here! - !self.default_eq(&Mat4::identity()) + // !self.fuzzy_eq(&Matrix::identity()) // FIXME: there's something wrong with static functions here! + !self.fuzzy_eq(&Mat4::identity()) } #[inline(always)] pure fn is_symmetric(&self) -> bool { - self[0][1].default_eq(&self[1][0]) && - self[0][2].default_eq(&self[2][0]) && - self[0][3].default_eq(&self[3][0]) && + self[0][1].fuzzy_eq(&self[1][0]) && + self[0][2].fuzzy_eq(&self[2][0]) && + self[0][3].fuzzy_eq(&self[3][0]) && - self[1][0].default_eq(&self[0][1]) && - self[1][2].default_eq(&self[2][1]) && - self[1][3].default_eq(&self[3][1]) && + self[1][0].fuzzy_eq(&self[0][1]) && + self[1][2].fuzzy_eq(&self[2][1]) && + self[1][3].fuzzy_eq(&self[3][1]) && - self[2][0].default_eq(&self[0][2]) && - self[2][1].default_eq(&self[1][2]) && - self[2][3].default_eq(&self[3][2]) && + self[2][0].fuzzy_eq(&self[0][2]) && + self[2][1].fuzzy_eq(&self[1][2]) && + self[2][3].fuzzy_eq(&self[3][2]) && - self[3][0].default_eq(&self[0][3]) && - self[3][1].default_eq(&self[1][3]) && - self[3][2].default_eq(&self[2][3]) + self[3][0].fuzzy_eq(&self[0][3]) && + self[3][1].fuzzy_eq(&self[1][3]) && + self[3][2].fuzzy_eq(&self[2][3]) } #[inline(always)] pure fn is_invertible(&self) -> bool { let _0 = cast(0); - !self.determinant().default_eq(&_0) + !self.determinant().fuzzy_eq(&_0) } } @@ -981,13 +963,3 @@ pub impl Mat4: FuzzyEq { self[3].fuzzy_eq(&other[3]) } } - -pub impl Mat4: DefaultEq { - #[inline(always)] - pure fn default_eq(&self, other: &Mat4) -> 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]) - } -} diff --git a/src/quat.rs b/src/quat.rs index c6a8fc5..dc2e53d 100644 --- a/src/quat.rs +++ b/src/quat.rs @@ -11,7 +11,6 @@ use funs::common::*; use funs::exponential::*; use funs::triganomic::*; use mat::{Mat3, Mat4}; -use num::default_eq::DefaultEq; use num::kinds::{Float, Number}; use vec::Vec3; @@ -19,9 +18,9 @@ use vec::Vec3; /// /// The base quaternion trait /// -pub trait Quaternion: Dimensional, ToPtr, Eq, DefaultEq, Neg { static pure fn identity() -> self; /// The multiplicative identity static pure fn zero() -> self; /// The additive identity +pub trait Quaternion: Dimensional, ToPtr, Eq, Neg { pure fn mul_t(&self, value: T) -> self; pure fn div_t(&self, value: T) -> self; @@ -293,16 +292,6 @@ pub impl Quat: FuzzyEq { } } -pub impl Quat: DefaultEq { - #[inline(always)] - pure fn default_eq(&self, other: &Quat) -> 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]) - } -} - // // Operator Overloads // pub impl> Quat: Add {