Divide RelationalVector into OrdinalVector and EquableVector

This commit is contained in:
Brendan Zabarauskas 2012-12-17 15:35:03 +10:00
parent 9cc6fa5b30
commit 85047f58b6
4 changed files with 58 additions and 7 deletions

View file

@ -309,12 +309,40 @@ pub trait MutableEuclideanVector<T>: MutableNumericVector<&self/T>
/** /**
* Component-wise vector comparison methods * Component-wise vector comparison methods
*/ */
pub trait RelationalVector<T, BoolVec>: Vector<T> { pub trait OrdinalVector<T, BoolVec>: Vector<T> {
/**
* Component-wise compare of `self < other`
*/
pure fn less_than(&self, other: &self) -> BoolVec; pure fn less_than(&self, other: &self) -> BoolVec;
/**
* Component-wise compare of `self <= other`
*/
pure fn less_than_equal(&self, other: &self) -> BoolVec; pure fn less_than_equal(&self, other: &self) -> BoolVec;
/**
* Component-wise compare of `self > other`
*/
pure fn greater_than(&self, other: &self) -> BoolVec; pure fn greater_than(&self, other: &self) -> BoolVec;
/**
* Component-wise compare of `self >= other`
*/
pure fn greater_than_equal(&self, other: &self) -> BoolVec; pure fn greater_than_equal(&self, other: &self) -> BoolVec;
}
/**
* Component-wise equality comparison methods
*/
pub trait EquableVector<T, BoolVec>: Vector<T> {
/**
* Component-wise compare of `self == other`
*/
pure fn equal(&self, other: &self) -> BoolVec; pure fn equal(&self, other: &self) -> BoolVec;
/**
* Component-wise compare of `self != other`
*/
pure fn not_equal(&self, other: &self) -> BoolVec; pure fn not_equal(&self, other: &self) -> BoolVec;
} }
@ -322,7 +350,24 @@ pub trait RelationalVector<T, BoolVec>: Vector<T> {
* A vector with boolean components * A vector with boolean components
*/ */
pub trait BooleanVector: Vector<bool> { pub trait BooleanVector: Vector<bool> {
/**
* # Return value
*
* `true` if of any component is `true`
*/
pure fn any(&self) -> bool; pure fn any(&self) -> bool;
/**
* # Return value
*
* `true` only if all components are `true`
*/
pure fn all(&self) -> bool; pure fn all(&self) -> bool;
/**
* # Return value
*
* the component-wise logical complement
*/
pure fn not(&self) -> self; pure fn not(&self) -> self;
} }

View file

@ -246,7 +246,7 @@ pub impl<T:Copy FuzzyEq> Vec2<T>: FuzzyEq {
} }
} }
pub impl<T:Copy Ord Eq> Vec2<T>: RelationalVector<T, Vec2<bool>> { pub impl<T:Copy Ord> Vec2<T>: OrdinalVector<T, Vec2<bool>> {
#[inline(always)] #[inline(always)]
pure fn less_than(&self, other: &Vec2<T>) -> Vec2<bool> { pure fn less_than(&self, other: &Vec2<T>) -> Vec2<bool> {
Vec2::new(self[0] < other[0], Vec2::new(self[0] < other[0],
@ -270,7 +270,9 @@ pub impl<T:Copy Ord Eq> Vec2<T>: RelationalVector<T, Vec2<bool>> {
Vec2::new(self[0] >= other[0], Vec2::new(self[0] >= other[0],
self[1] >= other[1]) self[1] >= other[1])
} }
}
pub impl<T:Copy Eq> Vec2<T>: EquableVector<T, Vec2<bool>> {
#[inline(always)] #[inline(always)]
pure fn equal(&self, other: &Vec2<T>) -> Vec2<bool> { pure fn equal(&self, other: &Vec2<T>) -> Vec2<bool> {
Vec2::new(self[0] == other[0], Vec2::new(self[0] == other[0],

View file

@ -271,7 +271,7 @@ pub impl<T:Copy FuzzyEq> Vec3<T>: FuzzyEq {
} }
} }
pub impl<T:Copy Ord Eq> Vec3<T>: RelationalVector<T, Vec3<bool>> { pub impl<T:Copy Ord> Vec3<T>: OrdinalVector<T, Vec3<bool>> {
#[inline(always)] #[inline(always)]
pure fn less_than(&self, other: &Vec3<T>) -> Vec3<bool> { pure fn less_than(&self, other: &Vec3<T>) -> Vec3<bool> {
Vec3::new(self[0] < other[0], Vec3::new(self[0] < other[0],
@ -299,7 +299,9 @@ pub impl<T:Copy Ord Eq> Vec3<T>: RelationalVector<T, Vec3<bool>> {
self[1] >= other[1], self[1] >= other[1],
self[2] >= other[2]) self[2] >= other[2])
} }
}
pub impl<T:Copy Eq> Vec3<T>: EquableVector<T, Vec3<bool>> {
#[inline(always)] #[inline(always)]
pure fn equal(&self, other: &Vec3<T>) -> Vec3<bool> { pure fn equal(&self, other: &Vec3<T>) -> Vec3<bool> {
Vec3::new(self[0] == other[0], Vec3::new(self[0] == other[0],

View file

@ -271,7 +271,7 @@ pub impl<T:Copy FuzzyEq> Vec4<T>: FuzzyEq {
} }
} }
pub impl<T:Copy Ord Eq> Vec4<T>: RelationalVector<T, Vec4<bool>> { pub impl<T:Copy Ord> Vec4<T>: OrdinalVector<T, Vec4<bool>> {
#[inline(always)] #[inline(always)]
pure fn less_than(&self, other: &Vec4<T>) -> Vec4<bool> { pure fn less_than(&self, other: &Vec4<T>) -> Vec4<bool> {
Vec4::new(self[0] < other[0], Vec4::new(self[0] < other[0],
@ -303,7 +303,9 @@ pub impl<T:Copy Ord Eq> Vec4<T>: RelationalVector<T, Vec4<bool>> {
self[2] >= other[2], self[2] >= other[2],
self[3] >= other[3]) self[3] >= other[3])
} }
}
pub impl<T:Copy Eq> Vec4<T>: EquableVector<T, Vec4<bool>> {
#[inline(always)] #[inline(always)]
pure fn equal(&self, other: &Vec4<T>) -> Vec4<bool> { pure fn equal(&self, other: &Vec4<T>) -> Vec4<bool> {
Vec4::new(self[0] == other[0], Vec4::new(self[0] == other[0],