Implement DefaultEq for matrix, vector and quaternion types

This commit is contained in:
Brendan Zabarauskas 2012-11-20 15:35:06 +10:00
parent be6ee9a7f4
commit 491a82ec28
4 changed files with 149 additions and 148 deletions

View file

@ -9,15 +9,15 @@ fn test_boolv2() {
assert tf.any() == true; assert tf.any() == true;
assert tf.all() == false; assert tf.all() == false;
assert tf.not().exact_eq(&Vec2::new(false, true)); assert tf.not() == Vec2::new(false, true);
assert ff.any() == false; assert ff.any() == false;
assert ff.all() == false; assert ff.all() == false;
assert ff.not().exact_eq(&Vec2::new(true, true)); assert ff.not() == Vec2::new(true, true);
assert tt.any() == true; assert tt.any() == true;
assert tt.all() == true; assert tt.all() == true;
assert tt.not().exact_eq(&Vec2::new(false, false)); assert tt.not() == Vec2::new(false, false);
} }
#[test] #[test]
@ -28,15 +28,15 @@ fn test_boolv3() {
assert tft.any() == true; assert tft.any() == true;
assert tft.all() == false; assert tft.all() == false;
assert tft.not().exact_eq(&Vec3::new(false, true, false)); assert tft.not() == Vec3::new(false, true, false);
assert fff.any() == false; assert fff.any() == false;
assert fff.all() == false; assert fff.all() == false;
assert fff.not().exact_eq(&Vec3::new(true, true, true)); assert fff.not() == Vec3::new(true, true, true);
assert ttt.any() == true; assert ttt.any() == true;
assert ttt.all() == true; assert ttt.all() == true;
assert ttt.not().exact_eq(&Vec3::new(false, false, false)); assert ttt.not() == Vec3::new(false, false, false);
} }
#[test] #[test]
@ -47,15 +47,15 @@ fn test_boolv4() {
assert tftf.any() == true; assert tftf.any() == true;
assert tftf.all() == false; assert tftf.all() == false;
assert tftf.not().exact_eq(&Vec4::new(false, true, false, true)); assert tftf.not() == Vec4::new(false, true, false, true);
assert ffff.any() == false; assert ffff.any() == false;
assert ffff.all() == false; assert ffff.all() == false;
assert ffff.not().exact_eq(&Vec4::new(true, true, true, true)); assert ffff.not() == Vec4::new(true, true, true, true);
assert tttt.any() == true; assert tttt.any() == true;
assert tttt.all() == true; assert tttt.all() == true;
assert tttt.not().exact_eq(&Vec4::new(false, false, false, false)); assert tttt.not() == Vec4::new(false, false, false, false);
} }
#[test] #[test]
@ -66,5 +66,5 @@ fn test_boolv_fns() {
assert any(&tf) == true; assert any(&tf) == true;
assert all(&ftf) == false; assert all(&ftf) == false;
assert not(&tftf).exact_eq(&Vec4::new(false, true, false, true)); assert not(&tftf) == Vec4::new(false, true, false, true);
} }

View file

