From 8818c9ffbfdd0befbe0f7530cb2a03a1a2d13e3a Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Wed, 2 Jan 2013 16:59:24 +1000 Subject: [PATCH] Create separate ToHomogeneous trait --- src/vec.rs | 14 ++++++++------ src/vec2.rs | 7 +++++++ src/vec3.rs | 13 ++++++++----- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/vec.rs b/src/vec.rs index 53d1173..eda8157 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,11 +210,6 @@ 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; } /** @@ -237,6 +232,13 @@ pub trait NumericVector4: NumericVector { // static pure fn unit_w() -> self; } +pub trait ToHomogeneous { + /** + * Convert to a homogenous coordinate + */ + pure fn to_homogeneous(&self) -> H; +} + /** * A Euclidean (or Affine) vector * diff --git a/src/vec2.rs b/src/vec2.rs index 4bff30e..c5d0b4f 100644 --- a/src/vec2.rs +++ b/src/vec2.rs @@ -191,6 +191,13 @@ pub impl Vec2: NumericVector2 { } } +pub impl Vec2: ToHomogeneous> { + #[inline(always)] + pure fn to_homogeneous(&self) -> Vec3 { + Vec3::new(self.x, self.y, zero()) + } +} + pub impl Vec2: EuclideanVector { #[inline(always)] pure fn length2(&self) -> T { diff --git a/src/vec3.rs b/src/vec3.rs index 09286f6..8aaad4e 100644 --- a/src/vec3.rs +++ b/src/vec3.rs @@ -203,17 +203,13 @@ 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> { @@ -223,6 +219,13 @@ pub impl Vec3: MutableNumericVector3<&self/T> { } } +pub impl Vec3: ToHomogeneous> { + #[inline(always)] + pure fn to_homogeneous(&self) -> Vec4 { + Vec4::new(self.x, self.y, self.z, zero()) + } +} + pub impl Vec3: EuclideanVector { #[inline(always)] pure fn length2(&self) -> T {