diff --git a/src/mat.rs b/src/mat.rs index c3cb6e4..8d3da96 100644 --- a/src/mat.rs +++ b/src/mat.rs @@ -1,6 +1,6 @@ use std::cmp::FuzzyEq; use cmp::Eq; -use ops::Neg; +use ops::{Neg, Index}; // use to_str::ToStr; use math::Sqrt; use quat::Quat; @@ -14,7 +14,6 @@ pub trait Matrix { pure fn cols() -> uint; pure fn is_col_major() -> bool; - pure fn index(&&index:uint) -> V; pure fn row(&&i:uint) -> V; pure fn col(&&i:uint) -> V; @@ -98,11 +97,6 @@ pub impl Mat2: Matrix { #[inline] pure fn is_col_major() -> bool { true } - #[inline] - pure fn index(&&i: uint) -> Vec2 { - self.data[i] - } - #[inline] pure fn row(&&i:uint) -> Vec2 { Vec2(self[0][i], @@ -186,6 +180,13 @@ pub impl Mat2: Matrix { } } +pub impl Mat2: Index { + #[inline] + pure fn index(+i: uint) -> Vec2 { + self.data[i] + } +} + pub impl Mat2: Neg { #[inline] pure fn neg() -> Mat2 { @@ -263,11 +264,6 @@ pub impl Mat3: Matrix { #[inline] pure fn is_col_major() -> bool { true } - #[inline] - pure fn index(&&i: uint) -> Vec3 { - self.data[i] - } - #[inline] pure fn row(&&i:uint) -> Vec3 { Vec3(self[0][i], @@ -433,6 +429,13 @@ pub impl Mat3: Matrix3 { } } +pub impl Mat3: Index { + #[inline] + pure fn index(+i: uint) -> Vec3 { + self.data[i] + } +} + pub impl Mat3: Neg { #[inline] pure fn neg() -> Mat3 { @@ -515,11 +518,6 @@ pub impl Mat4: Matrix { #[inline] pure fn is_col_major() -> bool { true } - #[inline] - pure fn index(&&i: uint) -> Vec4 { - self.data[i] - } - #[inline] pure fn row(&&i:uint) -> Vec4 { Vec4(self[0][i], @@ -678,6 +676,13 @@ pub impl Mat4: Matrix4 { } } +pub impl Mat4: Index { + #[inline] + pure fn index(+i: uint) -> Vec4 { + self.data[i] + } +} + pub impl Mat4: Neg { #[inline] pure fn neg() -> Mat4 { diff --git a/src/quat.rs b/src/quat.rs index 1894dc5..5cdc90b 100644 --- a/src/quat.rs +++ b/src/quat.rs @@ -1,6 +1,6 @@ use std::cmp::FuzzyEq; use cmp::Eq; -use ops::Neg; +use ops::{Neg, Index}; use to_str::ToStr; use math::Sqrt; use mat::{Mat3, Mat4}; @@ -14,7 +14,6 @@ use vec::Vec3; pub trait Quaternion { pure fn dim() -> uint; - pure fn index(&&index:uint) -> T; pure fn w() -> T; pure fn x() -> T; pure fn y() -> T; @@ -72,11 +71,6 @@ pub impl Quat: Quaternion { #[inline] pure fn dim() -> uint { 4 } - #[inline] - pure fn index(&&i: uint) -> float { - self.data[i] - } - #[inline] pure fn w() -> float { self.data[0] } #[inline] pure fn x() -> float { self.data[1] } #[inline] pure fn y() -> float { self.data[2] } @@ -182,6 +176,13 @@ pub impl Quat: Quaternion { } } +pub impl Quat: Index { + #[inline] + pure fn index(+i: uint) -> float { + self.data[i] + } +} + pub impl Quat: Neg { #[inline] pure fn neg() -> Quat { diff --git a/src/vec.rs b/src/vec.rs index 7b6d364..2da7a98 100644 --- a/src/vec.rs +++ b/src/vec.rs @@ -1,6 +1,6 @@ use std::cmp::FuzzyEq; use cmp::Eq; -use ops::Neg; +use ops::{Neg, Index}; use math::{Abs, min, max, Sqrt}; use to_str::ToStr; @@ -10,8 +10,6 @@ use to_str::ToStr; pub trait Vector { static pure fn dim() -> uint; - pure fn index(&&index:uint) -> T; - pure fn add_f(&&value:T) -> self; pure fn sub_f(&&value:T) -> self; pure fn mul_f(&&value:T) -> self; @@ -125,11 +123,6 @@ pub impl Vec2: Vector { #[inline] static pure fn dim() -> uint { 2 } - #[inline] - pure fn index(&&i: uint) -> float { - self.data[i] - } - #[inline] pure fn add_f(&&value:float) -> Vec2 { Vec2(self[0] + value, @@ -222,6 +215,13 @@ pub impl Vec2: Vector { #[inline] static pure fn identity() -> Vec2 { Vec2(1f, 1f) } } +pub impl Vec2: Index { + #[inline] + pure fn index(+i: uint) -> float { + self.data[i] + } +} + pub impl Vec2: Neg { #[inline] pure fn neg() -> Vec2 { @@ -305,11 +305,6 @@ pub impl Vec3: Vector { #[inline] static pure fn dim() -> uint { 3 } - #[inline] - pure fn index(&&i: uint) -> float { - self.data[i] - } - #[inline] pure fn add_f(&&value:float) -> Vec3 { Vec3(self[0] + value, @@ -414,6 +409,13 @@ pub impl Vec3: Vector { #[inline] static pure fn identity() -> Vec3 { Vec3(1f, 1f, 1f) } } +pub impl Vec3: Index { + #[inline] + pure fn index(+i: uint) -> float { + self.data[i] + } +} + pub impl Vec3: Neg { #[inline] pure fn neg() -> Vec3 { @@ -494,11 +496,6 @@ pub impl Vec4: Vector { #[inline] static pure fn dim() -> uint { 4 } - #[inline] - pure fn index(&&i: uint) -> float { - self.data[i] - } - #[inline] pure fn add_f(&&value:float) -> Vec4 { Vec4(self[0] + value, @@ -615,6 +612,13 @@ pub impl Vec4: Vector { #[inline] static pure fn identity() -> Vec4 { Vec4(1f, 1f, 1f, 1f) } } +pub impl Vec4: Index { + #[inline] + pure fn index(+i: uint) -> float { + self.data[i] + } +} + pub impl Vec4: Neg { #[inline] pure fn neg() -> Vec4 {