Divide RelationalVector into OrdinalVector and EquableVector
This commit is contained in:
parent
9cc6fa5b30
commit
85047f58b6
4 changed files with 58 additions and 7 deletions
47
src/vec.rs
47
src/vec.rs
|
@ -309,12 +309,40 @@ pub trait MutableEuclideanVector<T>: MutableNumericVector<&self/T>
|
|||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* Component-wise compare of `self <= other`
|
||||
*/
|
||||
pure fn less_than_equal(&self, other: &self) -> BoolVec;
|
||||
|
||||
/**
|
||||
* Component-wise compare of `self > other`
|
||||
*/
|
||||
pure fn greater_than(&self, other: &self) -> BoolVec;
|
||||
|
||||
/**
|
||||
* Component-wise compare of `self >= other`
|
||||
*/
|
||||
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;
|
||||
|
||||
/**
|
||||
* Component-wise compare of `self != other`
|
||||
*/
|
||||
pure fn not_equal(&self, other: &self) -> BoolVec;
|
||||
}
|
||||
|
||||
|
@ -322,7 +350,24 @@ pub trait RelationalVector<T, BoolVec>: Vector<T> {
|
|||
* A vector with boolean components
|
||||
*/
|
||||
pub trait BooleanVector: Vector<bool> {
|
||||
/**
|
||||
* # Return value
|
||||
*
|
||||
* `true` if of any component is `true`
|
||||
*/
|
||||
pure fn any(&self) -> bool;
|
||||
|
||||
/**
|
||||
* # Return value
|
||||
*
|
||||
* `true` only if all components are `true`
|
||||
*/
|
||||
pure fn all(&self) -> bool;
|
||||
|
||||
/**
|
||||
* # Return value
|
||||
*
|
||||
* the component-wise logical complement
|
||||
*/
|
||||
pure fn not(&self) -> self;
|
||||
}
|
|
@ -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)]
|
||||
pure fn less_than(&self, other: &Vec2<T>) -> Vec2<bool> {
|
||||
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],
|
||||
self[1] >= other[1])
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
pub impl<T:Copy Eq> Vec2<T>: EquableVector<T, Vec2<bool>> {
|
||||
#[inline(always)]
|
||||
pure fn equal(&self, other: &Vec2<T>) -> Vec2<bool> {
|
||||
Vec2::new(self[0] == other[0],
|
||||
|
|
|
@ -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)]
|
||||
pure fn less_than(&self, other: &Vec3<T>) -> Vec3<bool> {
|
||||
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[2] >= other[2])
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
pub impl<T:Copy Eq> Vec3<T>: EquableVector<T, Vec3<bool>> {
|
||||
#[inline(always)]
|
||||
pure fn equal(&self, other: &Vec3<T>) -> Vec3<bool> {
|
||||
Vec3::new(self[0] == other[0],
|
||||
|
|
|
@ -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)]
|
||||
pure fn less_than(&self, other: &Vec4<T>) -> Vec4<bool> {
|
||||
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[3] >= other[3])
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
pub impl<T:Copy Eq> Vec4<T>: EquableVector<T, Vec4<bool>> {
|
||||
#[inline(always)]
|
||||
pure fn equal(&self, other: &Vec4<T>) -> Vec4<bool> {
|
||||
Vec4::new(self[0] == other[0],
|
||||
|
|
Loading…
Reference in a new issue