Use more self-explanatory names for indexing methods

This commit is contained in:
Brendan Zabarauskas 2014-08-11 17:02:25 +10:00
parent 8999d88216
commit 325ebad75e
2 changed files with 57 additions and 9 deletions

View file

@ -28,16 +28,30 @@ pub trait Array1<Element: Copy>: Index<uint, Element> + IndexMut<uint, Element>
&mut (*self)[0] &mut (*self)[0]
} }
#[deprecated = "Use `Array1::swap_elems` instead"]
#[inline] #[inline]
/// Swap the elements at indices `i` and `j` in-place. /// Swap the elements at indices `i` and `j` in-place.
fn swap_i(&mut self, i: uint, j: uint) { 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 // Yeah, ok borrow checker I know what I'm doing here
unsafe { ptr::swap(&mut (*self)[i], &mut (*self)[j]) }; unsafe { ptr::swap(&mut (*self)[i], &mut (*self)[j]) };
} }
/// Replace an element in the array. /// Replace an element in the array.
#[deprecated = "Use `Array1::replace_elem` instead"]
#[inline] #[inline]
fn replace_i(&mut self, i: uint, src: Element) -> Element { 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) mem::replace(&mut (*self)[i], src)
} }
@ -59,26 +73,60 @@ pub trait Array2<Column: Array1<Element>, Row: Array1<Element>, Element: Copy>:
} }
/// Swap two columns of this array. /// Swap two columns of this array.
#[deprecated = "Use `Array2::swap_cols` instead"]
#[inline] #[inline]
fn swap_c(&mut self, a: uint, b: uint) { 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]) }; unsafe { ptr::swap(&mut (*self)[a], &mut (*self)[b]) };
} }
/// Replace a column in the array. /// Replace a column in the array.
#[deprecated = "Use `Array2::replace_col` instead"]
#[inline] #[inline]
fn replace_c(&mut self, c: uint, src: Column) -> Column { 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) mem::replace(&mut (*self)[c], src)
} }
/// Get a row from this array by-value. /// 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. /// 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` /// Swap the values at index `a` and `b`
#[inline] #[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 (ac, ar) = a;
let (bc, br) = b; let (bc, br) = b;
unsafe { ptr::swap(&mut (*self)[ac][ar], &mut (*self)[bc][br]) }; unsafe { ptr::swap(&mut (*self)[ac][ar], &mut (*self)[bc][br]) };

View file

@ -395,13 +395,13 @@ impl<S: BaseFloat> One for Matrix4<S> { #[inline] fn one() -> Matrix4<S> { Matri
impl<S: Copy> Array2<Vector2<S>, Vector2<S>, S> for Matrix2<S> { impl<S: Copy> Array2<Vector2<S>, Vector2<S>, S> for Matrix2<S> {
#[inline] #[inline]
fn r(&self, r: uint) -> Vector2<S> { fn row(&self, r: uint) -> Vector2<S> {
Vector2::new(self[0][r], Vector2::new(self[0][r],
self[1][r]) self[1][r])
} }
#[inline] #[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[0]).swap_i(a, b);
(&mut self[1]).swap_i(a, b); (&mut self[1]).swap_i(a, b);
} }
@ -432,14 +432,14 @@ impl<S: Copy> IndexMut<uint, Vector2<S>> for Matrix2<S> {
impl<S: Copy> Array2<Vector3<S>, Vector3<S>, S> for Matrix3<S> { impl<S: Copy> Array2<Vector3<S>, Vector3<S>, S> for Matrix3<S> {
#[inline] #[inline]
fn r(&self, r: uint) -> Vector3<S> { fn row(&self, r: uint) -> Vector3<S> {
Vector3::new(self[0][r], Vector3::new(self[0][r],
self[1][r], self[1][r],
self[2][r]) self[2][r])
} }
#[inline] #[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[0]).swap_i(a, b);
(&mut self[1]).swap_i(a, b); (&mut self[1]).swap_i(a, b);
(&mut self[2]).swap_i(a, b); (&mut self[2]).swap_i(a, b);
@ -472,7 +472,7 @@ impl<S: Copy> IndexMut<uint, Vector3<S>> for Matrix3<S> {
impl<S: Copy> Array2<Vector4<S>, Vector4<S>, S> for Matrix4<S> { impl<S: Copy> Array2<Vector4<S>, Vector4<S>, S> for Matrix4<S> {
#[inline] #[inline]
fn r(&self, r: uint) -> Vector4<S> { fn row(&self, r: uint) -> Vector4<S> {
Vector4::new(self[0][r], Vector4::new(self[0][r],
self[1][r], self[1][r],
self[2][r], self[2][r],
@ -480,7 +480,7 @@ impl<S: Copy> Array2<Vector4<S>, Vector4<S>, S> for Matrix4<S> {
} }
#[inline] #[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[0]).swap_i(a, b);
(&mut self[1]).swap_i(a, b); (&mut self[1]).swap_i(a, b);
(&mut self[2]).swap_i(a, b); (&mut self[2]).swap_i(a, b);