diff --git a/src/lib.rs b/src/lib.rs index 341d36cd..0a88cfea 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -84,6 +84,8 @@ Feel free to add your project to this list if you happen to use **nalgebra**! #![warn(missing_docs)] #![feature(macro_rules)] #![feature(globs)] +#![feature(default_type_params)] +#![feature(associated_types)] #![feature(old_orphan_check)] #![doc(html_root_url = "http://nalgebra.org/doc")] @@ -578,7 +580,7 @@ pub fn inv_rotate>(m: &M, v: &V) -> V { /// Rotates a copy of `m` by `amount` using `center` as the pivot point. #[inline(always)] -pub fn append_rotation_wrt_point + Copy, +pub fn append_rotation_wrt_point + Copy, AV, M: RotationWithTranslation>( m: &M, @@ -589,7 +591,7 @@ pub fn append_rotation_wrt_point + Copy, /// Rotates a copy of `m` by `amount` using `m.translation()` as the pivot point. #[inline(always)] -pub fn append_rotation_wrt_center + Copy, +pub fn append_rotation_wrt_center + Copy, AV, M: RotationWithTranslation>( m: &M, @@ -603,7 +605,7 @@ pub fn append_rotation_wrt_center + Copy, /// Builds a rotation matrix from `r`. #[inline(always)] -pub fn to_rot_mat + Rotation, R: RotationMatrix>(r: &R) -> M { +pub fn to_rot_mat>(r: &R) -> R::Output { r.to_rot_mat() } @@ -702,7 +704,7 @@ pub fn det, N>(m: &M) -> N { /// Computes the cross product of two vectors. #[inline(always)] -pub fn cross, AV>(a: &LV, b: &LV) -> AV { +pub fn cross(a: &LV, b: &LV) -> LV::Output { Cross::cross(a, b) } @@ -909,7 +911,7 @@ pub fn dim() -> uint { /// Gets the indexable range of an object. #[inline(always)] -pub fn shape, I, N>(v: &V) -> I { +pub fn shape, I, N>(v: &V) -> I { v.shape() } diff --git a/src/linalg/decompositions.rs b/src/linalg/decompositions.rs index f4b3423e..3b60d436 100644 --- a/src/linalg/decompositions.rs +++ b/src/linalg/decompositions.rs @@ -41,7 +41,8 @@ pub fn householder_matrix(dim: uint, start: uint, vec: V) -> M pub fn qr(m: &M) -> (M, M) where N: BaseFloat, V: Indexable + Norm, - M: Copy + Eye + ColSlice + Transpose + Indexable<(uint, uint), N> + Mul { + M: Copy + Eye + ColSlice + Transpose + Indexable<(uint, uint), N> + + Mul { let (rows, cols) = m.shape(); assert!(rows >= cols); let mut q : M = Eye::new_identity(rows); @@ -76,7 +77,8 @@ pub fn qr(m: &M) -> (M, M) pub fn eigen_qr(m: &M, eps: &N, niter: uint) -> (M, V) where N: BaseFloat, VS: Indexable + Norm, - M: Indexable<(uint, uint), N> + SquareMat + Add + Sub + ColSlice + + M: Indexable<(uint, uint), N> + SquareMat + Add + + Sub + ColSlice + ApproxEq + Copy { let mut eigenvectors: M = ::one::(); let mut eigenvalues = *m; diff --git a/src/structs/dmat.rs b/src/structs/dmat.rs index 4a58c9f6..6649a526 100644 --- a/src/structs/dmat.rs +++ b/src/structs/dmat.rs @@ -255,14 +255,16 @@ impl Indexable<(uint, uint), N> for DMat { } -impl Shape<(uint, uint), N> for DMat { +impl Shape<(uint, uint)> for DMat { #[inline] fn shape(&self) -> (uint, uint) { (self.nrows, self.ncols) } } -impl Index<(uint, uint), N> for DMat { +impl Index<(uint, uint)> for DMat { + type Output = N; + fn index(&self, &(i, j): &(uint, uint)) -> &N { assert!(i < self.nrows); assert!(j < self.ncols); @@ -273,7 +275,9 @@ impl Index<(uint, uint), N> for DMat { } } -impl IndexMut<(uint, uint), N> for DMat { +impl IndexMut<(uint, uint)> for DMat { + type Output = N; + fn index_mut(&mut self, &(i, j): &(uint, uint)) -> &mut N { assert!(i < self.nrows); assert!(j < self.ncols); @@ -286,7 +290,9 @@ impl IndexMut<(uint, uint), N> for DMat { } } -impl + Add + Zero> Mul, DMat> for DMat { +impl + Add + Zero> Mul> for DMat { + type Output = DMat; + fn mul(self, right: DMat) -> DMat { assert!(self.ncols == right.nrows); @@ -311,7 +317,9 @@ impl + Add + Zero> Mul, DMat> for DMat { } } -impl + Mul + Zero> Mul, DVec> for DMat { +impl + Mul + Zero> Mul> for DMat { + type Output = DVec; + fn mul(self, right: DVec) -> DVec { assert!(self.ncols == right.at.len()); @@ -334,7 +342,9 @@ impl + Mul + Zero> Mul, DVec> for DMat { } -impl + Mul + Zero> Mul, DVec> for DVec { +impl + Mul + Zero> Mul> for DVec { + type Output = DVec; + fn mul(self, right: DMat) -> DVec { assert!(right.nrows == self.at.len()); @@ -635,7 +645,9 @@ impl Show for DMat { } } -impl> Mul> for DMat { +impl> Mul for DMat { + type Output = DMat; + #[inline] fn mul(self, right: N) -> DMat { let mut res = self; @@ -648,7 +660,9 @@ impl> Mul> for DMat { } } -impl> Div> for DMat { +impl> Div for DMat { + type Output = DMat; + #[inline] fn div(self, right: N) -> DMat { let mut res = self; @@ -661,7 +675,9 @@ impl> Div> for DMat { } } -impl> Add> for DMat { +impl> Add for DMat { + type Output = DMat; + #[inline] fn add(self, right: N) -> DMat { let mut res = self; @@ -674,7 +690,9 @@ impl> Add> for DMat { } } -impl> Sub> for DMat { +impl> Sub for DMat { + type Output = DMat; + #[inline] fn sub(self, right: N) -> DMat { let mut res = self; diff --git a/src/structs/dvec.rs b/src/structs/dvec.rs index 729cc81b..1c54c026 100644 --- a/src/structs/dvec.rs +++ b/src/structs/dvec.rs @@ -67,7 +67,7 @@ impl DVec { impl FromIterator for DVec { #[inline] - fn from_iter>(mut param: I) -> DVec { + fn from_iter>(mut param: I) -> DVec { let mut res = DVec { at: Vec::new() }; for e in param { diff --git a/src/structs/dvec_macros.rs b/src/structs/dvec_macros.rs index 67eb5353..ebdac68f 100644 --- a/src/structs/dvec_macros.rs +++ b/src/structs/dvec_macros.rs @@ -34,7 +34,7 @@ macro_rules! dvec_impl( } } - impl Shape for $dvec { + impl Shape for $dvec { #[inline] fn shape(&self) -> uint { self.len() @@ -77,13 +77,17 @@ macro_rules! dvec_impl( } - impl Index for $dvec { + impl Index for $dvec { + type Output = N; + fn index(&self, i: &uint) -> &N { &self.as_slice()[*i] } } - impl IndexMut for $dvec { + impl IndexMut for $dvec { + type Output = N; + fn index_mut(&mut self, i: &uint) -> &mut N { &mut self.as_mut_slice()[*i] } @@ -122,7 +126,7 @@ macro_rules! dvec_impl( } } - impl + Mul> Axpy for $dvec { + impl + Mul> Axpy for $dvec { fn axpy(&mut self, a: &N, x: &$dvec) { assert!(self.len() == x.len()); @@ -190,7 +194,9 @@ macro_rules! dvec_impl( } } - impl + Zero> Mul<$dvec, $dvec> for $dvec { + impl + Zero> Mul<$dvec> for $dvec { + type Output = $dvec; + #[inline] fn mul(self, right: $dvec) -> $dvec { assert!(self.len() == right.len()); @@ -205,7 +211,9 @@ macro_rules! dvec_impl( } } - impl + Zero> Div<$dvec, $dvec> for $dvec { + impl + Zero> Div<$dvec> for $dvec { + type Output = $dvec; + #[inline] fn div(self, right: $dvec) -> $dvec { assert!(self.len() == right.len()); @@ -220,7 +228,9 @@ macro_rules! dvec_impl( } } - impl + Zero> Add<$dvec, $dvec> for $dvec { + impl + Zero> Add<$dvec> for $dvec { + type Output = $dvec; + #[inline] fn add(self, right: $dvec) -> $dvec { assert!(self.len() == right.len()); @@ -235,7 +245,9 @@ macro_rules! dvec_impl( } } - impl + Zero> Sub<$dvec, $dvec> for $dvec { + impl + Zero> Sub<$dvec> for $dvec { + type Output = $dvec; + #[inline] fn sub(self, right: $dvec) -> $dvec { assert!(self.len() == right.len()); @@ -250,7 +262,9 @@ macro_rules! dvec_impl( } } - impl + Zero + Copy> Neg<$dvec> for $dvec { + impl + Zero + Copy> Neg for $dvec { + type Output = $dvec; + #[inline] fn neg(self) -> $dvec { FromIterator::from_iter(self.as_slice().iter().map(|a| -*a)) @@ -318,7 +332,9 @@ macro_rules! dvec_impl( } } - impl + Zero> Mul> for $dvec { + impl + Zero> Mul for $dvec { + type Output = $dvec; + #[inline] fn mul(self, right: N) -> $dvec { let mut res = self; @@ -331,7 +347,9 @@ macro_rules! dvec_impl( } } - impl + Zero> Div> for $dvec { + impl + Zero> Div for $dvec { + type Output = $dvec; + #[inline] fn div(self, right: N) -> $dvec { let mut res = self; @@ -344,7 +362,9 @@ macro_rules! dvec_impl( } } - impl + Zero> Add> for $dvec { + impl + Zero> Add for $dvec { + type Output = $dvec; + #[inline] fn add(self, right: N) -> $dvec { let mut res = self; @@ -357,7 +377,9 @@ macro_rules! dvec_impl( } } - impl + Zero> Sub> for $dvec { + impl + Zero> Sub for $dvec { + type Output = $dvec; + #[inline] fn sub(self, right: N) -> $dvec { let mut res = self; @@ -477,7 +499,7 @@ macro_rules! small_dvec_from_impl ( impl FromIterator for $dvec { #[inline] - fn from_iter>(mut param: I) -> $dvec { + fn from_iter>(mut param: I) -> $dvec { let mut at: [N; $dim] = [ $( $zeros, )* ]; let mut dim = 0; diff --git a/src/structs/iso_macros.rs b/src/structs/iso_macros.rs index 4850e23e..b68343b9 100644 --- a/src/structs/iso_macros.rs +++ b/src/structs/iso_macros.rs @@ -27,7 +27,9 @@ macro_rules! iso_impl( macro_rules! rotation_matrix_impl( ($t: ident, $trot: ident, $tlv: ident, $tav: ident) => ( impl + BaseFloat> - RotationMatrix, $tav, $trot> for $t { + RotationMatrix, $tav> for $t { + type Output = $trot; + #[inline] fn to_rot_mat(&self) -> $trot { self.rotation @@ -61,7 +63,9 @@ macro_rules! one_impl( macro_rules! iso_mul_iso_impl( ($t: ident) => ( - impl Mul<$t, $t> for $t { + impl Mul<$t> for $t { + type Output = $t; + #[inline] fn mul(self, right: $t) -> $t { $t::new_with_rotmat( @@ -74,7 +78,9 @@ macro_rules! iso_mul_iso_impl( macro_rules! iso_mul_pnt_impl( ($t: ident, $tv: ident) => ( - impl Mul<$tv, $tv> for $t { + impl Mul<$tv> for $t { + type Output = $tv; + #[inline] fn mul(self, right: $tv) -> $tv { self.rotation * right + self.translation @@ -85,7 +91,8 @@ macro_rules! iso_mul_pnt_impl( macro_rules! pnt_mul_iso_impl( ($t: ident, $tv: ident) => ( - impl Mul<$t, $tv> for $tv { + impl Mul<$t> for $tv { + type Output = $tv; #[inline] fn mul(self, right: $t) -> $tv { (self + right.translation) * right.rotation @@ -137,7 +144,7 @@ macro_rules! translation_impl( macro_rules! translate_impl( ($t: ident, $tv: ident) => ( - impl + Sub> Translate<$tv> for $t { + impl + Sub> Translate<$tv> for $t { #[inline] fn translate(&self, v: &$tv) -> $tv { *v + self.translation diff --git a/src/structs/mat_macros.rs b/src/structs/mat_macros.rs index 5100f48a..c3726c1a 100644 --- a/src/structs/mat_macros.rs +++ b/src/structs/mat_macros.rs @@ -88,7 +88,9 @@ macro_rules! mat_cast_impl( macro_rules! add_impl( ($t: ident, $comp0: ident $(,$compN: ident)*) => ( - impl> Add<$t, $t> for $t { + impl> Add<$t> for $t { + type Output = $t; + #[inline] fn add(self, right: $t) -> $t { $t::new(self.$comp0 + right.$comp0 $(, self.$compN + right.$compN)*) @@ -99,7 +101,9 @@ macro_rules! add_impl( macro_rules! sub_impl( ($t: ident, $comp0: ident $(,$compN: ident)*) => ( - impl> Sub<$t, $t> for $t { + impl> Sub<$t> for $t { + type Output = $t; + #[inline] fn sub(self, right: $t) -> $t { $t::new(self.$comp0 - right.$comp0 $(, self.$compN - right.$compN)*) @@ -110,7 +114,9 @@ macro_rules! sub_impl( macro_rules! mat_mul_scalar_impl( ($t: ident, $comp0: ident $(,$compN: ident)*) => ( - impl> Mul> for N { + impl> Mul for N { + type Output = $t; + #[inline] fn mul(self, right: N) -> $t { $t::new(self.$comp0 * *right $(, self.$compN * *right)*) @@ -121,7 +127,9 @@ macro_rules! mat_mul_scalar_impl( macro_rules! mat_div_scalar_impl( ($t: ident, $comp0: ident $(,$compN: ident)*) => ( - impl> Div> for $t { + impl> Div for $t { + type Output = $t; + #[inline] fn div(self, right: N) -> $t { $t::new(self.$comp0 / *right $(, self.$compN / *right)*) @@ -132,7 +140,9 @@ macro_rules! mat_div_scalar_impl( macro_rules! mat_add_scalar_impl( ($t: ident, $comp0: ident $(,$compN: ident)*) => ( - impl> Add> for $t { + impl> Add for $t { + type Output = $t; + #[inline] fn add(self, right: N) -> $t { $t::new(self.$comp0 + *right $(, self.$compN + *right)*) @@ -157,7 +167,9 @@ macro_rules! eye_impl( macro_rules! mat_sub_scalar_impl( ($t: ident, $comp0: ident $(,$compN: ident)*) => ( - impl Sub> for $t { + impl Sub for $t { + type Output = $t; + #[inline] fn sub(self, right: &N) -> $t { $t::new(self.$comp0 - *right $(, self.$compN - *right)*) @@ -246,7 +258,7 @@ macro_rules! dim_impl( macro_rules! indexable_impl( ($t: ident, $dim: expr) => ( - impl Shape<(uint, uint), N> for $t { + impl Shape<(uint, uint)> for $t { #[inline] fn shape(&self) -> (uint, uint) { ($dim, $dim) @@ -291,7 +303,9 @@ macro_rules! indexable_impl( macro_rules! index_impl( ($t: ident, $dim: expr) => ( - impl Index<(uint, uint), N> for $t { + impl Index<(uint, uint)> for $t { + type Output = N; + fn index(&self, &(i, j): &(uint, uint)) -> &N { unsafe { &mem::transmute::<&$t, &mut [N; $dim * $dim]>(self)[i + j * $dim] @@ -299,7 +313,9 @@ macro_rules! index_impl( } } - impl IndexMut<(uint, uint), N> for $t { + impl IndexMut<(uint, uint)> for $t { + type Output = N; + fn index_mut(&mut self, &(i, j): &(uint, uint)) -> &mut N { unsafe { &mut mem::transmute::<&mut $t, &mut [N; $dim * $dim]>(self)[i + j * $dim] @@ -426,7 +442,8 @@ macro_rules! diag_impl( macro_rules! mat_mul_mat_impl( ($t: ident, $dim: expr) => ( - impl Mul<$t, $t> for $t { + impl Mul<$t> for $t { + type Output = $t; #[inline] fn mul(self, right: $t) -> $t { // careful! we need to comute other * self here (self is the rhs). @@ -454,7 +471,9 @@ macro_rules! mat_mul_mat_impl( macro_rules! vec_mul_mat_impl( ($t: ident, $v: ident, $dim: expr, $zero: expr) => ( - impl Mul<$t, $v> for $v { + impl Mul<$t> for $v { + type Output = $v; + #[inline] fn mul(self, right: $t) -> $v { let mut res : $v = $zero(); @@ -476,7 +495,9 @@ macro_rules! vec_mul_mat_impl( macro_rules! mat_mul_vec_impl( ($t: ident, $v: ident, $dim: expr, $zero: expr) => ( - impl Mul<$v, $v> for $t { + impl Mul<$v> for $t { + type Output = $v; + #[inline] fn mul(self, right: $v) -> $v { let mut res : $v = $zero(); @@ -685,7 +706,7 @@ macro_rules! from_homogeneous_impl( macro_rules! outer_impl( ($t: ident, $m: ident) => ( - impl + Zero> Outer<$m> for $t { + impl + Zero> Outer<$m> for $t { #[inline] fn outer(&self, other: &$t) -> $m { let mut res: $m = ::zero(); diff --git a/src/structs/pnt_macros.rs b/src/structs/pnt_macros.rs index 5ac383d4..b09f8fa9 100644 --- a/src/structs/pnt_macros.rs +++ b/src/structs/pnt_macros.rs @@ -21,7 +21,9 @@ macro_rules! orig_impl( macro_rules! pnt_sub_impl( ($t: ident, $tv: ident) => ( - impl> Sub<$t, $tv> for $t { + impl> Sub<$t> for $t { + type Output = $tv; + #[inline] fn sub(self, right: $t) -> $tv { *self.as_vec() - *right.as_vec() @@ -32,7 +34,9 @@ macro_rules! pnt_sub_impl( macro_rules! pnt_add_vec_impl( ($t: ident, $tv: ident, $comp0: ident $(,$compN: ident)*) => ( - impl> Add<$tv, $t> for $t { + impl> Add<$tv> for $t { + type Output = $t; + #[inline] fn add(self, right: $tv) -> $t { $t::new(self.$comp0 + right.$comp0 $(, self.$compN + right.$compN)*) @@ -43,7 +47,9 @@ macro_rules! pnt_add_vec_impl( macro_rules! pnt_sub_vec_impl( ($t: ident, $tv: ident, $comp0: ident $(,$compN: ident)*) => ( - impl> Sub<$tv, $t> for $t { + impl> Sub<$tv> for $t { + type Output = $t; + #[inline] fn sub(self, right: $tv) -> $t { $t::new(self.$comp0 - right.$comp0 $(, self.$compN - right.$compN)*) @@ -116,7 +122,7 @@ macro_rules! pnt_to_homogeneous_impl( macro_rules! pnt_from_homogeneous_impl( ($t: ident, $t2: ident, $extra: ident, $comp0: ident $(,$compN: ident)*) => ( - impl + One + Zero> FromHomogeneous<$t2> for $t { + impl + One + Zero> FromHomogeneous<$t2> for $t { fn from(v: &$t2) -> $t { let mut res: $t = Orig::orig(); diff --git a/src/structs/quat.rs b/src/structs/quat.rs index 8c926d5d..17a5090e 100644 --- a/src/structs/quat.rs +++ b/src/structs/quat.rs @@ -56,7 +56,7 @@ impl Quat { } } -impl + Copy> Quat { +impl + Copy> Quat { /// Replaces this quaternion by its conjugate. #[inline] pub fn conjugate(&mut self) { @@ -123,7 +123,10 @@ impl Norm for Quat { } } -impl + Sub + Add> Mul, Quat> for Quat { +impl Mul> for Quat + where N: Copy + Mul + Sub + Add { + type Output = Quat; + #[inline] fn mul(self, right: Quat) -> Quat { Quat::new( @@ -134,7 +137,9 @@ impl + Sub + Add> Mul, Quat> for Quat } } -impl + BaseFloat> Div, Quat> for Quat { +impl + BaseFloat> Div> for Quat { + type Output = Quat; + #[inline] fn div(self, right: Quat) -> Quat { self * right.inv_cpy().expect("Unable to invert the denominator.") @@ -261,7 +266,7 @@ impl One for UnitQuat { } } -impl> Inv for UnitQuat { +impl> Inv for UnitQuat { #[inline] fn inv_cpy(&self) -> Option> { let mut cpy = *self; @@ -307,21 +312,27 @@ impl> ApproxEq for UnitQuat { } } -impl> Div, UnitQuat> for UnitQuat { +impl> Div> for UnitQuat { + type Output = UnitQuat; + #[inline] fn div(self, other: UnitQuat) -> UnitQuat { UnitQuat { q: self.q / other.q } } } -impl Mul, UnitQuat> for UnitQuat { +impl Mul> for UnitQuat { + type Output = UnitQuat; + #[inline] fn mul(self, right: UnitQuat) -> UnitQuat { UnitQuat { q: self.q * right.q } } } -impl Mul, Vec3> for UnitQuat { +impl Mul> for UnitQuat { + type Output = Vec3; + #[inline] fn mul(self, right: Vec3) -> Vec3 { let _2: N = ::one::() + ::one(); @@ -334,14 +345,18 @@ impl Mul, Vec3> for UnitQuat { } } -impl Mul, Pnt3> for UnitQuat { +impl Mul> for UnitQuat { + type Output = Pnt3; + #[inline] fn mul(self, right: Pnt3) -> Pnt3 { ::orig::>() + self * *right.as_vec() } } -impl Mul, Vec3> for Vec3 { +impl Mul> for Vec3 { + type Output = Vec3; + #[inline] fn mul(self, right: UnitQuat) -> Vec3 { let mut inv_quat = right; @@ -352,7 +367,9 @@ impl Mul, Vec3> for Vec3 { } } -impl Mul, Pnt3> for Pnt3 { +impl Mul> for Pnt3 { + type Output = Pnt3; + #[inline] fn mul(self, right: UnitQuat) -> Pnt3 { ::orig::>() + *self.as_vec() * right diff --git a/src/structs/rot.rs b/src/structs/rot.rs index 58aae541..7c507e2a 100644 --- a/src/structs/rot.rs +++ b/src/structs/rot.rs @@ -19,7 +19,7 @@ pub struct Rot2 { submat: Mat2 } -impl + Copy> Rot2 { +impl + Copy> Rot2 { /// Builds a 2 dimensional rotation matrix from an angle in radian. pub fn new(angle: Vec1) -> Rot2 { let (sia, coa) = angle.x.sin_cos(); @@ -67,7 +67,7 @@ impl Rotation> for Rot2 { } } -impl + Copy> Rand for Rot2 { +impl Rand for Rot2 { #[inline] fn rand(rng: &mut R) -> Rot2 { Rot2::new(rng.gen()) diff --git a/src/structs/rot_macros.rs b/src/structs/rot_macros.rs index 8deaf8b0..975b4882 100644 --- a/src/structs/rot_macros.rs +++ b/src/structs/rot_macros.rs @@ -80,7 +80,9 @@ macro_rules! dim_impl( macro_rules! rotation_matrix_impl( ($t: ident, $tlv: ident, $tav: ident) => ( - impl + BaseFloat> RotationMatrix, $tav, $t> for $t { + impl + BaseFloat> RotationMatrix, $tav> for $t { + type Output = $t; + #[inline] fn to_rot_mat(&self) -> $t { self.clone() @@ -102,7 +104,9 @@ macro_rules! one_impl( macro_rules! rot_mul_rot_impl( ($t: ident) => ( - impl Mul<$t, $t> for $t { + impl Mul<$t> for $t { + type Output = $t; + #[inline] fn mul(self, right: $t) -> $t { $t { submat: self.submat * right.submat } @@ -113,7 +117,9 @@ macro_rules! rot_mul_rot_impl( macro_rules! rot_mul_vec_impl( ($t: ident, $tv: ident) => ( - impl Mul<$tv, $tv> for $t { + impl Mul<$tv> for $t { + type Output = $tv; + #[inline] fn mul(self, right: $tv) -> $tv { self.submat * right @@ -130,7 +136,9 @@ macro_rules! rot_mul_pnt_impl( macro_rules! vec_mul_rot_impl( ($t: ident, $tv: ident) => ( - impl Mul<$t, $tv> for $tv { + impl Mul<$t> for $tv { + type Output = $tv; + #[inline] fn mul(self, right: $t) -> $tv { self * right.submat @@ -223,7 +231,9 @@ macro_rules! col_impl( macro_rules! index_impl( ($t: ident) => ( - impl Index<(uint, uint), N> for $t { + impl Index<(uint, uint)> for $t { + type Output = N; + fn index(&self, i: &(uint, uint)) -> &N { &self.submat[*i] } diff --git a/src/structs/spec/identity.rs b/src/structs/spec/identity.rs index 06890960..e0dc9498 100644 --- a/src/structs/spec/identity.rs +++ b/src/structs/spec/identity.rs @@ -22,7 +22,9 @@ impl Inv for mat::Identity { } } -impl Mul for mat::Identity { +impl Mul for mat::Identity { + type Output = T; + #[inline] fn mul(self, other: T) -> T { other diff --git a/src/structs/spec/mat.rs b/src/structs/spec/mat.rs index e45ad6c8..96635906 100644 --- a/src/structs/spec/mat.rs +++ b/src/structs/spec/mat.rs @@ -210,7 +210,9 @@ impl Col> for Mat3 { } } -impl + Add> Mul, Mat3> for Mat3 { +impl + Add> Mul> for Mat3 { + type Output = Mat3; + #[inline] fn mul(self, right: Mat3) -> Mat3 { Mat3::new( @@ -229,7 +231,9 @@ impl + Add> Mul, Mat3> for Mat3 { } } -impl + Add> Mul, Mat2> for Mat2 { +impl + Add> Mul> for Mat2 { + type Output = Mat2; + #[inline(always)] fn mul(self, right: Mat2) -> Mat2 { Mat2::new( @@ -242,7 +246,9 @@ impl + Add> Mul, Mat2> for Mat2 { } } -impl + Add> Mul, Vec3> for Mat3 { +impl + Add> Mul> for Mat3 { + type Output = Vec3; + #[inline(always)] fn mul(self, right: Vec3) -> Vec3 { Vec3::new( @@ -253,7 +259,9 @@ impl + Add> Mul, Vec3> for Mat3 { } } -impl + Add> Mul, Vec3> for Vec3 { +impl + Add> Mul> for Vec3 { + type Output = Vec3; + #[inline(always)] fn mul(self, right: Mat3) -> Vec3 { Vec3::new( @@ -264,7 +272,9 @@ impl + Add> Mul, Vec3> for Vec3 { } } -impl + Add> Mul, Vec2> for Vec2 { +impl + Add> Mul> for Vec2 { + type Output = Vec2; + #[inline(always)] fn mul(self, right: Mat2) -> Vec2 { Vec2::new( @@ -274,7 +284,9 @@ impl + Add> Mul, Vec2> for Vec2 { } } -impl + Add> Mul, Vec2> for Mat2 { +impl + Add> Mul> for Mat2 { + type Output = Vec2; + #[inline(always)] fn mul(self, right: Vec2) -> Vec2 { Vec2::new( @@ -284,7 +296,9 @@ impl + Add> Mul, Vec2> for Mat2 { } } -impl + Add> Mul, Pnt3> for Mat3 { +impl + Add> Mul> for Mat3 { + type Output = Pnt3; + #[inline(always)] fn mul(self, right: Pnt3) -> Pnt3 { Pnt3::new( @@ -295,7 +309,9 @@ impl + Add> Mul, Pnt3> for Mat3 { } } -impl + Add> Mul, Pnt3> for Pnt3 { +impl + Add> Mul> for Pnt3 { + type Output = Pnt3; + #[inline(always)] fn mul(self, right: Mat3) -> Pnt3 { Pnt3::new( @@ -306,7 +322,9 @@ impl + Add> Mul, Pnt3> for Pnt3 { } } -impl + Add> Mul, Pnt2> for Pnt2 { +impl + Add> Mul> for Pnt2 { + type Output = Pnt2; + #[inline(always)] fn mul(self, right: Mat2) -> Pnt2 { Pnt2::new( @@ -316,7 +334,9 @@ impl + Add> Mul, Pnt2> for Pnt2 { } } -impl + Add> Mul, Pnt2> for Mat2 { +impl + Add> Mul> for Mat2 { + type Output = Pnt2; + #[inline(always)] fn mul(self, right: Pnt2) -> Pnt2 { Pnt2::new( diff --git a/src/structs/spec/vec.rs b/src/structs/spec/vec.rs index 34517851..41c775aa 100644 --- a/src/structs/spec/vec.rs +++ b/src/structs/spec/vec.rs @@ -4,7 +4,9 @@ use traits::geometry::{Norm, Cross, CrossMatrix, UniformSphereSample}; use structs::vec::{Vec1, Vec2, Vec3, Vec4}; use structs::mat::Mat3; -impl + Sub> Cross> for Vec2 { +impl + Sub> Cross for Vec2 { + type Output = Vec1; + #[inline] fn cross(&self, other: &Vec2) -> Vec1 { Vec1::new(self.x * other.y - self.y * other.x) @@ -12,14 +14,16 @@ impl + Sub> Cross> for Vec2 { } // FIXME: instead of returning a Vec2, define a Mat2x1 matrix? -impl + Copy> CrossMatrix> for Vec2 { +impl + Copy> CrossMatrix> for Vec2 { #[inline] fn cross_matrix(&self) -> Vec2 { Vec2::new(-self.y, self.x) } } -impl + Sub> Cross> for Vec3 { +impl + Sub> Cross for Vec3 { + type Output = Vec3; + #[inline] fn cross(&self, other: &Vec3) -> Vec3 { Vec3::new( @@ -30,7 +34,7 @@ impl + Sub> Cross> for Vec3 { } } -impl + Zero + Copy> CrossMatrix> for Vec3 { +impl + Zero + Copy> CrossMatrix> for Vec3 { #[inline] fn cross_matrix(&self) -> Mat3 { Mat3::new( @@ -88,7 +92,7 @@ impl Basis for Vec1 { } } -impl> Basis for Vec2 { +impl> Basis for Vec2 { #[inline(always)] fn canonical_basis(f: |Vec2| -> bool) { if !f(Vec2::new(::one(), ::zero())) { return }; diff --git a/src/structs/spec/vec0.rs b/src/structs/spec/vec0.rs index bec5d088..dc291af0 100644 --- a/src/structs/spec/vec0.rs +++ b/src/structs/spec/vec0.rs @@ -20,21 +20,25 @@ impl Zero for vec::Vec0 { } } -impl Index for vec::Vec0 { +impl Index for vec::Vec0 { + type Output = N; + #[inline] fn index(&self, _: &uint) -> &N { panic!("Canot index a Vec0.") } } -impl IndexMut for vec::Vec0 { +impl IndexMut for vec::Vec0 { + type Output = N; + #[inline] fn index_mut(&mut self, _: &uint) -> &mut N { panic!("Canot index a Vec0.") } } -impl Shape for vec::Vec0 { +impl Shape for vec::Vec0 { #[inline] fn shape(&self) -> uint { 0 @@ -99,21 +103,27 @@ impl Basis for vec::Vec0 { } } -impl Add> for vec::Vec0 { +impl Add for vec::Vec0 { + type Output = vec::Vec0; + #[inline] fn add(self, _: T) -> vec::Vec0 { vec::Vec0 } } -impl Sub> for vec::Vec0 { +impl Sub for vec::Vec0 { + type Output = vec::Vec0; + #[inline] fn sub(self, _: T) -> vec::Vec0 { vec::Vec0 } } -impl + Copy> Neg> for vec::Vec0 { +impl + Copy> Neg for vec::Vec0 { + type Output = vec::Vec0; + #[inline] fn neg(self) -> vec::Vec0 { vec::Vec0 @@ -127,21 +137,25 @@ impl Dot for vec::Vec0 { } } -impl Mul> for vec::Vec0 { +impl Mul for vec::Vec0 { + type Output = vec::Vec0; + #[inline] fn mul(self, _: T) -> vec::Vec0 { vec::Vec0 } } -impl Div> for vec::Vec0 { +impl Div for vec::Vec0 { + type Output = vec::Vec0; + #[inline] fn div(self, _: T) -> vec::Vec0 { vec::Vec0 } } -impl + Neg> Translation> for vec::Vec0 { +impl + Neg> Translation> for vec::Vec0 { #[inline] fn translation(&self) -> vec::Vec0 { *self @@ -229,7 +243,7 @@ impl One for vec::Vec0 { impl FromIterator for vec::Vec0 { #[inline] - fn from_iter>(_: I) -> vec::Vec0 { + fn from_iter>(_: I) -> vec::Vec0 { vec::Vec0 } } diff --git a/src/structs/vec_macros.rs b/src/structs/vec_macros.rs index 0d84234e..910c4e2a 100644 --- a/src/structs/vec_macros.rs +++ b/src/structs/vec_macros.rs @@ -192,7 +192,7 @@ macro_rules! vec_cast_impl( macro_rules! indexable_impl( ($t: ident, $dim: expr) => ( - impl Shape for $t { + impl Shape for $t { #[inline] fn shape(&self) -> uint { $dim @@ -236,13 +236,17 @@ macro_rules! indexable_impl( macro_rules! index_impl( ($t: ident) => ( - impl Index for $t { + impl Index for $t { + type Output = N; + fn index(&self, i: &uint) -> &N { &self.as_array()[*i] } } - impl IndexMut for $t { + impl IndexMut for $t { + type Output = N; + fn index_mut(&mut self, i: &uint) -> &mut N { &mut self.as_array_mut()[*i] } @@ -391,7 +395,9 @@ macro_rules! axpy_impl( macro_rules! add_impl( ($t: ident, $comp0: ident $(,$compN: ident)*) => ( - impl> Add<$t, $t> for $t { + impl> Add<$t> for $t { + type Output = $t; + #[inline] fn add(self, right: $t) -> $t { $t::new(self.$comp0 + right.$comp0 $(, self.$compN + right.$compN)*) @@ -403,7 +409,9 @@ macro_rules! add_impl( macro_rules! scalar_add_impl( ($t: ident, $comp0: ident $(,$compN: ident)*) => ( // $t against scalar - impl> Add> for $t { + impl> Add for $t { + type Output = $t; + #[inline] fn add(self, right: N) -> $t { $t::new(self.$comp0 + right $(, self.$compN + right)*) @@ -414,7 +422,9 @@ macro_rules! scalar_add_impl( macro_rules! sub_impl( ($t: ident, $comp0: ident $(,$compN: ident)*) => ( - impl> Sub<$t, $t> for $t { + impl> Sub<$t> for $t { + type Output = $t; + #[inline] fn sub(self, right: $t) -> $t { $t::new(self.$comp0 - right.$comp0 $(, self.$compN - right.$compN)*) @@ -425,7 +435,9 @@ macro_rules! sub_impl( macro_rules! scalar_sub_impl( ($t: ident, $comp0: ident $(,$compN: ident)*) => ( - impl> Sub> for $t { + impl> Sub for $t { + type Output = $t; + #[inline] fn sub(self, right: N) -> $t { $t::new(self.$comp0 - right $(, self.$compN - right)*) @@ -436,7 +448,8 @@ macro_rules! scalar_sub_impl( macro_rules! mul_impl( ($t: ident, $comp0: ident $(,$compN: ident)*) => ( - impl> Mul<$t, $t> for $t { + impl> Mul<$t> for $t { + type Output = $t; #[inline] fn mul(self, right: $t) -> $t { $t::new(self.$comp0 * right.$comp0 $(, self.$compN * right.$compN)*) @@ -447,7 +460,9 @@ macro_rules! mul_impl( macro_rules! scalar_mul_impl( ($t: ident, $comp0: ident $(,$compN: ident)*) => ( - impl> Mul> for $t { + impl> Mul for $t { + type Output = $t; + #[inline] fn mul(self, right: N) -> $t { $t::new(self.$comp0 * right $(, self.$compN * right)*) @@ -458,7 +473,9 @@ macro_rules! scalar_mul_impl( macro_rules! div_impl( ($t: ident, $comp0: ident $(,$compN: ident)*) => ( - impl> Div<$t, $t> for $t { + impl> Div<$t> for $t { + type Output = $t; + #[inline] fn div(self, right: $t) -> $t { $t::new(self.$comp0 / right.$comp0 $(, self.$compN / right.$compN)*) @@ -469,7 +486,9 @@ macro_rules! div_impl( macro_rules! scalar_div_impl( ($t: ident, $comp0: ident $(,$compN: ident)*) => ( - impl> Div> for $t { + impl> Div for $t { + type Output = $t; + #[inline] fn div(self, right: N) -> $t { $t::new(self.$comp0 / right $(, self.$compN / right)*) @@ -480,7 +499,9 @@ macro_rules! scalar_div_impl( macro_rules! neg_impl( ($t: ident, $comp0: ident $(,$compN: ident)*) => ( - impl + Copy> Neg<$t> for $t { + impl + Copy> Neg for $t { + type Output = $t; + #[inline] fn neg(self) -> $t { $t::new(-self.$comp0 $(, -self.$compN )*) @@ -502,28 +523,28 @@ macro_rules! dot_impl( macro_rules! scalar_ops_impl( ($t: ident, $comp0: ident $(,$compN: ident)*) => ( - impl> ScalarMul for $t { + impl> ScalarMul for $t { #[inline] fn mul_s(&self, other: &N) -> $t { $t::new(self.$comp0 * *other $(, self.$compN * *other)*) } } - impl> ScalarDiv for $t { + impl> ScalarDiv for $t { #[inline] fn div_s(&self, other: &N) -> $t { $t::new(self.$comp0 / *other $(, self.$compN / *other)*) } } - impl> ScalarAdd for $t { + impl> ScalarAdd for $t { #[inline] fn add_s(&self, other: &N) -> $t { $t::new(self.$comp0 + *other $(, self.$compN + *other)*) } } - impl> ScalarSub for $t { + impl> ScalarSub for $t { #[inline] fn sub_s(&self, other: &N) -> $t { $t::new(self.$comp0 - *other $(, self.$compN - *other)*) @@ -534,7 +555,7 @@ macro_rules! scalar_ops_impl( macro_rules! translation_impl( ($t: ident) => ( - impl + Neg> Translation<$t> for $t { + impl + Neg> Translation<$t> for $t { #[inline] fn translation(&self) -> $t { *self @@ -669,7 +690,7 @@ macro_rules! from_iterator_impl( ($t: ident, $param0: ident $(, $paramN: ident)*) => ( impl FromIterator for $t { #[inline] - fn from_iter>(mut $param0: I) -> $t { + fn from_iter>(mut $param0: I) -> $t { $t::new($param0.next().unwrap() $(, $paramN.next().unwrap())*) } } @@ -715,7 +736,7 @@ macro_rules! vec_to_homogeneous_impl( macro_rules! vec_from_homogeneous_impl( ($t: ident, $t2: ident, $extra: ident, $comp0: ident $(,$compN: ident)*) => ( - impl + One + Zero> FromHomogeneous<$t2> for $t { + impl + One + Zero> FromHomogeneous<$t2> for $t { fn from(v: &$t2) -> $t { let mut res: $t = ::zero(); @@ -730,7 +751,7 @@ macro_rules! vec_from_homogeneous_impl( macro_rules! translate_impl( ($tv: ident, $t: ident) => ( - impl + Sub> Translate<$t> for $tv { + impl + Sub> Translate<$t> for $tv { fn translate(&self, other: &$t) -> $t { *other + *self } @@ -758,7 +779,7 @@ macro_rules! rotate_impl( macro_rules! transform_impl( ($tv: ident, $t: ident) => ( - impl + Sub> Transform<$t> for $tv { + impl + Sub> Transform<$t> for $tv { fn transform(&self, other: &$t) -> $t { self.translate(other) } diff --git a/src/traits/geometry.rs b/src/traits/geometry.rs index cb52251b..359718f7 100644 --- a/src/traits/geometry.rs +++ b/src/traits/geometry.rs @@ -82,7 +82,7 @@ pub trait Rotate { /// /// Those operations are automatically implemented in term of the `Rotation` and `Translation` /// traits. -pub trait RotationWithTranslation + Copy, AV>: Rotation + Translation + Sized { +pub trait RotationWithTranslation + Copy, AV>: Rotation + Translation + Sized { /// Applies a rotation centered on a specific point. /// /// # Arguments @@ -136,14 +136,16 @@ pub trait RotationWithTranslation + Copy, AV>: Rotation + Transl } } -impl + Copy, AV, M: Rotation + Translation> RotationWithTranslation for M { +impl + Copy, AV, M: Rotation + Translation> RotationWithTranslation for M { } /// Trait of transformation having a rotation extractable as a rotation matrix. This can typically /// be implemented by quaternions to convert them to a rotation matrix. -pub trait RotationMatrix + Rotation> : Rotation { +pub trait RotationMatrix : Rotation { + type Output: Mat + Rotation; + /// Gets the rotation matrix represented by `self`. - fn to_rot_mat(&self) -> M; + fn to_rot_mat(&self) -> Self::Output; } /// Composition of a rotation and an absolute value. @@ -227,9 +229,11 @@ pub trait Norm { /** * Trait of elements having a cross product. */ -pub trait Cross { +pub trait Cross { + type Output; + /// Computes the cross product between two elements (usually vectors). - fn cross(&self, other: &Self) -> V; + fn cross(&self, other: &Self) -> Self::Output; } /** diff --git a/src/traits/operations.rs b/src/traits/operations.rs index 6f4461fd..75281e71 100644 --- a/src/traits/operations.rs +++ b/src/traits/operations.rs @@ -314,7 +314,7 @@ pub trait RMul { fn rmul(&self, v: &V) -> V; } -impl, T: Copy> RMul for M { +impl, T: Copy> RMul for M { fn rmul(&self, v: &T) -> T { *self * *v } @@ -326,7 +326,7 @@ pub trait LMul { fn lmul(&self, &V) -> V; } -impl, M: Copy> LMul for M { +impl, M: Copy> LMul for M { fn lmul(&self, v: &T) -> T { *v * *self } diff --git a/src/traits/structure.rs b/src/traits/structure.rs index 3d0f598f..ccb52816 100644 --- a/src/traits/structure.rs +++ b/src/traits/structure.rs @@ -9,9 +9,11 @@ use traits::operations::{RMul, LMul, Axpy, Transpose, Inv, Absolute}; use traits::geometry::{Dot, Norm, Orig}; /// Basic integral numeric trait. -pub trait BaseNum: Copy + Zero + One + Add + Sub + Mul + - Div + Rem + Neg + PartialEq + Absolute + - Axpy { +pub trait BaseNum: Copy + Zero + One + + Add + Sub + + Mul + Div + + Rem + Neg + PartialEq + + Absolute + Axpy { } /// Basic floating-point number numeric trait. @@ -58,19 +60,19 @@ pub trait Cast { /// Trait of matrices. /// /// A matrix has rows and columns and are able to multiply them. -pub trait Mat: Row + Col + RMul + LMul + Index<(uint, uint), N> { } +pub trait Mat: Row + Col + RMul + LMul + Index<(uint, uint), Output = N> { } impl Mat for M - where M: Row + Col + RMul + LMul + Index<(uint, uint), N> { + where M: Row + Col + RMul + LMul + Index<(uint, uint), Output = N> { } /// Trait implemented by square matrices. -pub trait SquareMat: Mat + Mul + Eye + Transpose + Diag + Inv + Dim + - One { +pub trait SquareMat: Mat + + Mul + Eye + Transpose + Diag + Inv + Dim + One { } impl SquareMat for M - where M: Mat + Mul + Eye + Transpose + Diag + Inv + Dim + One { + where M: Mat + Mul + Eye + Transpose + Diag + Inv + Dim + One { } /// Trait for constructing the identity matrix @@ -175,7 +177,7 @@ pub trait Diag { } /// The shape of an indexable object. -pub trait Shape: Index { +pub trait Shape: Index { /// Returns the shape of an indexable object. fn shape(&self) -> I; } @@ -185,24 +187,24 @@ pub trait Shape: Index { /// It exists because the `I` trait cannot be used to express write access. /// Thus, this is the same as the `I` trait but without the syntactic sugar and with a method /// to write to a specific index. -pub trait Indexable: Shape + IndexMut { +pub trait Indexable: Shape + IndexMut { #[deprecated = "use the Index `[]` overloaded operator instead"] /// Reads the `i`-th element of `self`. - fn at(&self, i: I) -> Res; + fn at(&self, i: I) -> N; #[deprecated = "use the IndexMut `[]` overloaded operator instead"] /// Writes to the `i`-th element of `self`. - fn set(&mut self, i: I, Res); + fn set(&mut self, i: I, N); /// Swaps the `i`-th element of `self` with its `j`-th element. fn swap(&mut self, i: I, j: I); /// Reads the `i`-th element of `self`. /// /// `i` is not checked. - unsafe fn unsafe_at(&self, i: I) -> Res; + unsafe fn unsafe_at(&self, i: I) -> N; /// Writes to the `i`-th element of `self`. /// /// `i` is not checked. - unsafe fn unsafe_set(&mut self, i: I, Res); + unsafe fn unsafe_set(&mut self, i: I, N); } /// This is a workaround of current Rust limitations. @@ -235,8 +237,12 @@ pub trait VecAsPnt

{ } /// Trait grouping most common operations on vectors. -pub trait NumVec: Dim + Sub + Add + Neg + Zero + PartialEq + - Mul + Div + Dot + Axpy + Index { +pub trait NumVec: Dim + + Sub + Add + + Mul + Div + + Neg + + Index + + Zero + PartialEq + Dot + Axpy { } /// Trait of vector with components implementing the `BaseFloat` trait. @@ -264,8 +270,18 @@ pub trait PntAsVec { // XXX: the vector space element `V` should be an associated type. Though this would prevent V from // having bounds (they are not supported yet). So, for now, we will just use a type parameter. pub trait NumPnt: - Copy + PntAsVec + Dim + Sub + Orig + Neg + PartialEq + Mul + - Div + Add + Axpy + Index { // FIXME: + Sub + Copy + + PntAsVec + + Dim + + Orig + + PartialEq + + Axpy + + Sub + + Neg + + Mul + + Div + + Add + + Index { // FIXME: + Sub } /// Trait of points with components implementing the `BaseFloat` trait.