diff --git a/src/structs/mat_macros.rs b/src/structs/mat_macros.rs index 637db4d2..3978ed60 100644 --- a/src/structs/mat_macros.rs +++ b/src/structs/mat_macros.rs @@ -259,7 +259,7 @@ macro_rules! col_slice_impl( macro_rules! row_impl( ($t: ident, $tv: ident, $dim: expr) => ( - impl Row<$tv> for $t { + impl Row<$tv> for $t { #[inline] fn nrows(&self) -> uint { Dim::dim(None::<$t>) @@ -267,12 +267,20 @@ macro_rules! row_impl( #[inline] fn set_row(&mut self, row: uint, v: $tv) { - self[row] = v; + for (i, e) in v.iter().enumerate() { + self.set((row, i), e.clone()); + } } #[inline] fn row(&self, row: uint) -> $tv { - self[row].clone() + let mut res: $tv = Zero::zero(); + + for (i, e) in res.mut_iter().enumerate() { + *e = self.at((row, i)); + } + + res } } ) @@ -292,7 +300,7 @@ macro_rules! row_slice_impl( macro_rules! col_impl( ($t: ident, $tv: ident, $dim: expr) => ( - impl Col<$tv> for $t { + impl Col<$tv> for $t { #[inline] fn ncols(&self) -> uint { Dim::dim(None::<$t>) @@ -300,20 +308,12 @@ macro_rules! col_impl( #[inline] fn set_col(&mut self, col: uint, v: $tv) { - for (i, e) in v.iter().enumerate() { - self.set((i, col), e.clone()); - } + self[col] = v; } #[inline] fn col(&self, col: uint) -> $tv { - let mut res: $tv = Zero::zero(); - - for (i, e) in res.mut_iter().enumerate() { - *e = self.at((i, col)); - } - - res + self[col].clone() } } ) diff --git a/src/tests/mat.rs b/src/tests/mat.rs index 882947ab..6d08ed0f 100644 --- a/src/tests/mat.rs +++ b/src/tests/mat.rs @@ -1,6 +1,6 @@ use std::num::{Float, abs}; use std::rand::random; -use na::{Vec1, Vec3, Mat1, Mat2, Mat3, Mat4, Mat5, Mat6, Rot3, DMat, DVec, Indexable}; +use na::{Vec1, Vec3, Mat1, Mat2, Mat3, Mat4, Mat5, Mat6, Rot3, DMat, DVec, Indexable, Row, Col}; use na; use std::cmp::{min, max}; @@ -330,3 +330,15 @@ fn test_from_fn() { assert_eq!(actual, expected); } + +#[test] +fn test_row_3() { + let mat = Mat3::new(0.0f32, 1.0, 2.0, + 3.0, 4.0, 5.0, + 6.0, 7.0, 8.0); + let second_row = mat.row(1); + let second_col = mat.col(1); + + assert!(second_row == Vec3::new(3.0, 4.0, 5.0)); + assert!(second_col == Vec3::new(1.0, 4.0, 7.0)); +}