Add (pointwise) Add and Sub impl for matrices.

This commit is contained in:
Sébastien Crozet 2013-08-12 16:50:50 +02:00
parent b08a8384ae
commit 037cf95542
2 changed files with 76 additions and 0 deletions

View File

@ -37,6 +37,8 @@ pub struct Mat1<N> {
mat_impl!(Mat1, m11)
mat_cast_impl!(Mat1, m11)
add_impl!(Mat1, m11)
sub_impl!(Mat1, m11)
one_impl!(Mat1, _1)
iterable_impl!(Mat1, 1)
iterable_mut_impl!(Mat1, 1)
@ -65,6 +67,10 @@ mat_impl!(Mat2, m11, m12,
m21, m22)
mat_cast_impl!(Mat2, m11, m12,
m21, m22)
add_impl!(Mat2, m11, m12,
m21, m22)
sub_impl!(Mat2, m11, m12,
m21, m22)
one_impl!(Mat2, _1, _0,
_0, _1)
iterable_impl!(Mat2, 2)
@ -97,6 +103,12 @@ mat_impl!(Mat3, m11, m12, m13,
mat_cast_impl!(Mat3, m11, m12, m13,
m21, m22, m23,
m31, m32, m33)
add_impl!(Mat3, m11, m12, m13,
m21, m22, m23,
m31, m32, m33)
sub_impl!(Mat3, m11, m12, m13,
m21, m22, m23,
m31, m32, m33)
one_impl!(Mat3, _1, _0, _0,
_0, _1, _0,
_0, _0, _1)
@ -137,6 +149,18 @@ mat_cast_impl!(Mat4,
m31, m32, m33, m34,
m41, m42, m43, m44
)
add_impl!(Mat4,
m11, m12, m13, m14,
m21, m22, m23, m24,
m31, m32, m33, m34,
m41, m42, m43, m44
)
sub_impl!(Mat4,
m11, m12, m13, m14,
m21, m22, m23, m24,
m31, m32, m33, m34,
m41, m42, m43, m44
)
one_impl!(Mat4, _1, _0, _0, _0,
_0, _1, _0, _0,
_0, _0, _1, _0,
@ -188,6 +212,20 @@ one_impl!(Mat5,
_0, _0, _0, _1, _0,
_0, _0, _0, _0, _1
)
add_impl!(Mat5,
m11, m12, m13, m14, m15,
m21, m22, m23, m24, m25,
m31, m32, m33, m34, m35,
m41, m42, m43, m44, m45,
m51, m52, m53, m54, m55
)
sub_impl!(Mat5,
m11, m12, m13, m14, m15,
m21, m22, m23, m24, m25,
m31, m32, m33, m34, m35,
m41, m42, m43, m44, m45,
m51, m52, m53, m54, m55
)
iterable_impl!(Mat5, 5)
iterable_mut_impl!(Mat5, 5)
dim_impl!(Mat5, 5)
@ -231,6 +269,22 @@ mat_cast_impl!(Mat6,
m51, m52, m53, m54, m55, m56,
m61, m62, m63, m64, m65, m66
)
add_impl!(Mat6,
m11, m12, m13, m14, m15, m16,
m21, m22, m23, m24, m25, m26,
m31, m32, m33, m34, m35, m36,
m41, m42, m43, m44, m45, m46,
m51, m52, m53, m54, m55, m56,
m61, m62, m63, m64, m65, m66
)
sub_impl!(Mat6,
m11, m12, m13, m14, m15, m16,
m21, m22, m23, m24, m25, m26,
m31, m32, m33, m34, m35, m36,
m41, m42, m43, m44, m45, m46,
m51, m52, m53, m54, m55, m56,
m61, m62, m63, m64, m65, m66
)
one_impl!(Mat6,
_1, _0, _0, _0, _0, _0,
_0, _1, _0, _0, _0, _0,

View File

@ -25,6 +25,28 @@ macro_rules! mat_cast_impl(
)
)
macro_rules! add_impl(
($t: ident, $comp0: ident $(,$compN: ident)*) => (
impl<N: Add<N, N>> Add<$t<N>, $t<N>> for $t<N> {
#[inline]
pub fn add(&self, other: &$t<N>) -> $t<N> {
$t::new(self.$comp0 + other.$comp0 $(, self.$compN + other.$compN )*)
}
}
)
)
macro_rules! sub_impl(
($t: ident, $comp0: ident $(,$compN: ident)*) => (
impl<N: Sub<N, N>> Sub<$t<N>, $t<N>> for $t<N> {
#[inline]
pub fn sub(&self, other: &$t<N>) -> $t<N> {
$t::new(self.$comp0 - other.$comp0 $(, self.$compN - other.$compN )*)
}
}
)
)
macro_rules! iterable_impl(
($t: ident, $dim: expr) => (
impl<N> Iterable<N> for $t<N> {