diff --git a/src/matrix.rs b/src/matrix.rs index ac5cab1..04179c8 100644 --- a/src/matrix.rs +++ b/src/matrix.rs @@ -41,17 +41,19 @@ pub type dmat3x3 = Mat3; /// same as a `dmat3` pub type dmat4x4 = Mat4; /// same as a `dmat4` -pub trait Matrix { +pub trait Matrix { pure fn rows() -> uint; pure fn cols() -> uint; pure fn is_col_major() -> bool; pure fn is_square() -> bool; - pure fn col(i: uint) -> ColV; - pure fn row(i: uint) -> RowV; - + pure fn col(i: uint) -> ColVec; + pure fn row(i: uint) -> RowVec; +} + +pub trait NumericMatrix { pure fn mul_t(value: T) -> self; - pure fn mul_v(other: &ColV) -> ColV; + pure fn mul_v(other: &ColVec) -> ColVec; } pub trait SquareMatrix { @@ -68,24 +70,15 @@ pub trait SquareMatrix { pure fn is_rotated() -> bool; } -// -// 2x2 Matrix -// pub trait Matrix2 { pure fn to_Mat3() -> Mat3; pure fn to_Mat4() -> Mat4; } -// -// 3x3 Matrix -// pub trait Matrix3 { pure fn to_Mat4() -> Mat4; } -// -// 4x4 Matrix -// pub trait Matrix4 { } @@ -138,7 +131,7 @@ pub mod Mat2 { } } -pub impl Mat2: Matrix, Vec2> { +pub impl Mat2: Matrix, Vec2> { #[inline(always)] pure fn rows() -> uint { 2 } @@ -159,7 +152,9 @@ pub impl Mat2: Matrix, Vec2> { Vec2::new(self[0][i], self[1][i]) } - +} + +pub impl Mat2: NumericMatrix> { #[inline(always)] pure fn mul_t(value: T) -> Mat2 { Mat2::from_cols(self[0].mul_t(value), @@ -350,7 +345,7 @@ pub mod Mat3 { } } -pub impl Mat3: Matrix, Vec3> { +pub impl Mat3: Matrix, Vec3> { #[inline(always)] pure fn rows() -> uint { 3 } @@ -372,7 +367,9 @@ pub impl Mat3: Matrix, Vec3> { self[1][i], self[2][i]) } - +} + +pub impl Mat3: NumericMatrix> { #[inline(always)] pure fn mul_t(value: T) -> Mat3 { Mat3::from_cols(self[0].mul_t(value), @@ -650,7 +647,7 @@ pub mod Mat4 { } } -pub impl Mat4: Matrix, Vec4> { +pub impl Mat4: Matrix, Vec4> { #[inline(always)] pure fn rows() -> uint { 4 } @@ -673,7 +670,9 @@ pub impl Mat4: Matrix, Vec4> { self[2][i], self[3][i]) } - +} + +pub impl Mat4: NumericMatrix> { #[inline(always)] pure fn mul_t(value: T) -> Mat4 { Mat4::from_cols(self[0].mul_t(value),