@ -10,11 +10,12 @@ use funs::common::*;
use funs::exp::*; use funs::exp::*;
use math::*; use math::*;
use num::cast::*; use num::cast::*;
use num::default_eq::DefaultEq;
use quat::{Quat, ToQuat}; use quat::{Quat, ToQuat};
use vec::{Vec2, Vec3, Vec4}; use vec::{Vec2, Vec3, Vec4};
pub trait Matrix<T, Col, Row>: Dimensional<T>, Eq { pub trait Matrix<T, Col, Row>: Dimensional<T>, Eq, DefaultEq {
pure fn rows() -> uint; pure fn rows() -> uint;
pure fn cols() -> uint; pure fn cols() -> uint;
pure fn is_col_major() -> bool; pure fn is_col_major() -> bool;
@ -177,7 +178,7 @@ pub impl<T:Copy Num> Mat2<T>: NumericMatrix<T, Vec2<T>, Vec2<T>> {
} }
} }
pub impl<T:Copy Num NumCast FuzzyEq> Mat2<T>: NumericMatrix_NxN<T, Vec2<T>> { pub impl<T:Copy Num NumCast DefaultEq> Mat2<T>: NumericMatrix_NxN<T, Vec2<T>> {
#[inline(always)] #[inline(always)]
pure fn mul_m(other: &Mat2<T>) -> Mat2<T> { pure fn mul_m(other: &Mat2<T>) -> Mat2<T> {
Mat2::new(self.row(0).dot(&other.col(0)), self.row(1).dot(&other.col(0)), Mat2::new(self.row(0).dot(&other.col(0)), self.row(1).dot(&other.col(0)),
@ -192,7 +193,7 @@ pub impl<T:Copy Num NumCast FuzzyEq> Mat2<T>: NumericMatrix_NxN<T, Vec2<T>> {
pure fn invert() -> Option<Mat2<T>> { pure fn invert() -> Option<Mat2<T>> {
let _0 = cast(0); let _0 = cast(0);
let d = self.det(); let d = self.det();
if d.fuzzy_eq(&_0) { if d.default_eq(&_0) {
None None
} else { } else {
Some(Mat2::new(self[1][1]/d, -self[0][1]/d, Some(Mat2::new(self[1][1]/d, -self[0][1]/d,
@ -208,31 +209,31 @@ pub impl<T:Copy Num NumCast FuzzyEq> Mat2<T>: NumericMatrix_NxN<T, Vec2<T>> {
#[inline(always)] #[inline(always)]
pure fn is_identity() -> bool { pure fn is_identity() -> bool {
self.fuzzy_eq(&Mat2::identity()) self.default_eq(&Mat2::identity())
} }
#[inline(always)] #[inline(always)]
pure fn is_symmetric() -> bool { pure fn is_symmetric() -> bool {
self[0][1].fuzzy_eq(&self[1][0]) && self[0][1].default_eq(&self[1][0]) &&
self[1][0].fuzzy_eq(&self[0][1]) self[1][0].default_eq(&self[0][1])
} }
#[inline(always)] #[inline(always)]
pure fn is_diagonal() -> bool { pure fn is_diagonal() -> bool {
let _0 = cast(0); let _0 = cast(0);
self[0][1].fuzzy_eq(&_0) && self[0][1].default_eq(&_0) &&
self[1][0].fuzzy_eq(&_0) self[1][0].default_eq(&_0)
} }
#[inline(always)] #[inline(always)]
pure fn is_rotated() -> bool { pure fn is_rotated() -> bool {
!self.fuzzy_eq(&Mat2::identity()) !self.default_eq(&Mat2::identity())
} }
#[inline(always)] #[inline(always)]
pure fn is_invertible() -> bool { pure fn is_invertible() -> bool {
let _0 = cast(0); let _0 = cast(0);
!self.det().fuzzy_eq(&_0) !self.det().default_eq(&_0)
} }
} }
@ -249,10 +250,10 @@ pub impl<T:Copy NumCast> Mat2<T>: Matrix2<T> {
} }
// TODO: make work for T:Integer // TODO: make work for T:Integer
pub impl<T:Copy FuzzyEq> Mat2<T>: Eq { pub impl<T:Copy DefaultEq> Mat2<T>: Eq {
#[inline(always)] #[inline(always)]
pure fn eq(other: &Mat2<T>) -> bool { pure fn eq(other: &Mat2<T>) -> bool {
self.fuzzy_eq(other) self.default_eq(other)
} }
#[inline(always)] #[inline(always)]
@ -261,14 +262,6 @@ pub impl<T:Copy FuzzyEq> Mat2<T>: Eq {
} }
} }
impl<T:Copy Eq> Mat2<T>: ExactEq {
#[inline(always)]
pure fn exact_eq(other: &Mat2<T>) -> bool {
self[0].exact_eq(&other[0]) &&
self[1].exact_eq(&other[1])
}
}
pub impl<T:Copy FuzzyEq> Mat2<T>: FuzzyEq { pub impl<T:Copy FuzzyEq> Mat2<T>: FuzzyEq {
#[inline(always)] #[inline(always)]
pure fn fuzzy_eq(other: &Mat2<T>) -> bool { pure fn fuzzy_eq(other: &Mat2<T>) -> bool {
@ -277,6 +270,14 @@ pub impl<T:Copy FuzzyEq> Mat2<T>: FuzzyEq {
} }
} }
pub impl<T:Copy DefaultEq> Mat2<T>: DefaultEq {
#[inline(always)]
pure fn default_eq(other: &Mat2<T>) -> bool {
self[0].default_eq(&other[0]) &&
self[1].default_eq(&other[1])
}
}
@ -415,7 +416,7 @@ pub impl<T:Copy Num> Mat3<T>: NumericMatrix<T, Vec3<T>, Vec3<T>> {
} }
} }
pub impl<T:Copy Num NumCast FuzzyEq> Mat3<T>: NumericMatrix_NxN<T, Vec3<T>> { pub impl<T:Copy Num NumCast DefaultEq> Mat3<T>: NumericMatrix_NxN<T, Vec3<T>> {
#[inline(always)] #[inline(always)]
pure fn mul_m(other: &Mat3<T>) -> Mat3<T> { pure fn mul_m(other: &Mat3<T>) -> Mat3<T> {
Mat3::new(self.row(0).dot(&other.col(0)), self.row(1).dot(&other.col(0)), self.row(2).dot(&other.col(0)), Mat3::new(self.row(0).dot(&other.col(0)), self.row(1).dot(&other.col(0)), self.row(2).dot(&other.col(0)),
@ -431,7 +432,7 @@ pub impl<T:Copy Num NumCast FuzzyEq> Mat3<T>: NumericMatrix_NxN<T, Vec3<T>> {
pure fn invert() -> Option<Mat3<T>> { pure fn invert() -> Option<Mat3<T>> {
let d = self.det(); let d = self.det();
let _0 = cast(0); let _0 = cast(0);
if d.fuzzy_eq(&_0) { if d.default_eq(&_0) {
None None
} else { } else {
Some(Mat3::from_cols(self[1].cross(&self[2]).div_t(d), Some(Mat3::from_cols(self[1].cross(&self[2]).div_t(d),
@ -450,43 +451,43 @@ pub impl<T:Copy Num NumCast FuzzyEq> Mat3<T>: NumericMatrix_NxN<T, Vec3<T>> {
#[inline(always)] #[inline(always)]
pure fn is_identity() -> bool { pure fn is_identity() -> bool {
self.fuzzy_eq(&Mat3::identity()) self.default_eq(&Mat3::identity())
} }
#[inline(always)] #[inline(always)]
pure fn is_symmetric() -> bool { pure fn is_symmetric() -> bool {
self[0][1].fuzzy_eq(&self[1][0]) && self[0][1].default_eq(&self[1][0]) &&
self[0][2].fuzzy_eq(&self[2][0]) && self[0][2].default_eq(&self[2][0]) &&
self[1][0].fuzzy_eq(&self[0][1]) && self[1][0].default_eq(&self[0][1]) &&
self[1][2].fuzzy_eq(&self[2][1]) && self[1][2].default_eq(&self[2][1]) &&
self[2][0].fuzzy_eq(&self[0][2]) && self[2][0].default_eq(&self[0][2]) &&
self[2][1].fuzzy_eq(&self[1][2]) self[2][1].default_eq(&self[1][2])
} }
#[inline(always)] #[inline(always)]
pure fn is_diagonal() -> bool { pure fn is_diagonal() -> bool {
let _0 = cast(0); let _0 = cast(0);
self[0][1].fuzzy_eq(&_0) && self[0][1].default_eq(&_0) &&
self[0][2].fuzzy_eq(&_0) && self[0][2].default_eq(&_0) &&
self[1][0].fuzzy_eq(&_0) && self[1][0].default_eq(&_0) &&
self[1][2].fuzzy_eq(&_0) && self[1][2].default_eq(&_0) &&
self[2][0].fuzzy_eq(&_0) && self[2][0].default_eq(&_0) &&
self[2][1].fuzzy_eq(&_0) self[2][1].default_eq(&_0)
} }
#[inline(always)] #[inline(always)]
pure fn is_rotated() -> bool { pure fn is_rotated() -> bool {
!self.fuzzy_eq(&Mat3::identity()) !self.default_eq(&Mat3::identity())
} }
#[inline(always)] #[inline(always)]
pure fn is_invertible() -> bool { pure fn is_invertible() -> bool {
let _0 = cast(0); let _0 = cast(0);
!self.det().fuzzy_eq(&_0) !self.det().default_eq(&_0)
} }
} }
@ -541,10 +542,10 @@ pub impl<T:Copy Num NumCast Ord> Mat3<T>: ToQuat<T> {
} }
// TODO: make work for T:Integer // TODO: make work for T:Integer
pub impl<T:Copy FuzzyEq> Mat3<T>: Eq { pub impl<T:Copy DefaultEq> Mat3<T>: Eq {
#[inline(always)] #[inline(always)]
pure fn eq(other: &Mat3<T>) -> bool { pure fn eq(other: &Mat3<T>) -> bool {
self.fuzzy_eq(other) self.default_eq(other)
} }
#[inline(always)] #[inline(always)]
@ -553,15 +554,6 @@ pub impl<T:Copy FuzzyEq> Mat3<T>: Eq {
} }
} }
pub impl<T:Copy Eq> Mat3<T>: ExactEq {
#[inline(always)]
pure fn exact_eq(other: &Mat3<T>) -> bool {
self[0].exact_eq(&other[0]) &&
self[1].exact_eq(&other[1]) &&
self[2].exact_eq(&other[2])
}
}
pub impl<T:Copy FuzzyEq> Mat3<T>: FuzzyEq { pub impl<T:Copy FuzzyEq> Mat3<T>: FuzzyEq {
#[inline(always)] #[inline(always)]
pure fn fuzzy_eq(other: &Mat3<T>) -> bool { pure fn fuzzy_eq(other: &Mat3<T>) -> bool {
@ -571,6 +563,15 @@ pub impl<T:Copy FuzzyEq> Mat3<T>: FuzzyEq {
} }
} }
pub impl<T:Copy DefaultEq> Mat3<T>: DefaultEq {
#[inline(always)]
pure fn default_eq(other: &Mat3<T>) -> bool {
self[0].default_eq(&other[0]) &&
self[1].default_eq(&other[1]) &&
self[2].default_eq(&other[2])
}
}
@ -731,7 +732,7 @@ pub impl<T:Copy Num> Mat4<T>: NumericMatrix<T, Vec4<T>, Vec4<T>> {
} }
} }
pub impl<T:Copy Num NumCast FuzzyEq Signed Ord> Mat4<T>: NumericMatrix_NxN<T, Vec4<T>> { pub impl<T:Copy Num NumCast DefaultEq Signed Ord> Mat4<T>: NumericMatrix_NxN<T, Vec4<T>> {
#[inline(always)] #[inline(always)]
pure fn mul_m(other: &Mat4<T>) -> Mat4<T> { pure fn mul_m(other: &Mat4<T>) -> Mat4<T> {
// Surprisingly when building with optimisation turned on this is actually // Surprisingly when building with optimisation turned on this is actually
@ -761,7 +762,7 @@ pub impl<T:Copy Num NumCast FuzzyEq Signed Ord> Mat4<T>: NumericMatrix_NxN<T, Ve
pure fn invert() -> Option<Mat4<T>> { pure fn invert() -> Option<Mat4<T>> {
let d = self.det(); let d = self.det();
let _0 = cast(0); let _0 = cast(0);
if d.fuzzy_eq(&_0) { if d.default_eq(&_0) {
None None
} else { } else {
@ -824,57 +825,57 @@ pub impl<T:Copy Num NumCast FuzzyEq Signed Ord> Mat4<T>: NumericMatrix_NxN<T, Ve
#[inline(always)] #[inline(always)]
pure fn is_identity() -> bool { pure fn is_identity() -> bool {
self.fuzzy_eq(&Mat4::identity()) self.default_eq(&Mat4::identity())
} }
#[inline(always)] #[inline(always)]
pure fn is_symmetric() -> bool { pure fn is_symmetric() -> bool {
self[0][1].fuzzy_eq(&self[1][0]) && self[0][1].default_eq(&self[1][0]) &&
self[0][2].fuzzy_eq(&self[2][0]) && self[0][2].default_eq(&self[2][0]) &&
self[0][3].fuzzy_eq(&self[3][0]) && self[0][3].default_eq(&self[3][0]) &&
self[1][0].fuzzy_eq(&self[0][1]) && self[1][0].default_eq(&self[0][1]) &&
self[1][2].fuzzy_eq(&self[2][1]) && self[1][2].default_eq(&self[2][1]) &&
self[1][3].fuzzy_eq(&self[3][1]) && self[1][3].default_eq(&self[3][1]) &&
self[2][0].fuzzy_eq(&self[0][2]) && self[2][0].default_eq(&self[0][2]) &&
self[2][1].fuzzy_eq(&self[1][2]) && self[2][1].default_eq(&self[1][2]) &&
self[2][3].fuzzy_eq(&self[3][2]) && self[2][3].default_eq(&self[3][2]) &&
self[3][0].fuzzy_eq(&self[0][3]) && self[3][0].default_eq(&self[0][3]) &&
self[3][1].fuzzy_eq(&self[1][3]) && self[3][1].default_eq(&self[1][3]) &&
self[3][2].fuzzy_eq(&self[2][3]) self[3][2].default_eq(&self[2][3])
} }
#[inline(always)] #[inline(always)]
pure fn is_diagonal() -> bool { pure fn is_diagonal() -> bool {
let _0 = cast(0); let _0 = cast(0);
self[0][1].fuzzy_eq(&_0) && self[0][1].default_eq(&_0) &&
self[0][2].fuzzy_eq(&_0) && self[0][2].default_eq(&_0) &&
self[0][3].fuzzy_eq(&_0) && self[0][3].default_eq(&_0) &&
self[1][0].fuzzy_eq(&_0) && self[1][0].default_eq(&_0) &&
self[1][2].fuzzy_eq(&_0) && self[1][2].default_eq(&_0) &&
self[1][3].fuzzy_eq(&_0) && self[1][3].default_eq(&_0) &&
self[2][0].fuzzy_eq(&_0) && self[2][0].default_eq(&_0) &&
self[2][1].fuzzy_eq(&_0) && self[2][1].default_eq(&_0) &&
self[2][3].fuzzy_eq(&_0) && self[2][3].default_eq(&_0) &&
self[3][0].fuzzy_eq(&_0) && self[3][0].default_eq(&_0) &&
self[3][1].fuzzy_eq(&_0) && self[3][1].default_eq(&_0) &&
self[3][2].fuzzy_eq(&_0) self[3][2].default_eq(&_0)
} }
#[inline(always)] #[inline(always)]
pure fn is_rotated() -> bool { pure fn is_rotated() -> bool {
!self.fuzzy_eq(&Mat4::identity()) !self.default_eq(&Mat4::identity())
} }
#[inline(always)] #[inline(always)]
pure fn is_invertible() -> bool { pure fn is_invertible() -> bool {
let _0 = cast(0); let _0 = cast(0);
!self.det().fuzzy_eq(&_0) !self.det().default_eq(&_0)
} }
} }
@ -883,10 +884,10 @@ pub impl<T> Mat4<T>: Matrix4<T> {
} }
// TODO: make work for T:Integer // TODO: make work for T:Integer
pub impl<T:Copy FuzzyEq> Mat4<T>: Eq { pub impl<T:Copy DefaultEq> Mat4<T>: Eq {
#[inline(always)] #[inline(always)]
pure fn eq(other: &Mat4<T>) -> bool { pure fn eq(other: &Mat4<T>) -> bool {
self.fuzzy_eq(other) self.default_eq(other)
} }
#[inline(always)] #[inline(always)]
@ -895,16 +896,6 @@ pub impl<T:Copy FuzzyEq> Mat4<T>: Eq {
} }
} }
pub impl<T:Copy Eq> Mat4<T>: ExactEq {
#[inline(always)]
pure fn exact_eq(other: &Mat4<T>) -> 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<T:Copy FuzzyEq> Mat4<T>: FuzzyEq { pub impl<T:Copy FuzzyEq> Mat4<T>: FuzzyEq {
#[inline(always)] #[inline(always)]
pure fn fuzzy_eq(other: &Mat4<T>) -> bool { pure fn fuzzy_eq(other: &Mat4<T>) -> bool {
@ -914,3 +905,13 @@ pub impl<T:Copy FuzzyEq> Mat4<T>: FuzzyEq {
self[3].fuzzy_eq(&other[3]) self[3].fuzzy_eq(&other[3])
} }
} }
pub impl<T:Copy DefaultEq> Mat4<T>: DefaultEq {
#[inline(always)]
pure fn default_eq(other: &Mat4<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])
}
}

View file

@ -12,13 +12,14 @@ use funs::common::*;
use math::*; use math::*;
use mat::{Mat3, Mat4}; use mat::{Mat3, Mat4};
use num::cast::*; use num::cast::*;
use num::default_eq::DefaultEq;
use vec::Vec3; use vec::Vec3;
// //
// Quaternion // Quaternion
// //
pub trait Quaternion<T>: Dimensional<T>, Eq, Neg<self> { pub trait Quaternion<T>: Dimensional<T>, Eq, DefaultEq, Neg<self> {
pure fn mul_t(value: T) -> self; pure fn mul_t(value: T) -> self;
pure fn div_t(value: T) -> self; pure fn div_t(value: T) -> self;
@ -266,11 +267,10 @@ pub impl<T:Copy> Quat<T>: Index<uint, T> {
} }
} }
// TODO: make work for T:Integer pub impl<T:Copy DefaultEq> Quat<T>: Eq {
pub impl<T:Copy FuzzyEq> Quat<T>: Eq {
#[inline(always)] #[inline(always)]
pure fn eq(other: &Quat<T>) -> bool { pure fn eq(other: &Quat<T>) -> bool {
self.fuzzy_eq(other) self.default_eq(other)
} }
#[inline(always)] #[inline(always)]
@ -279,16 +279,6 @@ pub impl<T:Copy FuzzyEq> Quat<T>: Eq {
} }
} }
pub impl<T:Copy Eq> Quat<T>: ExactEq {
#[inline(always)]
pure fn exact_eq(other: &Quat<T>) -> bool {
self[0] == other[0] &&
self[1] == other[1] &&
self[2] == other[2] &&
self[3] == other[3]
}
}
pub impl<T:Copy FuzzyEq> Quat<T>: FuzzyEq { pub impl<T:Copy FuzzyEq> Quat<T>: FuzzyEq {
#[inline(always)] #[inline(always)]
pure fn fuzzy_eq(other: &Quat<T>) -> bool { pure fn fuzzy_eq(other: &Quat<T>) -> bool {
@ -297,4 +287,14 @@ pub impl<T:Copy FuzzyEq> Quat<T>: FuzzyEq {
self[2].fuzzy_eq(&other[2]) && self[2].fuzzy_eq(&other[2]) &&
self[3].fuzzy_eq(&other[3]) self[3].fuzzy_eq(&other[3])
} }
}
pub impl<T:Copy DefaultEq> Quat<T>: DefaultEq {
#[inline(always)]
pure fn default_eq(other: &Quat<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])
}
} }

View file

@ -9,9 +9,10 @@ use dim::Dimensional;
use funs::exp::Exp; use funs::exp::Exp;
use math::*; use math::*;
use num::cast::*; use num::cast::*;
use num::default_eq::DefaultEq;
pub trait Vector<T>: Dimensional<T>, Eq {} pub trait Vector<T>: Dimensional<T>, Eq, DefaultEq {}
pub trait NumericVector<T>: Vector<T>, Neg<self>{ pub trait NumericVector<T>: Vector<T>, Neg<self>{
pure fn mul_t(value: T) -> self; pure fn mul_t(value: T) -> self;
@ -187,10 +188,10 @@ pub impl<T:Copy Num NumCast Exp> Vec2<T>: GeometricVector<T> {
} }
// TODO: make work for T:Integer // TODO: make work for T:Integer
pub impl<T:Copy FuzzyEq> Vec2<T>: Eq { pub impl<T:Copy DefaultEq> Vec2<T>: Eq {
#[inline(always)] #[inline(always)]
pure fn eq(other: &Vec2<T>) -> bool { pure fn eq(other: &Vec2<T>) -> bool {
self.fuzzy_eq(other) self.default_eq(other)
} }
#[inline(always)] #[inline(always)]
@ -199,14 +200,6 @@ pub impl<T:Copy FuzzyEq> Vec2<T>: Eq {
} }
} }
impl<T:Copy Eq> Vec2<T>: ExactEq {
#[inline(always)]
pure fn exact_eq(other: &Vec2<T>) -> bool {
self[0] == other[0] &&
self[1] == other[1]
}
}
pub impl<T:Copy FuzzyEq> Vec2<T>: FuzzyEq { pub impl<T:Copy FuzzyEq> Vec2<T>: FuzzyEq {
#[inline(always)] #[inline(always)]
pure fn fuzzy_eq(other: &Vec2<T>) -> bool { pure fn fuzzy_eq(other: &Vec2<T>) -> bool {
@ -215,6 +208,14 @@ pub impl<T:Copy FuzzyEq> Vec2<T>: FuzzyEq {
} }
} }
pub impl<T:Copy DefaultEq> Vec2<T>: DefaultEq {
#[inline(always)]
pure fn default_eq(other: &Vec2<T>) -> bool {
self[0].default_eq(&other[0]) &&
self[1].default_eq(&other[1])
}
}
@ -375,10 +376,10 @@ pub impl<T:Copy Num NumCast Exp> Vec3<T>: GeometricVector<T> {
} }
// TODO: make work for T:Integer // TODO: make work for T:Integer
pub impl<T:Copy FuzzyEq> Vec3<T>: Eq { pub impl<T:Copy DefaultEq> Vec3<T>: Eq {
#[inline(always)] #[inline(always)]
pure fn eq(other: &Vec3<T>) -> bool { pure fn eq(other: &Vec3<T>) -> bool {
self.fuzzy_eq(other) self.default_eq(other)
} }
#[inline(always)] #[inline(always)]
@ -387,15 +388,6 @@ pub impl<T:Copy FuzzyEq> Vec3<T>: Eq {
} }
} }
pub impl<T:Copy Eq> Vec3<T>: ExactEq {
#[inline(always)]
pure fn exact_eq(other: &Vec3<T>) -> bool {
self[0] == other[0] &&
self[1] == other[1] &&
self[2] == other[2]
}
}
pub impl<T:Copy FuzzyEq> Vec3<T>: FuzzyEq { pub impl<T:Copy FuzzyEq> Vec3<T>: FuzzyEq {
#[inline(always)] #[inline(always)]
pure fn fuzzy_eq(other: &Vec3<T>) -> bool { pure fn fuzzy_eq(other: &Vec3<T>) -> bool {
@ -405,6 +397,15 @@ pub impl<T:Copy FuzzyEq> Vec3<T>: FuzzyEq {
} }
} }
pub impl<T:Copy DefaultEq> Vec3<T>: DefaultEq {
#[inline(always)]
pure fn default_eq(other: &Vec3<T>) -> bool {
self[0].default_eq(&other[0]) &&
self[1].default_eq(&other[1]) &&
self[2].default_eq(&other[2])
}
}
@ -566,10 +567,10 @@ pub impl<T:Copy Num NumCast Exp> Vec4<T>: GeometricVector<T> {
} }
} }
pub impl<T:Copy FuzzyEq> Vec4<T>: Eq { pub impl<T:Copy DefaultEq> Vec4<T>: Eq {
#[inline(always)] #[inline(always)]
pure fn eq(other: &Vec4<T>) -> bool { pure fn eq(other: &Vec4<T>) -> bool {
self.fuzzy_eq(other) self.default_eq(other)
} }
#[inline(always)] #[inline(always)]
@ -578,17 +579,6 @@ pub impl<T:Copy FuzzyEq> Vec4<T>: Eq {
} }
} }
// TODO: make work for T:Integer
pub impl<T:Copy Eq> Vec4<T>: ExactEq {
#[inline(always)]
pure fn exact_eq(other: &Vec4<T>) -> bool {
self[0] == other[0] &&
self[1] == other[1] &&
self[2] == other[2] &&
self[3] == other[3]
}
}
pub impl<T:Copy FuzzyEq> Vec4<T>: FuzzyEq { pub impl<T:Copy FuzzyEq> Vec4<T>: FuzzyEq {
#[inline(always)] #[inline(always)]
pure fn fuzzy_eq(other: &Vec4<T>) -> bool { pure fn fuzzy_eq(other: &Vec4<T>) -> bool {
@ -597,4 +587,14 @@ pub impl<T:Copy FuzzyEq> Vec4<T>: FuzzyEq {
self[2].fuzzy_eq(&other[2]) && self[2].fuzzy_eq(&other[2]) &&
self[3].fuzzy_eq(&other[3]) self[3].fuzzy_eq(&other[3])
} }
}
pub impl<T:Copy DefaultEq> Vec4<T>: DefaultEq {
#[inline(always)]
pure fn default_eq(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])
}
} }