#![macro_use] macro_rules! submat_impl( ($t: ident, $submat: ident) => ( impl $t { #[inline] pub fn submat<'r>(&'r self) -> &'r $submat { &self.submat } } ) ); macro_rules! rotate_impl( ($t: ident, $tv: ident, $tp: ident) => ( impl Rotate<$tv> for $t { #[inline] fn rotate(&self, v: &$tv) -> $tv { *self * *v } #[inline] fn inv_rotate(&self, v: &$tv) -> $tv { *v * *self } } impl Rotate<$tp> for $t { #[inline] fn rotate(&self, p: &$tp) -> $tp { *self * *p } #[inline] fn inv_rotate(&self, p: &$tp) -> $tp { *p * *self } } ) ); macro_rules! transform_impl( ($t: ident, $tv: ident, $tp: ident) => ( impl Transform<$tv> for $t { #[inline] fn transform(&self, v: &$tv) -> $tv { self.rotate(v) } #[inline] fn inv_transform(&self, v: &$tv) -> $tv { self.inv_rotate(v) } } impl Transform<$tp> for $t { #[inline] fn transform(&self, p: &$tp) -> $tp { self.rotate(p) } #[inline] fn inv_transform(&self, p: &$tp) -> $tp { self.inv_rotate(p) } } ) ); macro_rules! dim_impl( ($t: ident, $dim: expr) => ( impl Dim for $t { #[inline] fn dim(_: Option<$t>) -> uint { $dim } } ) ); macro_rules! rotation_matrix_impl( ($t: ident, $tlv: ident, $tav: ident) => ( impl + BaseFloat> RotationMatrix, $tav> for $t { type Output = $t; #[inline] fn to_rot_mat(&self) -> $t { self.clone() } } ) ); macro_rules! one_impl( ($t: ident) => ( impl One for $t { #[inline] fn one() -> $t { $t { submat: ::one() } } } ) ); macro_rules! rot_mul_rot_impl( ($t: ident) => ( impl Mul<$t> for $t { type Output = $t; #[inline] fn mul(self, right: $t) -> $t { $t { submat: self.submat * right.submat } } } ) ); macro_rules! rot_mul_vec_impl( ($t: ident, $tv: ident) => ( impl Mul<$tv> for $t { type Output = $tv; #[inline] fn mul(self, right: $tv) -> $tv { self.submat * right } } ) ); macro_rules! rot_mul_pnt_impl( ($t: ident, $tv: ident) => ( rot_mul_vec_impl!($t, $tv); ) ); macro_rules! vec_mul_rot_impl( ($t: ident, $tv: ident) => ( impl Mul<$t> for $tv { type Output = $tv; #[inline] fn mul(self, right: $t) -> $tv { self * right.submat } } ) ); macro_rules! pnt_mul_rot_impl( ($t: ident, $tv: ident) => ( vec_mul_rot_impl!($t, $tv); ) ); macro_rules! inv_impl( ($t: ident) => ( impl Inv for $t { #[inline] fn inv(&mut self) -> bool { self.transpose(); // always succeed true } #[inline] fn inv_cpy(&self) -> Option<$t> { // always succeed Some(self.transpose_cpy()) } } ) ); macro_rules! transpose_impl( ($t: ident) => ( impl Transpose for $t { #[inline] fn transpose_cpy(&self) -> $t { $t { submat: Transpose::transpose_cpy(&self.submat) } } #[inline] fn transpose(&mut self) { self.submat.transpose() } } ) ); macro_rules! row_impl( ($t: ident, $tv: ident) => ( impl Row<$tv> for $t { #[inline] fn nrows(&self) -> uint { self.submat.nrows() } #[inline] fn row(&self, i: uint) -> $tv { self.submat.row(i) } #[inline] fn set_row(&mut self, i: uint, row: $tv) { self.submat.set_row(i, row); } } ) ); macro_rules! col_impl( ($t: ident, $tv: ident) => ( impl Col<$tv> for $t { #[inline] fn ncols(&self) -> uint { self.submat.ncols() } #[inline] fn col(&self, i: uint) -> $tv { self.submat.col(i) } #[inline] fn set_col(&mut self, i: uint, col: $tv) { self.submat.set_col(i, col); } } ) ); macro_rules! index_impl( ($t: ident) => ( impl Index<(uint, uint)> for $t { type Output = N; fn index(&self, i: &(uint, uint)) -> &N { &self.submat[*i] } } ) ); macro_rules! to_homogeneous_impl( ($t: ident, $tm: ident) => ( impl ToHomogeneous<$tm> for $t { #[inline] fn to_homogeneous(&self) -> $tm { self.submat.to_homogeneous() } } ) ); macro_rules! approx_eq_impl( ($t: ident) => ( impl> ApproxEq for $t { #[inline] fn approx_epsilon(_: Option<$t>) -> N { ApproxEq::approx_epsilon(None::) } #[inline] fn approx_ulps(_: Option<$t>) -> u32 { ApproxEq::approx_ulps(None::) } #[inline] fn approx_eq(&self, other: &$t) -> bool { ApproxEq::approx_eq(&self.submat, &other.submat) } #[inline] fn approx_eq_eps(&self, other: &$t, epsilon: &N) -> bool { ApproxEq::approx_eq_eps(&self.submat, &other.submat, epsilon) } #[inline] fn approx_eq_ulps(&self, other: &$t, ulps: u32) -> bool { ApproxEq::approx_eq_ulps(&self.submat, &other.submat, ulps) } } ) ); macro_rules! absolute_impl( ($t: ident, $tm: ident) => ( impl> Absolute<$tm> for $t { #[inline] fn abs(m: &$t) -> $tm { Absolute::abs(&m.submat) } } ) );