Rename the matrix slice constructors from `::new_*` to `_from_slice_*`.

This commit is contained in:
sebcrozet 2018-04-27 07:53:08 +02:00 committed by Sébastien Crozet
parent fefba2ef4e
commit d89e3dbac6
3 changed files with 73 additions and 64 deletions

View File

@ -1,6 +1,6 @@
use core::{MatrixSliceMN, MatrixSliceMutMN, Scalar};
use core::dimension::{Dim, DimName, Dynamic, U1};
use core::matrix_slice::{SliceStorage, SliceStorageMut};
use core::{MatrixSliceMN, MatrixSliceMutMN, Scalar};
/*
*
@ -8,13 +8,14 @@ use core::matrix_slice::{SliceStorage, SliceStorageMut};
*
*/
impl<'a, N: Scalar, R: Dim, C: Dim, RStride: Dim, CStride: Dim>
MatrixSliceMN<'a, N, R, C, RStride, CStride> {
MatrixSliceMN<'a, N, R, C, RStride, CStride>
{
/// Creates, without bound-checking, a matrix slice from an array and with dimensions and strides specified by generic types instances.
///
///
/// This method is unsafe because the input data array is not checked to contain enough elements.
/// The generic types `R`, `C`, `RStride`, `CStride` can either be type-level integers or integers wrapped with `Dynamic::new()`.
#[inline]
pub unsafe fn new_with_strides_generic_unchecked(
pub unsafe fn from_slice_with_strides_generic_unchecked(
data: &'a [N],
start: usize,
nrows: R,
@ -31,11 +32,11 @@ impl<'a, N: Scalar, R: Dim, C: Dim, RStride: Dim, CStride: Dim>
}
/// Creates a matrix slice from an array and with dimensions and strides specified by generic types instances.
///
///
/// Panics if the input data array dose not contain enough elements.
/// The generic types `R`, `C`, `RStride`, `CStride` can either be type-level integers or integers wrapped with `Dynamic::new()`.
#[inline]
pub fn new_with_strides_generic(
pub fn from_slice_with_strides_generic(
data: &'a [N],
nrows: R,
ncols: C,
@ -51,19 +52,21 @@ impl<'a, N: Scalar, R: Dim, C: Dim, RStride: Dim, CStride: Dim>
"Matrix slice: input data buffer to small."
);
unsafe { Self::new_with_strides_generic_unchecked(data, 0, nrows, ncols, rstride, cstride) }
unsafe {
Self::from_slice_with_strides_generic_unchecked(data, 0, nrows, ncols, rstride, cstride)
}
}
}
impl<'a, N: Scalar, R: Dim, C: Dim, RStride: Dim, CStride: Dim>
MatrixSliceMutMN<'a, N, R, C, RStride, CStride> {
MatrixSliceMutMN<'a, N, R, C, RStride, CStride>
{
/// Creates, without bound-checking, a mutable matrix slice from an array and with dimensions and strides specified by generic types instances.
///
///
/// This method is unsafe because the input data array is not checked to contain enough elements.
/// The generic types `R`, `C`, `RStride`, `CStride` can either be type-level integers or integers wrapped with `Dynamic::new()`.
#[inline]
pub unsafe fn new_with_strides_generic_mut_unchecked(
pub unsafe fn from_slice_with_strides_generic_unchecked(
data: &'a mut [N],
start: usize,
nrows: R,
@ -80,11 +83,11 @@ impl<'a, N: Scalar, R: Dim, C: Dim, RStride: Dim, CStride: Dim>
}
/// Creates a mutable matrix slice from an array and with dimensions and strides specified by generic types instances.
///
///
/// Panics if the input data array dose not contain enough elements.
/// The generic types `R`, `C`, `RStride`, `CStride` can either be type-level integers or integers wrapped with `Dynamic::new()`.
#[inline]
pub fn new_with_strides_generic_mut(
pub fn from_slice_with_strides_generic(
data: &'a mut [N],
nrows: R,
ncols: C,
@ -101,53 +104,58 @@ impl<'a, N: Scalar, R: Dim, C: Dim, RStride: Dim, CStride: Dim>
);
unsafe {
Self::new_with_strides_generic_mut_unchecked(data, 0, nrows, ncols, rstride, cstride)
Self::from_slice_with_strides_generic_unchecked(data, 0, nrows, ncols, rstride, cstride)
}
}
}
impl<'a, N: Scalar, R: Dim, C: Dim> MatrixSliceMN<'a, N, R, C> {
/// Creates, without bound-checking, a matrix slice from an array and with dimensions specified by generic types instances.
///
///
/// This method is unsafe because the input data array is not checked to contain enough elements.
/// The generic types `R` and `C` can either be type-level integers or integers wrapped with `Dynamic::new()`.
#[inline]
pub unsafe fn new_generic_unchecked(data: &'a [N], start: usize, nrows: R, ncols: C) -> Self {
Self::new_with_strides_generic_unchecked(data, start, nrows, ncols, U1, nrows)
pub unsafe fn from_slice_generic_unchecked(
data: &'a [N],
start: usize,
nrows: R,
ncols: C,
) -> Self {
Self::from_slice_with_strides_generic_unchecked(data, start, nrows, ncols, U1, nrows)
}
/// Creates a matrix slice from an array and with dimensions and strides specified by generic types instances.
///
///
/// Panics if the input data array dose not contain enough elements.
/// The generic types `R` and `C` can either be type-level integers or integers wrapped with `Dynamic::new()`.
#[inline]
pub fn new_generic(data: &'a [N], nrows: R, ncols: C) -> Self {
Self::new_with_strides_generic(data, nrows, ncols, U1, nrows)
pub fn from_slice_generic(data: &'a [N], nrows: R, ncols: C) -> Self {
Self::from_slice_with_strides_generic(data, nrows, ncols, U1, nrows)
}
}
impl<'a, N: Scalar, R: Dim, C: Dim> MatrixSliceMutMN<'a, N, R, C> {
/// Creates, without bound-checking, a mutable matrix slice from an array and with dimensions specified by generic types instances.
///
///
/// This method is unsafe because the input data array is not checked to contain enough elements.
/// The generic types `R` and `C` can either be type-level integers or integers wrapped with `Dynamic::new()`.
#[inline]
pub unsafe fn new_generic_mut_unchecked(
pub unsafe fn from_slice_generic_unchecked(
data: &'a mut [N],
start: usize,
nrows: R,
ncols: C,
) -> Self {
Self::new_with_strides_generic_mut_unchecked(data, start, nrows, ncols, U1, nrows)
Self::from_slice_with_strides_generic_unchecked(data, start, nrows, ncols, U1, nrows)
}
/// Creates a mutable matrix slice from an array and with dimensions and strides specified by generic types instances.
///
///
/// Panics if the input data array dose not contain enough elements.
/// The generic types `R` and `C` can either be type-level integers or integers wrapped with `Dynamic::new()`.
#[inline]
pub fn new_generic_mut(data: &'a mut [N], nrows: R, ncols: C) -> Self {
Self::new_with_strides_generic_mut(data, nrows, ncols, U1, nrows)
pub fn from_slice_generic(data: &'a mut [N], nrows: R, ncols: C) -> Self {
Self::from_slice_with_strides_generic(data, nrows, ncols, U1, nrows)
}
}
@ -155,33 +163,33 @@ macro_rules! impl_constructors(
($($Dims: ty),*; $(=> $DimIdent: ident: $DimBound: ident),*; $($gargs: expr),*; $($args: ident),*) => {
impl<'a, N: Scalar, $($DimIdent: $DimBound),*> MatrixSliceMN<'a, N, $($Dims),*> {
/// Creates a new matrix slice from the given data array.
///
///
/// Panics if `data` does not contain enough elements.
#[inline]
pub fn new(data: &'a [N], $($args: usize),*) -> Self {
Self::new_generic(data, $($gargs),*)
pub fn from_slice(data: &'a [N], $($args: usize),*) -> Self {
Self::from_slice_generic(data, $($gargs),*)
}
/// Creates, without bound checking, a new matrix slice from the given data array.
#[inline]
pub unsafe fn new_unchecked(data: &'a [N], start: usize, $($args: usize),*) -> Self {
Self::new_generic_unchecked(data, start, $($gargs),*)
pub unsafe fn from_slice_unchecked(data: &'a [N], start: usize, $($args: usize),*) -> Self {
Self::from_slice_generic_unchecked(data, start, $($gargs),*)
}
}
impl<'a, N: Scalar, $($DimIdent: $DimBound, )*> MatrixSliceMN<'a, N, $($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.
#[inline]
pub fn new_with_strides(data: &'a [N], $($args: usize,)* rstride: usize, cstride: usize) -> Self {
Self::new_with_strides_generic(data, $($gargs,)* Dynamic::new(rstride), Dynamic::new(cstride))
pub fn from_slice_with_strides(data: &'a [N], $($args: usize,)* rstride: usize, cstride: usize) -> Self {
Self::from_slice_with_strides_generic(data, $($gargs,)* Dynamic::new(rstride), Dynamic::new(cstride))
}
/// Creates, without bound checking, a new matrix slice with the specified strides from the given data array.
#[inline]
pub unsafe fn new_with_strides_unchecked(data: &'a [N], start: usize, $($args: usize,)* rstride: usize, cstride: usize) -> Self {
Self::new_with_strides_generic_unchecked(data, start, $($gargs,)* Dynamic::new(rstride), Dynamic::new(cstride))
pub unsafe fn from_slice_with_strides_unchecked(data: &'a [N], start: usize, $($args: usize,)* rstride: usize, cstride: usize) -> Self {
Self::from_slice_with_strides_generic_unchecked(data, start, $($gargs,)* Dynamic::new(rstride), Dynamic::new(cstride))
}
}
}
@ -212,34 +220,34 @@ macro_rules! impl_constructors_mut(
($($Dims: ty),*; $(=> $DimIdent: ident: $DimBound: ident),*; $($gargs: expr),*; $($args: ident),*) => {
impl<'a, N: Scalar, $($DimIdent: $DimBound),*> MatrixSliceMutMN<'a, N, $($Dims),*> {
/// Creates a new mutable matrix slice from the given data array.
///
///
/// Panics if `data` does not contain enough elements.
#[inline]
pub fn new(data: &'a mut [N], $($args: usize),*) -> Self {
Self::new_generic_mut(data, $($gargs),*)
pub fn from_slice(data: &'a mut [N], $($args: usize),*) -> Self {
Self::from_slice_generic(data, $($gargs),*)
}
/// Creates, without bound checking, a new mutable matrix slice from the given data array.
#[inline]
pub unsafe fn new_unchecked(data: &'a mut [N], start: usize, $($args: usize),*) -> Self {
Self::new_generic_mut_unchecked(data, start, $($gargs),*)
pub unsafe fn from_slice_unchecked(data: &'a mut [N], start: usize, $($args: usize),*) -> Self {
Self::from_slice_generic_unchecked(data, start, $($gargs),*)
}
}
impl<'a, N: Scalar, $($DimIdent: $DimBound, )*> MatrixSliceMutMN<'a, N, $($Dims,)* Dynamic, Dynamic> {
/// Creates a new mutable matrix slice with the specified strides from the given data array.
///
///
/// Panics if `data` does not contain enough elements.
#[inline]
pub fn new_with_strides(data: &'a mut [N], $($args: usize,)* rstride: usize, cstride: usize) -> Self {
Self::new_with_strides_generic_mut(
pub fn from_slice_with_strides_mut(data: &'a mut [N], $($args: usize,)* rstride: usize, cstride: usize) -> Self {
Self::from_slice_with_strides_generic(
data, $($gargs,)* Dynamic::new(rstride), Dynamic::new(cstride))
}
/// Creates, without bound checking, a new mutable matrix slice with the specified strides from the given data array.
#[inline]
pub unsafe fn new_with_strides_unchecked(data: &'a mut [N], start: usize, $($args: usize,)* rstride: usize, cstride: usize) -> Self {
Self::new_with_strides_generic_mut_unchecked(
pub unsafe fn from_slice_with_strides_unchecked(data: &'a mut [N], start: usize, $($args: usize,)* rstride: usize, cstride: usize) -> Self {
Self::from_slice_with_strides_generic_unchecked(
data, start, $($gargs,)* Dynamic::new(rstride), Dynamic::new(cstride))
}
}

View File

@ -82,6 +82,7 @@ an optimized set of tools for computer graphics and physics. Those features incl
#![deny(unused_qualifications)]
#![deny(unused_results)]
#![deny(missing_docs)]
#![deny(incoherent_fundamental_impls)]
#![doc(html_root_url = "http://nalgebra.org/rustdoc")]
#[cfg(feature = "arbitrary")]
@ -111,22 +112,22 @@ extern crate typenum;
extern crate alga;
pub mod core;
pub mod linalg;
pub mod geometry;
#[cfg(feature = "debug")]
pub mod debug;
pub mod geometry;
pub mod linalg;
pub use core::*;
pub use linalg::*;
pub use geometry::*;
pub use linalg::*;
use std::cmp::{self, Ordering, PartialOrd};
use num::Signed;
use alga::general::{Additive, AdditiveGroup, Identity, Inverse, JoinSemilattice, Lattice,
MeetSemilattice, Multiplicative, SupersetOf};
use alga::linear::SquareMatrix as AlgaSquareMatrix;
use alga::linear::{EuclideanSpace, FiniteDimVectorSpace, InnerSpace, NormedSpace};
use num::Signed;
pub use alga::general::{Id, Real};

View File

@ -209,13 +209,13 @@ fn new_slice() {
let expected3x2 = Matrix3x2::from_column_slice(&data);
{
let m2 = MatrixSlice2::new(&data);
let m3 = MatrixSlice3::new(&data);
let m2x3 = MatrixSlice2x3::new(&data);
let m3x2 = MatrixSlice3x2::new(&data);
let m2xX = MatrixSlice2xX::new(&data, 3);
let mXx3 = MatrixSliceXx3::new(&data, 2);
let mXxX = DMatrixSlice::new(&data, 2, 3);
let m2 = MatrixSlice2::from_slice(&data);
let m3 = MatrixSlice3::from_slice(&data);
let m2x3 = MatrixSlice2x3::from_slice(&data);
let m3x2 = MatrixSlice3x2::from_slice(&data);
let m2xX = MatrixSlice2xX::from_slice(&data, 3);
let mXx3 = MatrixSliceXx3::from_slice(&data, 2);
let mXxX = DMatrixSlice::from_slice(&data, 2, 3);
assert!(m2.eq(&expected2));
assert!(m3.eq(&expected3));
@ -246,31 +246,31 @@ fn new_slice_mut() {
9.0, 10.0, 11.0, 12.0 ];
let mut data_mut = data.clone();
MatrixSliceMut2::new(&mut data_mut).fill(0.0);
MatrixSliceMut2::from_slice(&mut data_mut).fill(0.0);
assert!(data_mut == expected2);
let mut data_mut = data.clone();
MatrixSliceMut3::new(&mut data_mut).fill(0.0);
MatrixSliceMut3::from_slice(&mut data_mut).fill(0.0);
assert!(data_mut == expected3);
let mut data_mut = data.clone();
MatrixSliceMut2x3::new(&mut data_mut).fill(0.0);
MatrixSliceMut2x3::from_slice(&mut data_mut).fill(0.0);
assert!(data_mut == expected2x3);
let mut data_mut = data.clone();
MatrixSliceMut3x2::new(&mut data_mut).fill(0.0);
MatrixSliceMut3x2::from_slice(&mut data_mut).fill(0.0);
assert!(data_mut == expected3x2);
let mut data_mut = data.clone();
MatrixSliceMut2xX::new(&mut data_mut, 3).fill(0.0);
MatrixSliceMut2xX::from_slice(&mut data_mut, 3).fill(0.0);
assert!(data_mut == expected2x3);
let mut data_mut = data.clone();
MatrixSliceMutXx3::new(&mut data_mut, 2).fill(0.0);
MatrixSliceMutXx3::from_slice(&mut data_mut, 2).fill(0.0);
assert!(data_mut == expected2x3);
let mut data_mut = data.clone();
DMatrixSliceMut::new(&mut data_mut, 2, 3).fill(0.0);
DMatrixSliceMut::from_slice(&mut data_mut, 2, 3).fill(0.0);
assert!(data_mut == expected2x3);
}