From 29bff32d2dc3050a758d70c13e8d4b89e1f6a3e3 Mon Sep 17 00:00:00 2001 From: Andreas Longva Date: Fri, 11 Nov 2022 16:10:39 +0100 Subject: [PATCH] Rename MatrixSlice(Mut) to MatrixView(Mut) Additionally introduce deprecated type aliases with the old names to avoid a breaking change. --- src/base/construction_slice.rs | 10 ++-- src/base/conversion.rs | 42 +++++++-------- src/base/indexing.rs | 6 +-- src/base/iter.rs | 10 ++-- src/base/matrix_slice.rs | 97 +++++++++++++++++++++------------- src/geometry/quaternion.rs | 6 +-- 6 files changed, 96 insertions(+), 75 deletions(-) diff --git a/src/base/construction_slice.rs b/src/base/construction_slice.rs index aad50685..e54d824c 100644 --- a/src/base/construction_slice.rs +++ b/src/base/construction_slice.rs @@ -1,12 +1,12 @@ use crate::base::dimension::{Const, Dim, DimName, Dynamic}; use crate::base::matrix_slice::{ViewStorage, ViewStorageMut}; -use crate::base::{MatrixSlice, MatrixSliceMutMN, Scalar}; +use crate::base::{MatrixView, MatrixSliceMutMN, Scalar}; use num_rational::Ratio; /// # Creating matrix slices from `&[T]` impl<'a, T: Scalar, R: Dim, C: Dim, RStride: Dim, CStride: Dim> - MatrixSlice<'a, T, R, C, RStride, CStride> + MatrixView<'a, T, R, C, RStride, CStride> { /// Creates, without bound-checking, a matrix slice from an array and with dimensions and strides specified by generic types instances. /// @@ -57,7 +57,7 @@ impl<'a, T: Scalar, R: Dim, C: Dim, RStride: Dim, CStride: Dim> } } -impl<'a, T: Scalar, R: Dim, C: Dim> MatrixSlice<'a, T, R, C> { +impl<'a, T: Scalar, R: Dim, C: Dim> MatrixView<'a, T, R, C> { /// Creates, without bound-checking, a matrix slice from an array and with dimensions specified by generic types instances. /// /// # Safety @@ -87,7 +87,7 @@ impl<'a, T: Scalar, R: Dim, C: Dim> MatrixSlice<'a, T, R, C> { macro_rules! impl_constructors( ($($Dims: ty),*; $(=> $DimIdent: ident: $DimBound: ident),*; $($gargs: expr),*; $($args: ident),*) => { - impl<'a, T: Scalar, $($DimIdent: $DimBound),*> MatrixSlice<'a, T, $($Dims),*> { + impl<'a, T: Scalar, $($DimIdent: $DimBound),*> MatrixView<'a, T, $($Dims),*> { /// Creates a new matrix slice from the given data array. /// /// Panics if `data` does not contain enough elements. @@ -103,7 +103,7 @@ macro_rules! impl_constructors( } } - impl<'a, T: Scalar, $($DimIdent: $DimBound, )*> MatrixSlice<'a, T, $($Dims,)* Dynamic, Dynamic> { + impl<'a, T: Scalar, $($DimIdent: $DimBound, )*> MatrixView<'a, T, $($Dims,)* Dynamic, Dynamic> { /// Creates a new matrix slice with the specified strides from the given data array. /// /// Panics if `data` does not contain enough elements. diff --git a/src/base/conversion.rs b/src/base/conversion.rs index 26e624a3..9b6df2c2 100644 --- a/src/base/conversion.rs +++ b/src/base/conversion.rs @@ -16,8 +16,8 @@ use crate::base::dimension::{ use crate::base::iter::{MatrixIter, MatrixIterMut}; use crate::base::storage::{IsContiguous, RawStorage, RawStorageMut}; use crate::base::{ - ArrayStorage, DVectorSlice, DVectorSliceMut, DefaultAllocator, Matrix, MatrixSlice, - MatrixSliceMut, OMatrix, Scalar, + ArrayStorage, DVectorSlice, DVectorSliceMut, DefaultAllocator, Matrix, MatrixView, + MatrixViewMut, OMatrix, Scalar, }; #[cfg(any(feature = "std", feature = "alloc"))] use crate::base::{DVector, RowDVector, VecStorage}; @@ -221,19 +221,19 @@ impl From> for [[T; } impl<'a, T: Scalar, RStride: Dim, CStride: Dim, const R: usize, const C: usize> - From, Const, RStride, CStride>> for [[T; R]; C] + From, Const, RStride, CStride>> for [[T; R]; C] { #[inline] - fn from(mat: MatrixSlice<'a, T, Const, Const, RStride, CStride>) -> Self { + fn from(mat: MatrixView<'a, T, Const, Const, RStride, CStride>) -> Self { mat.into_owned().into() } } impl<'a, T: Scalar, RStride: Dim, CStride: Dim, const R: usize, const C: usize> - From, Const, RStride, CStride>> for [[T; R]; C] + From, Const, RStride, CStride>> for [[T; R]; C] { #[inline] - fn from(mat: MatrixSliceMut<'a, T, Const, Const, RStride, CStride>) -> Self { + fn from(mat: MatrixViewMut<'a, T, Const, Const, RStride, CStride>) -> Self { mat.into_owned().into() } } @@ -289,20 +289,20 @@ impl_from_into_asref_borrow_2D!( ); impl<'a, T, RStride, CStride, const R: usize, const C: usize> - From, Const, RStride, CStride>> + From, Const, RStride, CStride>> for Matrix, Const, ArrayStorage> where T: Scalar, RStride: Dim, CStride: Dim, { - fn from(matrix_slice: MatrixSlice<'a, T, Const, Const, RStride, CStride>) -> Self { + fn from(matrix_slice: MatrixView<'a, T, Const, Const, RStride, CStride>) -> Self { matrix_slice.into_owned() } } #[cfg(any(feature = "std", feature = "alloc"))] -impl<'a, T, C, RStride, CStride> From> +impl<'a, T, C, RStride, CStride> From> for Matrix> where T: Scalar, @@ -310,13 +310,13 @@ where RStride: Dim, CStride: Dim, { - fn from(matrix_slice: MatrixSlice<'a, T, Dynamic, C, RStride, CStride>) -> Self { + fn from(matrix_slice: MatrixView<'a, T, Dynamic, C, RStride, CStride>) -> Self { matrix_slice.into_owned() } } #[cfg(any(feature = "std", feature = "alloc"))] -impl<'a, T, R, RStride, CStride> From> +impl<'a, T, R, RStride, CStride> From> for Matrix> where T: Scalar, @@ -324,26 +324,26 @@ where RStride: Dim, CStride: Dim, { - fn from(matrix_slice: MatrixSlice<'a, T, R, Dynamic, RStride, CStride>) -> Self { + fn from(matrix_slice: MatrixView<'a, T, R, Dynamic, RStride, CStride>) -> Self { matrix_slice.into_owned() } } impl<'a, T, RStride, CStride, const R: usize, const C: usize> - From, Const, RStride, CStride>> + From, Const, RStride, CStride>> for Matrix, Const, ArrayStorage> where T: Scalar, RStride: Dim, CStride: Dim, { - fn from(matrix_slice: MatrixSliceMut<'a, T, Const, Const, RStride, CStride>) -> Self { + fn from(matrix_slice: MatrixViewMut<'a, T, Const, Const, RStride, CStride>) -> Self { matrix_slice.into_owned() } } #[cfg(any(feature = "std", feature = "alloc"))] -impl<'a, T, C, RStride, CStride> From> +impl<'a, T, C, RStride, CStride> From> for Matrix> where T: Scalar, @@ -351,13 +351,13 @@ where RStride: Dim, CStride: Dim, { - fn from(matrix_slice: MatrixSliceMut<'a, T, Dynamic, C, RStride, CStride>) -> Self { + fn from(matrix_slice: MatrixViewMut<'a, T, Dynamic, C, RStride, CStride>) -> Self { matrix_slice.into_owned() } } #[cfg(any(feature = "std", feature = "alloc"))] -impl<'a, T, R, RStride, CStride> From> +impl<'a, T, R, RStride, CStride> From> for Matrix> where T: Scalar, @@ -365,13 +365,13 @@ where RStride: Dim, CStride: Dim, { - fn from(matrix_slice: MatrixSliceMut<'a, T, R, Dynamic, RStride, CStride>) -> Self { + fn from(matrix_slice: MatrixViewMut<'a, T, R, Dynamic, RStride, CStride>) -> Self { matrix_slice.into_owned() } } impl<'a, T, R, C, RSlice, CSlice, RStride, CStride, S> From<&'a Matrix> - for MatrixSlice<'a, T, RSlice, CSlice, RStride, CStride> + for MatrixView<'a, T, RSlice, CSlice, RStride, CStride> where T: Scalar, R: Dim, @@ -408,7 +408,7 @@ where } impl<'a, T, R, C, RSlice, CSlice, RStride, CStride, S> From<&'a mut Matrix> - for MatrixSlice<'a, T, RSlice, CSlice, RStride, CStride> + for MatrixView<'a, T, RSlice, CSlice, RStride, CStride> where T: Scalar, R: Dim, @@ -445,7 +445,7 @@ where } impl<'a, T, R, C, RSlice, CSlice, RStride, CStride, S> From<&'a mut Matrix> - for MatrixSliceMut<'a, T, RSlice, CSlice, RStride, CStride> + for MatrixViewMut<'a, T, RSlice, CSlice, RStride, CStride> where T: Scalar, R: Dim, diff --git a/src/base/indexing.rs b/src/base/indexing.rs index 5cc64db0..df769163 100644 --- a/src/base/indexing.rs +++ b/src/base/indexing.rs @@ -3,7 +3,7 @@ use crate::base::storage::{RawStorage, RawStorageMut}; use crate::base::{ - Const, Dim, DimDiff, DimName, DimSub, Dynamic, Matrix, MatrixSlice, MatrixSliceMut, Scalar, U1, + Const, Dim, DimDiff, DimName, DimSub, Dynamic, Matrix, MatrixView, MatrixViewMut, Scalar, U1, }; use std::ops; @@ -669,7 +669,7 @@ macro_rules! impl_index_pair { $( $RConstraintType: $RConstraintBound $(<$( $RConstraintBoundParams $( = $REqBound )*),*>)* ,)* $( $CConstraintType: $CConstraintBound $(<$( $CConstraintBoundParams $( = $CEqBound )*),*>)* ),* { - type Output = MatrixSlice<'a, T, $ROut, $COut, S::RStride, S::CStride>; + type Output = MatrixView<'a, T, $ROut, $COut, S::RStride, S::CStride>; #[doc(hidden)] #[inline(always)] @@ -705,7 +705,7 @@ macro_rules! impl_index_pair { $( $RConstraintType: $RConstraintBound $(<$( $RConstraintBoundParams $( = $REqBound )*),*>)* ,)* $( $CConstraintType: $CConstraintBound $(<$( $CConstraintBoundParams $( = $CEqBound )*),*>)* ),* { - type OutputMut = MatrixSliceMut<'a, T, $ROut, $COut, S::RStride, S::CStride>; + type OutputMut = MatrixViewMut<'a, T, $ROut, $COut, S::RStride, S::CStride>; #[doc(hidden)] #[inline(always)] diff --git a/src/base/iter.rs b/src/base/iter.rs index b68e1051..991c24dc 100644 --- a/src/base/iter.rs +++ b/src/base/iter.rs @@ -6,7 +6,7 @@ use std::mem; use crate::base::dimension::{Dim, U1}; use crate::base::storage::{RawStorage, RawStorageMut}; -use crate::base::{Matrix, MatrixSlice, MatrixSliceMut, Scalar}; +use crate::base::{Matrix, MatrixView, MatrixViewMut, Scalar}; macro_rules! iterator { (struct $Name:ident for $Storage:ident.$ptr: ident -> $Ptr:ty, $Ref:ty, $SRef: ty) => { @@ -193,7 +193,7 @@ impl<'a, T, R: Dim, C: Dim, S: 'a + RawStorage> RowIter<'a, T, R, C, S> } impl<'a, T, R: Dim, C: Dim, S: 'a + RawStorage> Iterator for RowIter<'a, T, R, C, S> { - type Item = MatrixSlice<'a, T, U1, C, S::RStride, S::CStride>; + type Item = MatrixView<'a, T, U1, C, S::RStride, S::CStride>; #[inline] fn next(&mut self) -> Option { @@ -254,7 +254,7 @@ impl<'a, T, R: Dim, C: Dim, S: 'a + RawStorageMut> RowIterMut<'a, T, R, impl<'a, T, R: Dim, C: Dim, S: 'a + RawStorageMut> Iterator for RowIterMut<'a, T, R, C, S> { - type Item = MatrixSliceMut<'a, T, U1, C, S::RStride, S::CStride>; + type Item = MatrixViewMut<'a, T, U1, C, S::RStride, S::CStride>; #[inline] fn next(&mut self) -> Option { @@ -306,7 +306,7 @@ impl<'a, T, R: Dim, C: Dim, S: 'a + RawStorage> ColumnIter<'a, T, R, C, } impl<'a, T, R: Dim, C: Dim, S: 'a + RawStorage> Iterator for ColumnIter<'a, T, R, C, S> { - type Item = MatrixSlice<'a, T, R, U1, S::RStride, S::CStride>; + type Item = MatrixView<'a, T, R, U1, S::RStride, S::CStride>; #[inline] fn next(&mut self) -> Option { @@ -367,7 +367,7 @@ impl<'a, T, R: Dim, C: Dim, S: 'a + RawStorageMut> ColumnIterMut<'a, T, impl<'a, T, R: Dim, C: Dim, S: 'a + RawStorageMut> Iterator for ColumnIterMut<'a, T, R, C, S> { - type Item = MatrixSliceMut<'a, T, R, U1, S::RStride, S::CStride>; + type Item = MatrixViewMut<'a, T, R, U1, S::RStride, S::CStride>; #[inline] fn next(&mut self) -> Option { diff --git a/src/base/matrix_slice.rs b/src/base/matrix_slice.rs index be646cee..03d06778 100644 --- a/src/base/matrix_slice.rs +++ b/src/base/matrix_slice.rs @@ -285,7 +285,7 @@ impl> Matrix { } macro_rules! matrix_slice_impl ( - ($me: ident: $Me: ty, $MatrixSlice: ident, $ViewStorage: ident, $Storage: ident.$get_addr: ident (), $data: expr; + ($me: ident: $Me: ty, $MatrixView: ident, $ViewStorage: ident, $Storage: ident.$get_addr: ident (), $data: expr; $row: ident, $row_part: ident, $rows: ident, @@ -317,20 +317,20 @@ macro_rules! matrix_slice_impl ( */ /// Returns a slice containing the i-th row of this matrix. #[inline] - pub fn $row($me: $Me, i: usize) -> $MatrixSlice<'_, T, U1, C, S::RStride, S::CStride> { + pub fn $row($me: $Me, i: usize) -> $MatrixView<'_, T, U1, C, S::RStride, S::CStride> { $me.$fixed_rows::<1>(i) } /// Returns a slice containing the `n` first elements of the i-th row of this matrix. #[inline] - pub fn $row_part($me: $Me, i: usize, n: usize) -> $MatrixSlice<'_, T, U1, Dynamic, S::RStride, S::CStride> { + pub fn $row_part($me: $Me, i: usize, n: usize) -> $MatrixView<'_, T, U1, Dynamic, S::RStride, S::CStride> { $me.$generic_slice((i, 0), (Const::<1>, Dynamic::new(n))) } /// Extracts from this matrix a set of consecutive rows. #[inline] pub fn $rows($me: $Me, first_row: usize, nrows: usize) - -> $MatrixSlice<'_, T, Dynamic, C, S::RStride, S::CStride> { + -> $MatrixView<'_, T, Dynamic, C, S::RStride, S::CStride> { $me.$rows_generic(first_row, Dynamic::new(nrows)) } @@ -338,7 +338,7 @@ macro_rules! matrix_slice_impl ( /// Extracts from this matrix a set of consecutive rows regularly skipping `step` rows. #[inline] pub fn $rows_with_step($me: $Me, first_row: usize, nrows: usize, step: usize) - -> $MatrixSlice<'_, T, Dynamic, C, Dynamic, S::CStride> { + -> $MatrixView<'_, T, Dynamic, C, Dynamic, S::CStride> { $me.$rows_generic_with_step(first_row, Dynamic::new(nrows), step) } @@ -346,7 +346,7 @@ macro_rules! matrix_slice_impl ( /// Extracts a compile-time number of consecutive rows from this matrix. #[inline] pub fn $fixed_rows($me: $Me, first_row: usize) - -> $MatrixSlice<'_, T, Const, C, S::RStride, S::CStride> { + -> $MatrixView<'_, T, Const, C, S::RStride, S::CStride> { $me.$rows_generic(first_row, Const::) } @@ -355,7 +355,7 @@ macro_rules! matrix_slice_impl ( /// rows. #[inline] pub fn $fixed_rows_with_step($me: $Me, first_row: usize, step: usize) - -> $MatrixSlice<'_, T, Const, C, Dynamic, S::CStride> { + -> $MatrixView<'_, T, Const, C, Dynamic, S::CStride> { $me.$rows_generic_with_step(first_row, Const::, step) } @@ -364,7 +364,7 @@ macro_rules! matrix_slice_impl ( /// argument may or may not be values known at compile-time. #[inline] pub fn $rows_generic($me: $Me, row_start: usize, nrows: RSlice) - -> $MatrixSlice<'_, T, RSlice, C, S::RStride, S::CStride> { + -> $MatrixView<'_, T, RSlice, C, S::RStride, S::CStride> { let my_shape = $me.shape_generic(); $me.assert_slice_index((row_start, 0), (nrows.value(), my_shape.1.value()), (0, 0)); @@ -381,7 +381,7 @@ macro_rules! matrix_slice_impl ( /// argument may or may not be values known at compile-time. #[inline] pub fn $rows_generic_with_step($me: $Me, row_start: usize, nrows: RSlice, step: usize) - -> $MatrixSlice<'_, T, RSlice, C, Dynamic, S::CStride> + -> $MatrixView<'_, T, RSlice, C, Dynamic, S::CStride> where RSlice: Dim { let my_shape = $me.shape_generic(); @@ -404,20 +404,20 @@ macro_rules! matrix_slice_impl ( */ /// Returns a slice containing the i-th column of this matrix. #[inline] - pub fn $column($me: $Me, i: usize) -> $MatrixSlice<'_, T, R, U1, S::RStride, S::CStride> { + pub fn $column($me: $Me, i: usize) -> $MatrixView<'_, T, R, U1, S::RStride, S::CStride> { $me.$fixed_columns::<1>(i) } /// Returns a slice containing the `n` first elements of the i-th column of this matrix. #[inline] - pub fn $column_part($me: $Me, i: usize, n: usize) -> $MatrixSlice<'_, T, Dynamic, U1, S::RStride, S::CStride> { + pub fn $column_part($me: $Me, i: usize, n: usize) -> $MatrixView<'_, T, Dynamic, U1, S::RStride, S::CStride> { $me.$generic_slice((0, i), (Dynamic::new(n), Const::<1>)) } /// Extracts from this matrix a set of consecutive columns. #[inline] pub fn $columns($me: $Me, first_col: usize, ncols: usize) - -> $MatrixSlice<'_, T, R, Dynamic, S::RStride, S::CStride> { + -> $MatrixView<'_, T, R, Dynamic, S::RStride, S::CStride> { $me.$columns_generic(first_col, Dynamic::new(ncols)) } @@ -426,7 +426,7 @@ macro_rules! matrix_slice_impl ( /// columns. #[inline] pub fn $columns_with_step($me: $Me, first_col: usize, ncols: usize, step: usize) - -> $MatrixSlice<'_, T, R, Dynamic, S::RStride, Dynamic> { + -> $MatrixView<'_, T, R, Dynamic, S::RStride, Dynamic> { $me.$columns_generic_with_step(first_col, Dynamic::new(ncols), step) } @@ -434,7 +434,7 @@ macro_rules! matrix_slice_impl ( /// Extracts a compile-time number of consecutive columns from this matrix. #[inline] pub fn $fixed_columns($me: $Me, first_col: usize) - -> $MatrixSlice<'_, T, R, Const, S::RStride, S::CStride> { + -> $MatrixView<'_, T, R, Const, S::RStride, S::CStride> { $me.$columns_generic(first_col, Const::) } @@ -443,7 +443,7 @@ macro_rules! matrix_slice_impl ( /// `step` columns. #[inline] pub fn $fixed_columns_with_step($me: $Me, first_col: usize, step: usize) - -> $MatrixSlice<'_, T, R, Const, S::RStride, Dynamic> { + -> $MatrixView<'_, T, R, Const, S::RStride, Dynamic> { $me.$columns_generic_with_step(first_col, Const::, step) } @@ -452,7 +452,7 @@ macro_rules! matrix_slice_impl ( /// known at compile-time. #[inline] pub fn $columns_generic($me: $Me, first_col: usize, ncols: CSlice) - -> $MatrixSlice<'_, T, R, CSlice, S::RStride, S::CStride> { + -> $MatrixView<'_, T, R, CSlice, S::RStride, S::CStride> { let my_shape = $me.shape_generic(); $me.assert_slice_index((0, first_col), (my_shape.0.value(), ncols.value()), (0, 0)); @@ -469,7 +469,7 @@ macro_rules! matrix_slice_impl ( /// or may not be values known at compile-time. #[inline] pub fn $columns_generic_with_step($me: $Me, first_col: usize, ncols: CSlice, step: usize) - -> $MatrixSlice<'_, T, R, CSlice, S::RStride, Dynamic> { + -> $MatrixView<'_, T, R, CSlice, S::RStride, Dynamic> { let my_shape = $me.shape_generic(); let my_strides = $me.data.strides(); @@ -494,7 +494,7 @@ macro_rules! matrix_slice_impl ( /// consecutive elements. #[inline] pub fn $slice($me: $Me, start: (usize, usize), shape: (usize, usize)) - -> $MatrixSlice<'_, T, Dynamic, Dynamic, S::RStride, S::CStride> { + -> $MatrixView<'_, T, Dynamic, Dynamic, S::RStride, S::CStride> { $me.assert_slice_index(start, shape, (0, 0)); let shape = (Dynamic::new(shape.0), Dynamic::new(shape.1)); @@ -512,7 +512,7 @@ macro_rules! matrix_slice_impl ( /// original matrix. #[inline] pub fn $slice_with_steps($me: $Me, start: (usize, usize), shape: (usize, usize), steps: (usize, usize)) - -> $MatrixSlice<'_, T, Dynamic, Dynamic, Dynamic, Dynamic> { + -> $MatrixView<'_, T, Dynamic, Dynamic, Dynamic, Dynamic> { let shape = (Dynamic::new(shape.0), Dynamic::new(shape.1)); $me.$generic_slice_with_steps(start, shape, steps) @@ -522,7 +522,7 @@ macro_rules! matrix_slice_impl ( /// CSlice::dim())` consecutive components. #[inline] pub fn $fixed_slice($me: $Me, irow: usize, icol: usize) - -> $MatrixSlice<'_, T, Const, Const, S::RStride, S::CStride> { + -> $MatrixView<'_, T, Const, Const, S::RStride, S::CStride> { $me.assert_slice_index((irow, icol), (RSLICE, CSLICE), (0, 0)); let shape = (Const::, Const::); @@ -539,7 +539,7 @@ macro_rules! matrix_slice_impl ( /// the original matrix. #[inline] pub fn $fixed_slice_with_steps($me: $Me, start: (usize, usize), steps: (usize, usize)) - -> $MatrixSlice<'_, T, Const, Const, Dynamic, Dynamic> { + -> $MatrixView<'_, T, Const, Const, Dynamic, Dynamic> { let shape = (Const::, Const::); $me.$generic_slice_with_steps(start, shape, steps) } @@ -547,7 +547,7 @@ macro_rules! matrix_slice_impl ( /// Creates a slice that may or may not have a fixed size and stride. #[inline] pub fn $generic_slice($me: $Me, start: (usize, usize), shape: (RSlice, CSlice)) - -> $MatrixSlice<'_, T, RSlice, CSlice, S::RStride, S::CStride> + -> $MatrixView<'_, T, RSlice, CSlice, S::RStride, S::CStride> where RSlice: Dim, CSlice: Dim { @@ -565,7 +565,7 @@ macro_rules! matrix_slice_impl ( start: (usize, usize), shape: (RSlice, CSlice), steps: (usize, usize)) - -> $MatrixSlice<'_, T, RSlice, CSlice, Dynamic, Dynamic> + -> $MatrixView<'_, T, RSlice, CSlice, Dynamic, Dynamic> where RSlice: Dim, CSlice: Dim { @@ -591,8 +591,8 @@ macro_rules! matrix_slice_impl ( /// Panics if the ranges overlap or if the first range is empty. #[inline] pub fn $rows_range_pair, Range2: SliceRange>($me: $Me, r1: Range1, r2: Range2) - -> ($MatrixSlice<'_, T, Range1::Size, C, S::RStride, S::CStride>, - $MatrixSlice<'_, T, Range2::Size, C, S::RStride, S::CStride>) { + -> ($MatrixView<'_, T, Range1::Size, C, S::RStride, S::CStride>, + $MatrixView<'_, T, Range2::Size, C, S::RStride, S::CStride>) { let (nrows, ncols) = $me.shape_generic(); let strides = $me.data.strides(); @@ -627,8 +627,8 @@ macro_rules! matrix_slice_impl ( /// Panics if the ranges overlap or if the first range is empty. #[inline] pub fn $columns_range_pair, Range2: SliceRange>($me: $Me, r1: Range1, r2: Range2) - -> ($MatrixSlice<'_, T, R, Range1::Size, S::RStride, S::CStride>, - $MatrixSlice<'_, T, R, Range2::Size, S::RStride, S::CStride>) { + -> ($MatrixView<'_, T, R, Range1::Size, S::RStride, S::CStride>, + $MatrixView<'_, T, R, Range2::Size, S::RStride, S::CStride>) { let (nrows, ncols) = $me.shape_generic(); let strides = $me.data.strides(); @@ -661,16 +661,37 @@ macro_rules! matrix_slice_impl ( ); /// A matrix slice. +/// +/// This type alias exists only for legacy purposes and is deprecated. It will be removed +/// in a future release. Please use [`MatrixView`] instead. +/// See [issue #1076](https://github.com/dimforge/nalgebra/issues/1076) +/// for the rationale. +#[deprecated = "Use MatrixView instead."] pub type MatrixSlice<'a, T, R, C, RStride = U1, CStride = R> = + MatrixView<'a, T, R, C, RStride, CStride>; + +/// A matrix view. +pub type MatrixView<'a, T, R, C, RStride = U1, CStride = R> = Matrix>; + /// A mutable matrix slice. +/// +/// This type alias exists only for legacy purposes and is deprecated. It will be removed +/// in a future release. Please use [`MatrixViewMut`] instead. +/// See [issue #1076](https://github.com/dimforge/nalgebra/issues/1076) +/// for the rationale. +#[deprecated = "Use MatrixViewMut instead."] pub type MatrixSliceMut<'a, T, R, C, RStride = U1, CStride = R> = + MatrixViewMut<'a, T, R, C, RStride, CStride>; + +/// A mutable matrix view. +pub type MatrixViewMut<'a, T, R, C, RStride = U1, CStride = R> = Matrix>; /// # Slicing based on index and length impl> Matrix { matrix_slice_impl!( - self: &Self, MatrixSlice, ViewStorage, RawStorage.get_address_unchecked(), &self.data; + self: &Self, MatrixView, ViewStorage, RawStorage.get_address_unchecked(), &self.data; row, row_part, rows, @@ -700,7 +721,7 @@ impl> Matrix { /// # Mutable slicing based on index and length impl> Matrix { matrix_slice_impl!( - self: &mut Self, MatrixSliceMut, ViewStorageMut, RawStorageMut.get_address_unchecked_mut(), &mut self.data; + self: &mut Self, MatrixViewMut, ViewStorageMut, RawStorageMut.get_address_unchecked_mut(), &mut self.data; row_mut, row_part_mut, rows_mut, @@ -872,7 +893,7 @@ impl> Matrix { &self, rows: RowRange, cols: ColRange, - ) -> MatrixSlice<'_, T, RowRange::Size, ColRange::Size, S::RStride, S::CStride> + ) -> MatrixView<'_, T, RowRange::Size, ColRange::Size, S::RStride, S::CStride> where RowRange: SliceRange, ColRange: SliceRange, @@ -890,7 +911,7 @@ impl> Matrix { pub fn rows_range>( &self, rows: RowRange, - ) -> MatrixSlice<'_, T, RowRange::Size, C, S::RStride, S::CStride> { + ) -> MatrixView<'_, T, RowRange::Size, C, S::RStride, S::CStride> { self.slice_range(rows, ..) } @@ -900,7 +921,7 @@ impl> Matrix { pub fn columns_range>( &self, cols: ColRange, - ) -> MatrixSlice<'_, T, R, ColRange::Size, S::RStride, S::CStride> { + ) -> MatrixView<'_, T, R, ColRange::Size, S::RStride, S::CStride> { self.slice_range(.., cols) } } @@ -914,7 +935,7 @@ impl> Matrix { &mut self, rows: RowRange, cols: ColRange, - ) -> MatrixSliceMut<'_, T, RowRange::Size, ColRange::Size, S::RStride, S::CStride> + ) -> MatrixViewMut<'_, T, RowRange::Size, ColRange::Size, S::RStride, S::CStride> where RowRange: SliceRange, ColRange: SliceRange, @@ -931,7 +952,7 @@ impl> Matrix { pub fn rows_range_mut>( &mut self, rows: RowRange, - ) -> MatrixSliceMut<'_, T, RowRange::Size, C, S::RStride, S::CStride> { + ) -> MatrixViewMut<'_, T, RowRange::Size, C, S::RStride, S::CStride> { self.slice_range_mut(rows, ..) } @@ -940,20 +961,20 @@ impl> Matrix { pub fn columns_range_mut>( &mut self, cols: ColRange, - ) -> MatrixSliceMut<'_, T, R, ColRange::Size, S::RStride, S::CStride> { + ) -> MatrixViewMut<'_, T, R, ColRange::Size, S::RStride, S::CStride> { self.slice_range_mut(.., cols) } } -impl<'a, T, R, C, RStride, CStride> From> - for MatrixSlice<'a, T, R, C, RStride, CStride> +impl<'a, T, R, C, RStride, CStride> From> + for MatrixView<'a, T, R, C, RStride, CStride> where R: Dim, C: Dim, RStride: Dim, CStride: Dim, { - fn from(slice_mut: MatrixSliceMut<'a, T, R, C, RStride, CStride>) -> Self { + fn from(slice_mut: MatrixViewMut<'a, T, R, C, RStride, CStride>) -> Self { let data = ViewStorage { ptr: slice_mut.data.ptr, shape: slice_mut.data.shape, diff --git a/src/geometry/quaternion.rs b/src/geometry/quaternion.rs index 293ab125..34eda897 100755 --- a/src/geometry/quaternion.rs +++ b/src/geometry/quaternion.rs @@ -14,7 +14,7 @@ use simba::simd::{SimdBool, SimdOption, SimdRealField}; use crate::base::dimension::{U1, U3, U4}; use crate::base::storage::{CStride, RStride}; use crate::base::{ - Matrix3, Matrix4, MatrixSlice, MatrixSliceMut, Normed, Scalar, Unit, Vector3, Vector4, + Matrix3, Matrix4, MatrixView, MatrixViewMut, Normed, Scalar, Unit, Vector3, Vector4, }; use crate::geometry::{Point3, Rotation}; @@ -191,7 +191,7 @@ where /// ``` #[inline] #[must_use] - pub fn vector(&self) -> MatrixSlice<'_, T, U3, U1, RStride, CStride> { + pub fn vector(&self) -> MatrixView<'_, T, U3, U1, RStride, CStride> { self.coords.fixed_rows::<3>(0) } @@ -584,7 +584,7 @@ where #[inline] pub fn vector_mut( &mut self, - ) -> MatrixSliceMut<'_, T, U3, U1, RStride, CStride> { + ) -> MatrixViewMut<'_, T, U3, U1, RStride, CStride> { self.coords.fixed_rows_mut::<3>(0) }