clippy: fix len_without_is_empty warnings

This commit is contained in:
Philippe Renon 2020-11-19 12:24:26 +01:00
parent 6a5b418fbc
commit bbc6a28f7d
5 changed files with 49 additions and 17 deletions

View File

@ -298,20 +298,6 @@ impl<N: Scalar, R: Dim, C: Dim, S: Storage<N, R, C>> Matrix<N, R, C, S> {
unsafe { Self::from_data_statically_unchecked(data) }
}
/// The total number of elements of this matrix.
///
/// # Examples:
///
/// ```
/// # use nalgebra::Matrix3x4;
/// let mat = Matrix3x4::<f32>::zeros();
/// assert_eq!(mat.len(), 12);
#[inline]
pub fn len(&self) -> usize {
let (nrows, ncols) = self.shape();
nrows * ncols
}
/// The shape of this matrix returned as the tuple (number of rows, number of columns).
///
/// # Examples:

View File

@ -10,11 +10,33 @@ use crate::base::storage::Storage;
use crate::base::{DefaultAllocator, Matrix, Scalar, SquareMatrix};
impl<N: Scalar, R: Dim, C: Dim, S: Storage<N, R, C>> Matrix<N, R, C, S> {
/// Indicates if this is an empty matrix.
/// The total number of elements of this matrix.
///
/// # Examples:
///
/// ```
/// # use nalgebra::Matrix3x4;
/// let mat = Matrix3x4::<f32>::zeros();
/// assert_eq!(mat.len(), 12);
/// ```
#[inline]
pub fn len(&self) -> usize {
let (nrows, ncols) = self.shape();
nrows * ncols
}
/// Returns true if the matrix contains no elements.
///
/// # Examples:
///
/// ```
/// # use nalgebra::Matrix3x4;
/// let mat = Matrix3x4::<f32>::zeros();
/// assert!(!mat.is_empty());
/// ```
#[inline]
pub fn is_empty(&self) -> bool {
let (nrows, ncols) = self.shape();
nrows == 0 || ncols == 0
self.len() == 0
}
/// Indicates if this is a square matrix.

View File

@ -85,6 +85,12 @@ impl<N, R: Dim, C: Dim> VecStorage<N, R, C> {
pub fn len(&self) -> usize {
self.data.len()
}
/// Returns true if the underlying vector contains no elements.
#[inline]
pub fn is_empty(&self) -> bool {
self.len() == 0
}
}
impl<N, R: Dim, C: Dim> Into<Vec<N>> for VecStorage<N, R, C> {

View File

@ -194,6 +194,19 @@ where
self.coords.len()
}
/// Returns true if the point contains no elements.
///
/// # Example
/// ```
/// # use nalgebra::{Point2, Point3};
/// let p = Point2::new(1.0, 2.0);
/// assert!(!p.is_empty());
/// ```
#[inline]
pub fn is_empty(&self) -> bool {
self.len() == 0
}
/// The stride of this point. This is the number of buffer element separating each component of
/// this point.
#[inline]

View File

@ -144,6 +144,11 @@ where
self.len
}
/// Returns true if the permutation sequence contains no elements.
pub fn is_empty(&self) -> bool {
self.len() == 0
}
/// The determinant of the matrix corresponding to this permutation.
#[inline]
pub fn determinant<N: One + ClosedNeg>(&self) -> N {