From 325ebad75ef09a2bc5aea157f1afa7622f669ebe Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Mon, 11 Aug 2014 17:02:25 +1000 Subject: [PATCH] Use more self-explanatory names for indexing methods --- src/array.rs | 54 ++++++++++++++++++++++++++++++++++++++++++++++++--- src/matrix.rs | 12 ++++++------ 2 files changed, 57 insertions(+), 9 deletions(-) diff --git a/src/array.rs b/src/array.rs index 595a1b0..e60234f 100644 --- a/src/array.rs +++ b/src/array.rs @@ -28,16 +28,30 @@ pub trait Array1: Index + IndexMut &mut (*self)[0] } + #[deprecated = "Use `Array1::swap_elems` instead"] #[inline] /// Swap the elements at indices `i` and `j` in-place. fn swap_i(&mut self, i: uint, j: uint) { + self.swap_i(i, j) + } + + /// Swap the elements at indices `i` and `j` in-place. + #[inline] + fn swap_elems(&mut self, i: uint, j: uint) { // Yeah, ok borrow checker – I know what I'm doing here unsafe { ptr::swap(&mut (*self)[i], &mut (*self)[j]) }; } /// Replace an element in the array. + #[deprecated = "Use `Array1::replace_elem` instead"] #[inline] fn replace_i(&mut self, i: uint, src: Element) -> Element { + self.replace_i(i, src) + } + + /// Replace an element in the array. + #[inline] + fn replace_elem(&mut self, i: uint, src: Element) -> Element { mem::replace(&mut (*self)[i], src) } @@ -59,26 +73,60 @@ pub trait Array2, Row: Array1, Element: Copy>: } /// Swap two columns of this array. + #[deprecated = "Use `Array2::swap_cols` instead"] #[inline] fn swap_c(&mut self, a: uint, b: uint) { + self.swap_cols(a, b) + } + + /// Swap two columns of this array. + #[inline] + fn swap_cols(&mut self, a: uint, b: uint) { unsafe { ptr::swap(&mut (*self)[a], &mut (*self)[b]) }; } /// Replace a column in the array. + #[deprecated = "Use `Array2::replace_col` instead"] #[inline] fn replace_c(&mut self, c: uint, src: Column) -> Column { + self.replace_col(c, src) + } + + /// Replace a column in the array. + #[inline] + fn replace_col(&mut self, c: uint, src: Column) -> Column { mem::replace(&mut (*self)[c], src) } /// Get a row from this array by-value. - fn r(&self, r: uint) -> Row; + #[deprecated = "Use `Array2::row` instead"] + #[inline] + fn r(&self, r: uint) -> Row { + self.row(r) + } + + /// Get a row from this array by-value. + fn row(&self, r: uint) -> Row; + + #[deprecated = "Use `Array2::swap_rows` instead"] + #[inline] + fn swap_r(&mut self, a: uint, b: uint) { + self.swap_rows(a, b) + } /// Swap two rows of this array. - fn swap_r(&mut self, a: uint, b: uint); + fn swap_rows(&mut self, a: uint, b: uint); + + /// Swap the values at index `a` and `b` + #[deprecated = "Use `Array2::swap_elems` instead"] + #[inline] + fn swap_cr(&mut self, a: (uint, uint), b: (uint, uint)) { + self.swap_elems(a, b) + } /// Swap the values at index `a` and `b` #[inline] - fn swap_cr(&mut self, a: (uint, uint), b: (uint, uint)) { + fn swap_elems(&mut self, a: (uint, uint), b: (uint, uint)) { let (ac, ar) = a; let (bc, br) = b; unsafe { ptr::swap(&mut (*self)[ac][ar], &mut (*self)[bc][br]) }; diff --git a/src/matrix.rs b/src/matrix.rs index a0a84f3..90a5e2f 100644 --- a/src/matrix.rs +++ b/src/matrix.rs @@ -395,13 +395,13 @@ impl One for Matrix4 { #[inline] fn one() -> Matrix4 { Matri impl Array2, Vector2, S> for Matrix2 { #[inline] - fn r(&self, r: uint) -> Vector2 { + fn row(&self, r: uint) -> Vector2 { Vector2::new(self[0][r], self[1][r]) } #[inline] - fn swap_r(&mut self, a: uint, b: uint) { + fn swap_rows(&mut self, a: uint, b: uint) { (&mut self[0]).swap_i(a, b); (&mut self[1]).swap_i(a, b); } @@ -432,14 +432,14 @@ impl IndexMut> for Matrix2 { impl Array2, Vector3, S> for Matrix3 { #[inline] - fn r(&self, r: uint) -> Vector3 { + fn row(&self, r: uint) -> Vector3 { Vector3::new(self[0][r], self[1][r], self[2][r]) } #[inline] - fn swap_r(&mut self, a: uint, b: uint) { + fn swap_rows(&mut self, a: uint, b: uint) { (&mut self[0]).swap_i(a, b); (&mut self[1]).swap_i(a, b); (&mut self[2]).swap_i(a, b); @@ -472,7 +472,7 @@ impl IndexMut> for Matrix3 { impl Array2, Vector4, S> for Matrix4 { #[inline] - fn r(&self, r: uint) -> Vector4 { + fn row(&self, r: uint) -> Vector4 { Vector4::new(self[0][r], self[1][r], self[2][r], @@ -480,7 +480,7 @@ impl Array2, Vector4, S> for Matrix4 { } #[inline] - fn swap_r(&mut self, a: uint, b: uint) { + fn swap_rows(&mut self, a: uint, b: uint) { (&mut self[0]).swap_i(a, b); (&mut self[1]).swap_i(a, b); (&mut self[2]).swap_i(a, b);