From 85047f58b67e4ca208a2111cde81eba87a9797df Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Mon, 17 Dec 2012 15:35:03 +1000 Subject: [PATCH] Divide RelationalVector into OrdinalVector and EquableVector --- src/vec.rs | 47 ++++++++++++++++++++++++++++++++++++++++++++++- src/vec2.rs | 6 ++++-- src/vec3.rs | 6 ++++-- src/vec4.rs | 6 ++++-- 4 files changed, 58 insertions(+), 7 deletions(-) diff --git a/src/vec.rs b/src/vec.rs index 5119c6d..61f0219 100644 --- a/src/vec.rs +++ b/src/vec.rs @@ -309,12 +309,40 @@ pub trait MutableEuclideanVector: MutableNumericVector<&self/T> /** * Component-wise vector comparison methods */ -pub trait RelationalVector: Vector { +pub trait OrdinalVector: Vector { + /** + * 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: Vector { + /** + * 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: Vector { * A vector with boolean components */ pub trait BooleanVector: Vector { + /** + * # 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; } \ No newline at end of file diff --git a/src/vec2.rs b/src/vec2.rs index 9b750a9..26d2a29 100644 --- a/src/vec2.rs +++ b/src/vec2.rs @@ -246,7 +246,7 @@ pub impl Vec2: FuzzyEq { } } -pub impl Vec2: RelationalVector> { +pub impl Vec2: OrdinalVector> { #[inline(always)] pure fn less_than(&self, other: &Vec2) -> Vec2 { Vec2::new(self[0] < other[0], @@ -270,7 +270,9 @@ pub impl Vec2: RelationalVector> { Vec2::new(self[0] >= other[0], self[1] >= other[1]) } - +} + +pub impl Vec2: EquableVector> { #[inline(always)] pure fn equal(&self, other: &Vec2) -> Vec2 { Vec2::new(self[0] == other[0], diff --git a/src/vec3.rs b/src/vec3.rs index 3af93f6..cea19d1 100644 --- a/src/vec3.rs +++ b/src/vec3.rs @@ -271,7 +271,7 @@ pub impl Vec3: FuzzyEq { } } -pub impl Vec3: RelationalVector> { +pub impl Vec3: OrdinalVector> { #[inline(always)] pure fn less_than(&self, other: &Vec3) -> Vec3 { Vec3::new(self[0] < other[0], @@ -299,7 +299,9 @@ pub impl Vec3: RelationalVector> { self[1] >= other[1], self[2] >= other[2]) } - +} + +pub impl Vec3: EquableVector> { #[inline(always)] pure fn equal(&self, other: &Vec3) -> Vec3 { Vec3::new(self[0] == other[0], diff --git a/src/vec4.rs b/src/vec4.rs index e3c8e41..ee07d17 100644 --- a/src/vec4.rs +++ b/src/vec4.rs @@ -271,7 +271,7 @@ pub impl Vec4: FuzzyEq { } } -pub impl Vec4: RelationalVector> { +pub impl Vec4: OrdinalVector> { #[inline(always)] pure fn less_than(&self, other: &Vec4) -> Vec4 { Vec4::new(self[0] < other[0], @@ -303,7 +303,9 @@ pub impl Vec4: RelationalVector> { self[2] >= other[2], self[3] >= other[3]) } - +} + +pub impl Vec4: EquableVector> { #[inline(always)] pure fn equal(&self, other: &Vec4) -> Vec4 { Vec4::new(self[0] == other[0],