Create separate ToHomogeneous trait

This commit is contained in:
Brendan Zabarauskas 2013-01-02 16:59:24 +10:00
parent a16a41daad
commit 8818c9ffbf
3 changed files with 23 additions and 11 deletions

View file

@ -199,7 +199,7 @@ pub trait NumericVector2<T>: NumericVector<T> {
/**
* A 3-dimensional vector with numeric components
*/
pub trait NumericVector3<T,HV>: NumericVector<T> {
pub trait NumericVector3<T>: NumericVector<T> {
// static pure fn unit_x() -> self;
// static pure fn unit_y() -> self;
// static pure fn unit_z() -> self;
@ -210,11 +210,6 @@ pub trait NumericVector3<T,HV>: NumericVector<T> {
* The cross product of the vector and `other`
*/
pure fn cross(&self, other: &self) -> self;
/**
* Convert the vector to its homogeneous form
*/
pure fn to_homogeneous(&self) -> HV;
}
/**
@ -237,6 +232,13 @@ pub trait NumericVector4<T>: NumericVector<T> {
// static pure fn unit_w() -> self;
}
pub trait ToHomogeneous<H> {
/**
* Convert to a homogenous coordinate
*/
pure fn to_homogeneous(&self) -> H;
}
/**
* A Euclidean (or Affine) vector
*

View file

@ -191,6 +191,13 @@ pub impl<T:Copy Number> Vec2<T>: NumericVector2<T> {
}
}
pub impl<T:Copy Number> Vec2<T>: ToHomogeneous<Vec3<T>> {
#[inline(always)]
pure fn to_homogeneous(&self) -> Vec3<T> {
Vec3::new(self.x, self.y, zero())
}
}
pub impl<T:Copy Float> Vec2<T>: EuclideanVector<T> {
#[inline(always)]
pure fn length2(&self) -> T {

View file

@ -203,17 +203,13 @@ pub impl<T:Copy Number> Vec3<T>: MutableNumericVector<&self/T> {
}
}
pub impl<T:Copy Number> Vec3<T>: NumericVector3<T,Vec4<T>> {
pub impl<T:Copy Number> Vec3<T>: NumericVector3<T> {
#[inline(always)]
pure fn cross(&self, other: &Vec3<T>) -> Vec3<T> {
Vec3::new((self[1] * other[2]) - (self[2] * other[1]),
(self[2] * other[0]) - (self[0] * other[2]),
(self[0] * other[1]) - (self[1] * other[0]))
}
pure fn to_homogeneous(&self) -> Vec4<T> {
Vec4::new(self.x, self.y, self.z, zero())
}
}
pub impl<T:Copy Number> Vec3<T>: MutableNumericVector3<&self/T> {
@ -223,6 +219,13 @@ pub impl<T:Copy Number> Vec3<T>: MutableNumericVector3<&self/T> {
}
}
pub impl<T:Copy Number> Vec3<T>: ToHomogeneous<Vec4<T>> {
#[inline(always)]
pure fn to_homogeneous(&self) -> Vec4<T> {
Vec4::new(self.x, self.y, self.z, zero())
}
}
pub impl<T:Copy Float> Vec3<T>: EuclideanVector<T> {
#[inline(always)]
pure fn length2(&self) -> T {