Add to_homogeneous conversion method

This commit is contained in:
Brendan Zabarauskas 2012-12-31 12:24:14 +10:00
parent 73548ab1cb
commit 1295f574b2
2 changed files with 13 additions and 2 deletions

View file

@ -199,7 +199,7 @@ pub trait NumericVector2<T>: NumericVector<T> {
/**
* A 3-dimensional vector with numeric components
*/
pub trait NumericVector3<T>: NumericVector<T> {
pub trait NumericVector3<T,HV>: NumericVector<T> {
// static pure fn unit_x() -> self;
// static pure fn unit_y() -> self;
// static pure fn unit_z() -> self;
@ -210,6 +210,11 @@ pub trait NumericVector3<T>: 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;
}
/**

View file

@ -10,6 +10,8 @@ use numeric::types::float::Float;
use numeric::types::number::Number;
use numeric::types::number::Number::{one, zero};
use vec::Vec4;
/**
* A 3-dimensional vector
*
@ -201,13 +203,17 @@ pub impl<T:Copy Number> Vec3<T>: MutableNumericVector<&self/T> {
}
}
pub impl<T:Copy Number> Vec3<T>: NumericVector3<T> {
pub impl<T:Copy Number> Vec3<T>: NumericVector3<T,Vec4<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> {