diff --git a/src/matrix.rs b/src/matrix.rs index ce2a5e7..caddf3d 100644 --- a/src/matrix.rs +++ b/src/matrix.rs @@ -155,6 +155,14 @@ pub impl Mat2: Matrix, Vec2> { Vec2::new(self[0][i], self[1][i]) } + + #[inline(always)] + pure fn index(i: uint) -> Vec2 { + unsafe { do buf_as_slice( + transmute::<*Mat2, *Vec2>( + to_unsafe_ptr(&self)), 2) |slice| { slice[i] } + } + } } pub impl Mat2: NumericMatrix, Vec2> { @@ -259,16 +267,6 @@ pub impl Mat2: Matrix2 { } } -pub impl Mat2: Index> { - #[inline(always)] - pure fn index(i: uint) -> Vec2 { - unsafe { do buf_as_slice( - transmute::<*Mat2, *Vec2>( - to_unsafe_ptr(&self)), 2) |slice| { slice[i] } - } - } -} - // TODO: make work for T:Integer pub impl Mat2: Eq { #[inline(always)] @@ -390,6 +388,14 @@ pub impl Mat3: Matrix, Vec3> { self[1][i], self[2][i]) } + + #[inline(always)] + pure fn index(i: uint) -> Vec3 { + unsafe { do buf_as_slice( + transmute::<*Mat3, *Vec3>( + to_unsafe_ptr(&self)), 3) |slice| { slice[i] } + } + } } pub impl Mat3: NumericMatrix, Vec3> { @@ -552,16 +558,6 @@ pub impl Mat3: ToQuat { } } -pub impl Mat3: Index> { - #[inline(always)] - pure fn index(i: uint) -> Vec3 { - unsafe { do buf_as_slice( - transmute::<*Mat3, *Vec3>( - to_unsafe_ptr(&self)), 3) |slice| { slice[i] } - } - } -} - // TODO: make work for T:Integer pub impl Mat3: Eq { #[inline(always)] @@ -703,7 +699,14 @@ pub impl Mat4: Matrix, Vec4> { self[2][i], self[3][i]) } - + + #[inline(always)] + pure fn index(i: uint) -> Vec4 { + unsafe { do buf_as_slice( + transmute::<*Mat4, *Vec4>( + to_unsafe_ptr(&self)), 4) |slice| { slice[i] } + } + } } pub impl Mat4: NumericMatrix, Vec4> { @@ -896,16 +899,6 @@ pub impl Mat4: Matrix4 { } -pub impl Mat4: Index> { - #[inline(always)] - pure fn index(i: uint) -> Vec4 { - unsafe { do buf_as_slice( - transmute::<*Mat4, *Vec4>( - to_unsafe_ptr(&self)), 4) |slice| { slice[i] } - } - } -} - // TODO: make work for T:Integer pub impl Mat4: Eq { #[inline(always)] diff --git a/src/vector.rs b/src/vector.rs index 18eff52..a644a17 100644 --- a/src/vector.rs +++ b/src/vector.rs @@ -117,9 +117,17 @@ pub mod Vec2 { } } -pub impl Vec2: Vector { +pub impl Vec2: Vector { #[inline(always)] static pure fn dim() -> uint { 2 } + + #[inline(always)] + pure fn index(i: uint) -> T { + unsafe { do buf_as_slice( + transmute::<*Vec2, *T>( + to_unsafe_ptr(&self)), 2) |slice| { slice[i] } + } + } } pub impl Vec2: NumericVector { @@ -184,16 +192,6 @@ pub impl Vec2: GeometricVector { } } -pub impl Vec2: Index { - #[inline(always)] - pure fn index(i: uint) -> T { - unsafe { do buf_as_slice( - transmute::<*Vec2, *T>( - to_unsafe_ptr(&self)), 2) |slice| { slice[i] } - } - } -} - // TODO: make work for T:Integer pub impl Vec2: Eq { #[inline(always)] @@ -295,9 +293,17 @@ pub impl Vec3: Vector3 { } } -pub impl Vec3: Vector { +pub impl Vec3: Vector { #[inline(always)] static pure fn dim() -> uint { 3 } + + #[inline(always)] + pure fn index(i: uint) -> T { + unsafe { do buf_as_slice( + transmute::<*Vec3, *T>( + to_unsafe_ptr(&self)), 3) |slice| { slice[i] } + } + } } pub impl Vec3: NumericVector { @@ -368,16 +374,6 @@ pub impl Vec3: GeometricVector { } } -pub impl Vec3: Index { - #[inline(always)] - pure fn index(i: uint) -> T { - unsafe { do buf_as_slice( - transmute::<*Vec3, *T>( - to_unsafe_ptr(&self)), 3) |slice| { slice[i] } - } - } -} - // TODO: make work for T:Integer pub impl Vec3: Eq { #[inline(always)] @@ -479,9 +475,17 @@ pub mod Vec4 { } } -pub impl Vec4: Vector { +pub impl Vec4: Vector { #[inline(always)] static pure fn dim() -> uint { 4 } + + #[inline(always)] + pure fn index(i: uint) -> T { + unsafe { do buf_as_slice( + transmute::<*Vec4, *T>( + to_unsafe_ptr(&self)), 4) |slice| { slice[i] } + } + } } pub impl Vec4: NumericVector { @@ -558,16 +562,6 @@ pub impl Vec4: GeometricVector { } } -pub impl Vec4: Index { - #[inline(always)] - pure fn index(i: uint) -> T { - unsafe { do buf_as_slice( - transmute::<*Vec4, *T>( - to_unsafe_ptr(&self)), 4) |slice| { slice[i] } - } - } -} - pub impl Vec4: Eq { #[inline(always)] pure fn eq(other: &Vec4) -> bool {