From 1295f574b2c823633e16f2348c2f11160fb0d6e3 Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Mon, 31 Dec 2012 12:24:14 +1000 Subject: [PATCH] Add to_homogeneous conversion method --- src/vec.rs | 7 ++++++- src/vec3.rs | 8 +++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/vec.rs b/src/vec.rs index 925cce5..53d1173 100644 --- a/src/vec.rs +++ b/src/vec.rs @@ -199,7 +199,7 @@ pub trait NumericVector2: NumericVector { /** * A 3-dimensional vector with numeric components */ -pub trait NumericVector3: NumericVector { +pub trait NumericVector3: NumericVector { // 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: NumericVector { * 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; } /** diff --git a/src/vec3.rs b/src/vec3.rs index 1afaa93..09286f6 100644 --- a/src/vec3.rs +++ b/src/vec3.rs @@ -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 Vec3: MutableNumericVector<&self/T> { } } -pub impl Vec3: NumericVector3 { +pub impl Vec3: NumericVector3> { #[inline(always)] pure fn cross(&self, other: &Vec3) -> Vec3 { 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 { + Vec4::new(self.x, self.y, self.z, zero()) + } } pub impl Vec3: MutableNumericVector3<&self/T> {