diff --git a/src/core/vec.rs b/src/core/vec.rs index 2f99ec9..0988f88 100644 --- a/src/core/vec.rs +++ b/src/core/vec.rs @@ -15,8 +15,10 @@ use core::{Dimensional, Swap}; +pub trait Vec: Dimensional + Swap {} + /// Vectors with numeric components -pub trait NumVec: Neg { +pub trait NumVec: Neg { pub fn add_t(&self, value: T) -> Self; pub fn sub_t(&self, value: T) -> Self; pub fn mul_t(&self, value: T) -> Self; @@ -42,7 +44,7 @@ pub trait NumVec: Neg { } /// Vectors with real components -pub trait RealVec: NumVec + ApproxEq { +pub trait RealVec: NumVec + ApproxEq { pub fn magnitude2(&self) -> T; pub fn magnitude(&self) -> T; pub fn angle(&self, other: &Self) -> T; @@ -55,7 +57,7 @@ pub trait RealVec: NumVec + ApproxEq { } /// Vectors with orderable components -pub trait OrdVec { +pub trait OrdVec: Vec { pub fn lt_t(&self, value: T) -> BV; pub fn le_t(&self, value: T) -> BV; pub fn ge_t(&self, value: T) -> BV; @@ -67,7 +69,7 @@ pub trait OrdVec { } /// Vectors with components that can be tested for equality -pub trait EqVec: Eq { +pub trait EqVec: Eq { pub fn eq_t(&self, value: T) -> BV; pub fn ne_t(&self, value: T) -> BV; pub fn eq_v(&self, other: &Self) -> BV; @@ -75,7 +77,7 @@ pub trait EqVec: Eq { } /// Vectors with boolean components -pub trait BoolVec: Not { +pub trait BoolVec: Vec + Not { pub fn any(&self) -> bool; pub fn all(&self) -> bool; } @@ -179,7 +181,9 @@ impl Vec2 { } } -impl NumVec for Vec2 { +impl Vec for Vec2 {} + +impl NumVec for Vec2 { /// Returns a new vector with `value` added to each component. #[inline] pub fn add_t(&self, value: T) -> Vec2 { @@ -328,7 +332,7 @@ impl Neg> for Vec2 { } } -impl RealVec for Vec2 { +impl RealVec for Vec2 { /// Returns the squared magnitude of the vector. This does not perform a /// square root operation like in the `magnitude` method and can therefore /// be more efficient for comparing the magnitudes of two vectors. @@ -390,7 +394,7 @@ impl RealVec for Vec2 { } } -impl OrdVec> for Vec2 { +impl OrdVec> for Vec2 { #[inline] pub fn lt_t(&self, value: T) -> Vec2 { Vec2::new(*self.index(0) < value, @@ -440,7 +444,7 @@ impl OrdVec> for Vec2 { } } -impl EqVec> for Vec2 { +impl EqVec> for Vec2 { #[inline] pub fn eq_t(&self, value: T) -> Vec2 { Vec2::new(*self.index(0) == value, @@ -466,7 +470,7 @@ impl EqVec> for Vec2 { } } -impl BoolVec for Vec2 { +impl BoolVec<[bool,..2]> for Vec2 { /// Returns `true` if any of the components of the vector are equal to /// `true`, otherwise `false`. #[inline] @@ -732,7 +736,9 @@ impl Vec3 { } } -impl NumVec for Vec3 { +impl Vec for Vec3 {} + +impl NumVec for Vec3 { /// Returns a new vector with `value` added to each component. #[inline] pub fn add_t(&self, value: T) -> Vec3 { @@ -904,7 +910,7 @@ impl Neg> for Vec3 { } } -impl RealVec for Vec3 { +impl RealVec for Vec3 { /// Returns the squared magnitude of the vector. This does not perform a /// square root operation like in the `magnitude` method and can therefore /// be more efficient for comparing the magnitudes of two vectors. @@ -966,7 +972,7 @@ impl RealVec for Vec3 { } } -impl OrdVec> for Vec3 { +impl OrdVec> for Vec3 { #[inline] pub fn lt_t(&self, value: T) -> Vec3 { Vec3::new(*self.index(0) < value, @@ -1024,7 +1030,7 @@ impl OrdVec> for Vec3 { } } -impl EqVec> for Vec3 { +impl EqVec> for Vec3 { #[inline] pub fn eq_t(&self, value: T) -> Vec3 { Vec3::new(*self.index(0) == value, @@ -1054,7 +1060,7 @@ impl EqVec> for Vec3 { } } -impl BoolVec for Vec3 { +impl BoolVec<[bool,..3]> for Vec3 { /// Returns `true` if any of the components of the vector are equal to /// `true`, otherwise `false`. #[inline] @@ -1313,7 +1319,9 @@ impl Vec4 { } } -impl NumVec for Vec4 { +impl Vec for Vec4 {} + +impl NumVec for Vec4 { /// Returns a new vector with `value` added to each component. #[inline] pub fn add_t(&self, value: T) -> Vec4 { @@ -1508,7 +1516,7 @@ impl Neg> for Vec4 { } } -impl RealVec for Vec4 { +impl RealVec for Vec4 { /// Returns the squared magnitude of the vector. This does not perform a /// square root operation like in the `magnitude` method and can therefore /// be more efficient for comparing the magnitudes of two vectors. @@ -1570,7 +1578,7 @@ impl RealVec for Vec4 { } } -impl OrdVec> for Vec4 { +impl OrdVec> for Vec4 { #[inline] pub fn lt_t(&self, value: T) -> Vec4 { Vec4::new(*self.index(0) < value, @@ -1636,7 +1644,7 @@ impl OrdVec> for Vec4 { } } -impl EqVec> for Vec4 { +impl EqVec> for Vec4 { #[inline] pub fn eq_t(&self, value: T) -> Vec4 { Vec4::new(*self.index(0) == value, @@ -1670,7 +1678,7 @@ impl EqVec> for Vec4 { } } -impl BoolVec for Vec4 { +impl BoolVec<[bool,..4]> for Vec4 { /// Returns `true` if any of the components of the vector are equal to /// `true`, otherwise `false`. #[inline]