From 28a9a8250a186d9339aea640240af3ee86e1cccc Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Sun, 28 Oct 2012 16:59:19 +1000 Subject: [PATCH] Move abs method to Abs trait implementations --- src/vec.rs | 57 +++++++++++++++++++++++++++--------------------------- 1 file changed, 28 insertions(+), 29 deletions(-) diff --git a/src/vec.rs b/src/vec.rs index 0fbd996..cc3ebd0 100644 --- a/src/vec.rs +++ b/src/vec.rs @@ -1,7 +1,7 @@ use std::cmp::FuzzyEq; use cmp::Eq; use ops::{Neg, Index}; -use math::{Abs, min, max, Sqrt}; +use math::{Abs, abs, min, max, Sqrt}; use to_str::ToStr; // @@ -27,7 +27,6 @@ pub trait Vector { pure fn normalize() -> self; pure fn lerp(other: &self, value: T) -> self; - pure fn abs() -> self; pure fn min(other: &self) -> self; pure fn max(other: &self) -> self; @@ -35,12 +34,6 @@ pub trait Vector { static pure fn identity() -> self; } - - - - - - pub trait Vector3 { fn cross(other: &self) -> self; } @@ -142,12 +135,6 @@ pub impl Vec2: Vector { self.add_v(&other.sub_v(&self).mul_f(value)) } - #[inline] - pure fn abs() -> Vec2 { - Vec2(self[0].abs(), - self[1].abs()) - } - #[inline] pure fn min(other: &Vec2) -> Vec2 { Vec2(min(&self[0], &other[0]), @@ -175,6 +162,14 @@ pub impl Vec2: Index { } } +pub impl Vec2: Abs { + #[inline] + pure fn abs() -> Vec2 { + Vec2(abs(self[0]), + abs(self[1])) + } +} + pub impl Vec2: Neg { #[inline] pure fn neg() -> Vec2 { @@ -328,13 +323,6 @@ pub impl Vec3: Vector { self.add_v(&other.sub_v(&self).mul_f(value)) } - #[inline] - pure fn abs() -> Vec3 { - Vec3(self[0].abs(), - self[1].abs(), - self[2].abs()) - } - #[inline] pure fn min(other: &Vec3) -> Vec3 { Vec3(min(&self[0], &other[0]), @@ -365,6 +353,15 @@ pub impl Vec3: Index { } } +pub impl Vec3: Abs { + #[inline] + pure fn abs() -> Vec3 { + Vec3(abs(self[0]), + abs(self[1]), + abs(self[2])) + } +} + pub impl Vec3: Neg { #[inline] pure fn neg() -> Vec3 { @@ -516,14 +513,6 @@ pub impl Vec4: Vector { self.add_v(&other.sub_v(&self).mul_f(value)) } - #[inline] - pure fn abs() -> Vec4 { - Vec4(self[0].abs(), - self[1].abs(), - self[2].abs(), - self[3].abs()) - } - #[inline] pure fn min(other: &Vec4) -> Vec4 { Vec4(min(&self[0], &other[0]), @@ -557,6 +546,16 @@ pub impl Vec4: Index { } } +pub impl Vec4: Abs { + #[inline] + pure fn abs() -> Vec4 { + Vec4(abs(self[0]), + abs(self[1]), + abs(self[2]), + abs(self[3])) + } +} + pub impl Vec4: Neg { #[inline] pure fn neg() -> Vec4 {