diff --git a/src/matrix.rs b/src/matrix.rs index 6bdba62..dc350dc 100644 --- a/src/matrix.rs +++ b/src/matrix.rs @@ -41,7 +41,7 @@ pub type dmat3x3 = Mat3; /// same as a `dmat3` pub type dmat4x4 = Mat4; /// same as a `dmat4` -pub trait Matrix { +pub trait Matrix: Eq, Index, ToPtr { pure fn rows() -> uint; pure fn cols() -> uint; pure fn is_col_major() -> bool; @@ -51,12 +51,12 @@ pub trait Matrix { pure fn row(i: uint) -> RowVec; } -pub trait NumericMatrix { +pub trait NumericMatrix: Matrix { pure fn mul_t(value: T) -> self; pure fn mul_v(other: &ColVec) -> ColVec; } -pub trait NumericMatrix_NxN { +pub trait NumericMatrix_NxN: NumericMatrix { pure fn add_m(other: &self) -> self; pure fn sub_m(other: &self) -> self; pure fn mul_m(other: &self) -> self; @@ -73,16 +73,16 @@ pub trait NumericMatrix_NxN { pure fn is_invertible() -> bool; } -pub trait Matrix2 { +pub trait Matrix2: Matrix, Mat2> { pure fn to_Mat3() -> Mat3; pure fn to_Mat4() -> Mat4; } -pub trait Matrix3 { +pub trait Matrix3: Matrix, Mat3> { pure fn to_Mat4() -> Mat4; } -pub trait Matrix4 { +pub trait Matrix4: Matrix, Mat4> { } @@ -157,7 +157,7 @@ pub impl Mat2: Matrix, Vec2> { } } -pub impl Mat2: NumericMatrix> { +pub impl Mat2: NumericMatrix, Vec2> { #[inline(always)] pure fn mul_t(value: T) -> Mat2 { Mat2::from_cols(self[0].mul_t(value), @@ -171,7 +171,7 @@ pub impl Mat2: NumericMatrix> { } } -pub impl Mat2: NumericMatrix_NxN { +pub impl Mat2: NumericMatrix_NxN> { #[inline(always)] pure fn add_m(other: &Mat2) -> Mat2 { Mat2::from_cols(self[0].add_v(&other[0]), @@ -300,6 +300,13 @@ pub impl Mat2: FuzzyEq { } } +pub impl Mat2: ToPtr { + #[inline(always)] + pure fn to_ptr() -> *T { + self[0].to_ptr() + } +} + @@ -387,7 +394,7 @@ pub impl Mat3: Matrix, Vec3> { } } -pub impl Mat3: NumericMatrix> { +pub impl Mat3: NumericMatrix, Vec3> { #[inline(always)] pure fn mul_t(value: T) -> Mat3 { Mat3::from_cols(self[0].mul_t(value), @@ -403,7 +410,7 @@ pub impl Mat3: NumericMatrix> { } } -pub impl Mat3: NumericMatrix_NxN { +pub impl Mat3: NumericMatrix_NxN> { #[inline(always)] pure fn add_m(other: &Mat3) -> Mat3 { Mat3::from_cols(self[0].add_v(&other[0]), @@ -703,7 +710,7 @@ pub impl Mat4: Matrix, Vec4> { } -pub impl Mat4: NumericMatrix> { +pub impl Mat4: NumericMatrix, Vec4> { #[inline(always)] pure fn mul_t(value: T) -> Mat4 { Mat4::from_cols(self[0].mul_t(value), @@ -721,7 +728,7 @@ pub impl Mat4: NumericMatrix> { } } -pub impl Mat4: NumericMatrix_NxN { +pub impl Mat4: NumericMatrix_NxN> { #[inline(always)] pure fn add_m(other: &Mat4) -> Mat4 { Mat4::from_cols(self[0].add_v(&other[0]), diff --git a/src/quaternion.rs b/src/quaternion.rs index 2836c13..5622dbf 100644 --- a/src/quaternion.rs +++ b/src/quaternion.rs @@ -23,7 +23,7 @@ pub type dquat4 = Quat; /// a double-precision floating-point quate // // Quaternion // -pub trait Quaternion { +pub trait Quaternion: Eq, Index, ToPtr { pure fn dim() -> uint; pure fn mul_t(value: T) -> self; diff --git a/src/vector.rs b/src/vector.rs index 95b3a86..04fb5a6 100644 --- a/src/vector.rs +++ b/src/vector.rs @@ -31,11 +31,11 @@ pub type uvec3 = Vec3; /// a three-component unsigned integer vecto pub type uvec4 = Vec4; /// a four-component unsigned integer vector -pub trait Vector { +pub trait Vector: Eq, Index, ToPtr { static pure fn dim() -> uint; } -pub trait NumericVector { +pub trait NumericVector: Vector { pure fn mul_t(value: T) -> self; pure fn div_t(value: T) -> self; @@ -45,26 +45,26 @@ pub trait NumericVector { pure fn dot(other: &self) -> T; } -pub trait GeometricVector { +pub trait GeometricVector: NumericVector { pure fn length2() -> T; pure fn length() -> T; pure fn normalize() -> self; pure fn lerp(other: &self, amount: T) -> self; } -pub trait Vector2 { +pub trait Vector2: Vector { // static pure fn new(x: T, y: T) -> self; // static pure fn from_value(value: T) -> self; } -pub trait Vector3 { +pub trait Vector3: Vector { // static pure fn new(x: T, y: T, z: T) -> self; // static pure fn from_value(value: T) -> self; pure fn cross(other: &self) -> self; } -pub trait Vector4 { +pub trait Vector4: Vector { // pub static pure fn new(x: T, y: T, z: T, w: T) -> self; // pub static pure fn from_value(value: T) -> self; } @@ -117,7 +117,7 @@ pub mod Vec2 { } } -pub impl Vec2: Vector { +pub impl Vec2: Vector { #[inline(always)] static pure fn dim() -> uint { 2 } } @@ -297,7 +297,7 @@ pub impl Vec3: Vector3 { } } -pub impl Vec3: Vector { +pub impl Vec3: Vector { #[inline(always)] static pure fn dim() -> uint { 3 } } @@ -483,7 +483,7 @@ pub mod Vec4 { } } -pub impl Vec4: Vector { +pub impl Vec4: Vector { #[inline(always)] static pure fn dim() -> uint { 4 } }