diff --git a/src/structs/dvec_macros.rs b/src/structs/dvec_macros.rs index 12bfa107..8d780734 100644 --- a/src/structs/dvec_macros.rs +++ b/src/structs/dvec_macros.rs @@ -94,7 +94,8 @@ macro_rules! dvec_impl( } } - impl Iterable for $dvec { + impl Iterable for $dvec { + type Output = N; #[inline] fn iter<'l>(&'l self) -> Iter<'l, N> { self.as_slice().iter() diff --git a/src/structs/mat_macros.rs b/src/structs/mat_macros.rs index 5f268004..6cd40fcd 100644 --- a/src/structs/mat_macros.rs +++ b/src/structs/mat_macros.rs @@ -190,7 +190,9 @@ macro_rules! absolute_impl( macro_rules! iterable_impl( ($t: ident, $dim: expr) => ( - impl Iterable for $t { + impl Iterable for $t { + type Output = N; + #[inline] fn iter<'l>(&'l self) -> Iter<'l, N> { unsafe { diff --git a/src/structs/spec/vec0.rs b/src/structs/spec/vec0.rs index e0db6b7d..cf8ffbe7 100644 --- a/src/structs/spec/vec0.rs +++ b/src/structs/spec/vec0.rs @@ -60,7 +60,9 @@ impl Indexable for vec::Vec0 { } } -impl Iterable for vec::Vec0 { +impl Iterable for vec::Vec0 { + type Output = N; + #[inline] fn iter<'l>(&'l self) -> Iter<'l, N> { unsafe { mem::transmute::<&'l vec::Vec0, &'l [N; 0]>(self).iter() } diff --git a/src/structs/vec_macros.rs b/src/structs/vec_macros.rs index 65fa31be..1f7cf7c2 100644 --- a/src/structs/vec_macros.rs +++ b/src/structs/vec_macros.rs @@ -243,7 +243,8 @@ macro_rules! new_repeat_impl( macro_rules! iterable_impl( ($t: ident, $dim: expr) => ( - impl Iterable for $t { + impl Iterable for $t { + type Output = N; #[inline] fn iter<'l>(&'l self) -> Iter<'l, N> { unsafe { @@ -504,6 +505,38 @@ macro_rules! dot_impl( ) ); +macro_rules! scalar_ops_impl( + ($t: ident, $($compN: ident),+) => ( + impl> ScalarMul for $t { + #[inline] + fn mul_s(&self, other: &N) -> $t { + $t::new($(self.$compN * *other),+) + } + } + + impl> ScalarDiv for $t { + #[inline] + fn div_s(&self, other: &N) -> $t { + $t::new($(self.$compN / *other),+) + } + } + + impl> ScalarAdd for $t { + #[inline] + fn add_s(&self, other: &N) -> $t { + $t::new($(self.$compN + *other),+) + } + } + + impl> ScalarSub for $t { + #[inline] + fn sub_s(&self, other: &N) -> $t { + $t::new($(self.$compN - *other),+) + } + } + ) +); + macro_rules! translation_impl( ($t: ident) => ( impl + Neg> Translation<$t> for $t { diff --git a/src/traits/structure.rs b/src/traits/structure.rs index 90430f69..8183f0c6 100644 --- a/src/traits/structure.rs +++ b/src/traits/structure.rs @@ -59,12 +59,11 @@ pub trait Cast { /// Trait of matrices. /// /// A matrix has rows and columns and are able to multiply them. -pub trait Mat>: Row + Col + Mul + Index<(usize, usize), Output = N> { } +pub trait Mat: Row + Col + Index<(usize, usize), Output = N> { } impl Mat for M - where M: Row + Col + Mul + Index<(usize, usize), Output = N>, - C: Mul, -{} + where M: Row + Col + Index<(usize, usize), Output = N> { +} /// Trait implemented by square matrices. pub trait SquareMat: Mat + @@ -190,9 +189,11 @@ pub trait Indexable: Shape + IndexMut { /// This is a workaround of current Rust limitations. /// /// Traits of objects which can be iterated through like a vector. -pub trait Iterable { +pub trait Iterable { + /// Iterable output type + type Output; /// Gets a vector-like read-only iterator. - fn iter<'l>(&'l self) -> Iter<'l, N>; + fn iter<'l>(&'l self) -> Iter<'l, Self::Output>; } /// This is a workaround of current Rust limitations.