Move exact_eq to trait

This commit is contained in:
Brendan Zabarauskas 2012-10-30 12:45:18 +10:00
parent cc053d449d
commit 6f0b49aa0c
4 changed files with 71 additions and 59 deletions

View file

@ -1,6 +1,10 @@
use cmp::Ord; use cmp::Ord;
use num::{Num, from_int}; use num::{Num, from_int};
pub trait ExactEq {
pure fn exact_eq(other: &self) -> bool;
}
// //
// Min // Min
// //

View file

@ -1,6 +1,6 @@
use std::cmp::FuzzyEq; use std::cmp::FuzzyEq;
use cmp::Eq; use cmp::Eq;
use math::Sqrt; use math::{ExactEq, Sqrt};
use quaternion::Quat; use quaternion::Quat;
use vector::{Vec2, Vec3, Vec4}; use vector::{Vec2, Vec3, Vec4};
@ -24,8 +24,6 @@ pub trait Matrix<T, V> {
// pure fn invert(other: &self) -> self; // pure fn invert(other: &self) -> self;
pure fn transpose() -> self; pure fn transpose() -> self;
pure fn exact_eq(other: &self) -> bool;
pure fn is_identity() -> bool; pure fn is_identity() -> bool;
pure fn is_symmetric() -> bool; pure fn is_symmetric() -> bool;
pure fn is_diagonal() -> bool; pure fn is_diagonal() -> bool;
@ -156,12 +154,6 @@ pub impl Mat2: Matrix<float, Vec2> {
self[0][1], self[1][1]) self[0][1], self[1][1])
} }
#[inline]
pure fn exact_eq(other: &Mat2) -> bool {
self[0].exact_eq(&other[0]) &&
self[1].exact_eq(&other[1])
}
#[inline] #[inline]
pure fn is_identity() -> bool { pure fn is_identity() -> bool {
self.fuzzy_eq(&Mat2::identity) self.fuzzy_eq(&Mat2::identity)
@ -211,6 +203,14 @@ pub impl Mat2: Eq {
} }
} }
impl Mat2: ExactEq {
#[inline]
pure fn exact_eq(other: &Mat2) -> bool {
self[0].exact_eq(&other[0]) &&
self[1].exact_eq(&other[1])
}
}
pub impl Mat2: FuzzyEq { pub impl Mat2: FuzzyEq {
#[inline] #[inline]
pure fn fuzzy_eq(other: &Mat2) -> bool { pure fn fuzzy_eq(other: &Mat2) -> bool {
@ -337,13 +337,6 @@ pub impl Mat3: Matrix<float, Vec3> {
self[0][2], self[1][2], self[2][2]) self[0][2], self[1][2], self[2][2])
} }
#[inline]
pure fn exact_eq(other: &Mat3) -> bool {
self[0].exact_eq(&other[0]) &&
self[1].exact_eq(&other[1]) &&
self[2].exact_eq(&other[2])
}
#[inline] #[inline]
pure fn is_identity() -> bool { pure fn is_identity() -> bool {
self.fuzzy_eq(&Mat3::identity) self.fuzzy_eq(&Mat3::identity)
@ -462,6 +455,15 @@ pub impl Mat3: Eq {
} }
} }
impl Mat3: ExactEq {
#[inline]
pure fn exact_eq(other: &Mat3) -> bool {
self[0].exact_eq(&other[0]) &&
self[1].exact_eq(&other[1]) &&
self[2].exact_eq(&other[2])
}
}
pub impl Mat3: FuzzyEq { pub impl Mat3: FuzzyEq {
#[inline] #[inline]
pure fn fuzzy_eq(other: &Mat3) -> bool { pure fn fuzzy_eq(other: &Mat3) -> bool {
@ -607,14 +609,6 @@ pub impl Mat4: Matrix<float, Vec4> {
self[0][3], self[1][3], self[2][3], self[3][3]) self[0][3], self[1][3], self[2][3], self[3][3])
} }
#[inline]
pure fn exact_eq(other: &Mat4) -> bool {
self[0].exact_eq(&other[0]) &&
self[1].exact_eq(&other[1]) &&
self[2].exact_eq(&other[2]) &&
self[3].exact_eq(&other[3])
}
#[inline] #[inline]
pure fn is_identity() -> bool { pure fn is_identity() -> bool {
self.fuzzy_eq(&Mat4::identity) self.fuzzy_eq(&Mat4::identity)
@ -711,6 +705,16 @@ pub impl Mat4: Eq {
} }
} }
impl Mat4: ExactEq {
#[inline]
pure fn exact_eq(other: &Mat4) -> bool {
self[0].exact_eq(&other[0]) &&
self[1].exact_eq(&other[1]) &&
self[2].exact_eq(&other[2]) &&
self[3].exact_eq(&other[3])
}
}
pub impl Mat4: FuzzyEq { pub impl Mat4: FuzzyEq {
#[inline] #[inline]
pure fn fuzzy_eq(other: &Mat4) -> bool { pure fn fuzzy_eq(other: &Mat4) -> bool {

View file

@ -3,7 +3,7 @@ use vec::raw::buf_as_slice;
use ptr::to_unsafe_ptr; use ptr::to_unsafe_ptr;
use cmp::Eq; use cmp::Eq;
use std::cmp::FuzzyEq; use std::cmp::FuzzyEq;
use math::*; use math::{ExactEq, Sqrt};
use matrix::{Mat3, Mat4}; use matrix::{Mat3, Mat4};
use vector::Vec3; use vector::Vec3;
@ -22,8 +22,6 @@ pub trait Quaternion<T> {
pure fn sub_q(other: &self) -> self; pure fn sub_q(other: &self) -> self;
pure fn mul_q(other: &self) -> self; pure fn mul_q(other: &self) -> self;
pure fn exact_eq(other: &self) -> bool;
pure fn conjugate() -> self; pure fn conjugate() -> self;
pure fn inverse() -> self; pure fn inverse() -> self;
pure fn magnitude2() -> T; pure fn magnitude2() -> T;
@ -103,14 +101,6 @@ pub impl Quat: Quaternion<float> {
self.w * other.z + self.z * other.w + self.x * other.y - self.y * other.x) self.w * other.z + self.z * other.w + self.x * other.y - self.y * other.x)
} }
#[inline]
pure fn exact_eq(other: &Quat) -> bool {
self[0] == other[0] &&
self[1] == other[1] &&
self[2] == other[2] &&
self[3] == other[3]
}
#[inline] #[inline]
pure fn conjugate() -> Quat { pure fn conjugate() -> Quat {
Quat(self.w, -self.x, -self.y, -self.z) Quat(self.w, -self.x, -self.y, -self.z)
@ -193,6 +183,16 @@ pub impl Quat: Eq {
} }
} }
impl Quat: ExactEq {
#[inline]
pure fn exact_eq(other: &Quat) -> bool {
self[0] == other[0] &&
self[1] == other[1] &&
self[2] == other[2] &&
self[3] == other[3]
}
}
pub impl Quat: FuzzyEq { pub impl Quat: FuzzyEq {
#[inline] #[inline]
pure fn fuzzy_eq(other: &Quat) -> bool { pure fn fuzzy_eq(other: &Quat) -> bool {

View file

@ -3,7 +3,7 @@ use vec::raw::buf_as_slice;
use ptr::to_unsafe_ptr; use ptr::to_unsafe_ptr;
use cmp::Eq; use cmp::Eq;
use std::cmp::FuzzyEq; use std::cmp::FuzzyEq;
use math::*; use math::{Abs, abs, ExactEq, max, min, Sqrt};
// //
// N-dimensional Vector // N-dimensional Vector
@ -21,8 +21,6 @@ pub trait Vector<T> {
pure fn dot(other: &self) -> T; pure fn dot(other: &self) -> T;
pure fn exact_eq(other:&self) -> bool;
pure fn magnitude2() -> T; pure fn magnitude2() -> T;
pure fn magnitude() -> T; pure fn magnitude() -> T;
pure fn normalize() -> self; pure fn normalize() -> self;
@ -111,12 +109,6 @@ pub impl Vec2: Vector<float> {
self[1] * other[1] self[1] * other[1]
} }
#[inline]
pure fn exact_eq(other: &Vec2) -> bool {
self[0] == other[0] &&
self[1] == other[1]
}
#[inline] #[inline]
pure fn magnitude2() -> float { pure fn magnitude2() -> float {
self[0] * self[0] + self[0] * self[0] +
@ -193,6 +185,14 @@ pub impl Vec2: Eq {
} }
} }
impl Vec2: ExactEq {
#[inline]
pure fn exact_eq(other: &Vec2) -> bool {
self[0] == other[0] &&
self[1] == other[1]
}
}
pub impl Vec2: FuzzyEq { pub impl Vec2: FuzzyEq {
#[inline] #[inline]
pure fn fuzzy_eq(other: &Vec2) -> bool { pure fn fuzzy_eq(other: &Vec2) -> bool {
@ -295,13 +295,6 @@ pub impl Vec3: Vector<float> {
self[2] * other[2] self[2] * other[2]
} }
#[inline]
pure fn exact_eq(other: &Vec3) -> bool {
self[0] == other[0] &&
self[1] == other[1] &&
self[2] == other[2]
}
#[inline] #[inline]
pure fn magnitude2() -> float { pure fn magnitude2() -> float {
self[0] * self[0] + self[0] * self[0] +
@ -381,6 +374,15 @@ pub impl Vec3: Eq {
} }
} }
impl Vec3: ExactEq {
#[inline]
pure fn exact_eq(other: &Vec3) -> bool {
self[0] == other[0] &&
self[1] == other[1] &&
self[2] == other[2]
}
}
pub impl Vec3: FuzzyEq { pub impl Vec3: FuzzyEq {
#[inline] #[inline]
pure fn fuzzy_eq(other: &Vec3) -> bool { pure fn fuzzy_eq(other: &Vec3) -> bool {
@ -483,14 +485,6 @@ pub impl Vec4: Vector<float> {
self[3] * other[3] self[3] * other[3]
} }
#[inline]
pure fn exact_eq(other: &Vec4) -> bool {
self[0] == other[0] &&
self[1] == other[1] &&
self[2] == other[2] &&
self[3] == other[3]
}
#[inline] #[inline]
pure fn magnitude2() -> float { pure fn magnitude2() -> float {
self[0] * self[0] + self[0] * self[0] +
@ -575,6 +569,16 @@ pub impl Vec4: Eq {
} }
} }
impl Vec4: ExactEq {
#[inline]
pure fn exact_eq(other: &Vec4) -> bool {
self[0] == other[0] &&
self[1] == other[1] &&
self[2] == other[2] &&
self[3] == other[3]
}
}
pub impl Vec4: FuzzyEq { pub impl Vec4: FuzzyEq {
#[inline] #[inline]
pure fn fuzzy_eq(other: &Vec4) -> bool { pure fn fuzzy_eq(other: &Vec4) -> bool {