diff --git a/src/index.rs b/src/index.rs index 4627016..fcfbb1a 100644 --- a/src/index.rs +++ b/src/index.rs @@ -34,7 +34,7 @@ assert_eq!(m[(0,0)], 1); assert_eq!(m[(1,1)], 5); assert_eq!(m[(2,1)], 8); ``` */ -pub trait Index2D: Copy + Debug { +pub trait MatrixIndex: Copy + Debug { /** Convert an index to its 1-D linear interpretation, given the `width` and `height` of the matrix being subscripted. @@ -43,7 +43,7 @@ pub trait Index2D: Copy + Debug { # Examples ``` - # use vector_victor::index::Index2D; + # use vector_victor::index::MatrixIndex; assert_eq!( (1usize,2usize).to_1d(3,3), Some(5), @@ -67,7 +67,7 @@ pub trait Index2D: Copy + Debug { # Examples ``` - # use vector_victor::index::Index2D; + # use vector_victor::index::MatrixIndex; assert_eq!( 5usize.to_2d(3,3), Some((1usize,2usize)), @@ -80,7 +80,7 @@ pub trait Index2D: Copy + Debug { fn to_2d(self, height: usize, width: usize) -> Option<(usize, usize)>; } -impl Index2D for usize { +impl MatrixIndex for usize { #[inline(always)] fn to_2d(self, height: usize, width: usize) -> Option<(usize, usize)> { match self < (height * width) { @@ -90,7 +90,7 @@ impl Index2D for usize { } } -impl Index2D for (usize, usize) { +impl MatrixIndex for (usize, usize) { #[inline(always)] fn to_2d(self, height: usize, width: usize) -> Option<(usize, usize)> { match self.0 < height && self.1 < width { diff --git a/src/lib.rs b/src/lib.rs index bea0f22..2a764c3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,7 +4,7 @@ extern crate core; -use index::Index2D; +use index::MatrixIndex; use num_traits::{Bounded, One, Zero}; use std::cmp::min; use std::fmt::Debug; @@ -314,7 +314,7 @@ impl Matrix { # Arguments - * `index`: a 1D or 2D index into the matrix. See [Index2D] for more information on matrix indexing. + * `index`: a 1D or 2D index into the matrix. See [MatrixIndex] for more information on matrix indexing. # Examples @@ -335,7 +335,7 @@ impl Matrix { ``` */ #[inline] #[must_use] - pub fn get(&self, index: impl Index2D) -> Option<&T> { + pub fn get(&self, index: impl MatrixIndex) -> Option<&T> { let (m, n) = index.to_2d(M, N)?; Some(&self.data[m][n]) } @@ -348,7 +348,7 @@ impl Matrix { # Arguments - * `index`: a 1D or 2D index into the matrix. See [Index2D] for more information + * `index`: a 1D or 2D index into the matrix. See [MatrixIndex] for more information on matrix indexing. # Examples @@ -365,7 +365,7 @@ impl Matrix { ``` */ #[inline] #[must_use] - pub fn get_mut(&mut self, index: impl Index2D) -> Option<&mut T> { + pub fn get_mut(&mut self, index: impl MatrixIndex) -> Option<&mut T> { let (m, n) = index.to_2d(M, N)?; Some(&mut self.data[m][n]) } @@ -602,7 +602,7 @@ impl Matrix { // Index impl Index for Matrix where - I: Index2D, + I: MatrixIndex, T: Copy, { type Output = T; @@ -619,7 +619,7 @@ where // IndexMut impl IndexMut for Matrix where - I: Index2D, + I: MatrixIndex, T: Copy, { #[inline(always)]