Skip to content

Commit

Permalink
Replace explicit types with Self where possible.
Browse files Browse the repository at this point in the history
  • Loading branch information
adamnemecek authored and sebcrozet committed Feb 16, 2019
1 parent fac709b commit 975d72f
Show file tree
Hide file tree
Showing 42 changed files with 163 additions and 163 deletions.
2 changes: 1 addition & 1 deletion nalgebra-lapack/src/cholesky.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ where DefaultAllocator: Allocator<N, D, D>
N::xpotrf(uplo, dim, m.as_mut_slice(), dim, &mut info);
lapack_check!(info);

Some(Cholesky { l: m })
Some(Self { l: m })
}

/// Retrieves the lower-triangular factor of the cholesky decomposition.
Expand Down
8 changes: 4 additions & 4 deletions nalgebra-lapack/src/eigen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ where DefaultAllocator: Allocator<N, D, D> + Allocator<N, D>
lapack_check!(info);

if wi.iter().all(|e| e.is_zero()) {
return Some(Eigen {
return Some(Self {
eigenvalues: wr,
left_eigenvectors: Some(vl),
eigenvectors: Some(vr),
Expand Down Expand Up @@ -156,7 +156,7 @@ where DefaultAllocator: Allocator<N, D, D> + Allocator<N, D>
lapack_check!(info);

if wi.iter().all(|e| e.is_zero()) {
return Some(Eigen {
return Some(Self {
eigenvalues: wr,
left_eigenvectors: Some(vl),
eigenvectors: None,
Expand Down Expand Up @@ -185,7 +185,7 @@ where DefaultAllocator: Allocator<N, D, D> + Allocator<N, D>
lapack_check!(info);

if wi.iter().all(|e| e.is_zero()) {
return Some(Eigen {
return Some(Self {
eigenvalues: wr,
left_eigenvectors: None,
eigenvectors: Some(vr),
Expand All @@ -212,7 +212,7 @@ where DefaultAllocator: Allocator<N, D, D> + Allocator<N, D>
lapack_check!(info);

if wi.iter().all(|e| e.is_zero()) {
return Some(Eigen {
return Some(Self {
eigenvalues: wr,
left_eigenvectors: None,
eigenvectors: None,
Expand Down
4 changes: 2 additions & 2 deletions nalgebra-lapack/src/hessenberg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl<N: HessenbergScalar + Zero, D: DimSub<U1>> Hessenberg<N, D>
where DefaultAllocator: Allocator<N, D, D> + Allocator<N, DimDiff<D, U1>>
{
/// Computes the hessenberg decomposition of the matrix `m`.
pub fn new(mut m: MatrixN<N, D>) -> Hessenberg<N, D> {
pub fn new(mut m: MatrixN<N, D>) -> Self {
let nrows = m.data.shape().0;
let n = nrows.value() as i32;

Expand Down Expand Up @@ -83,7 +83,7 @@ where DefaultAllocator: Allocator<N, D, D> + Allocator<N, DimDiff<D, U1>>
);
lapack_panic!(info);

Hessenberg { h: m, tau: tau }
Self { h: m, tau: tau }
}

/// Computes the hessenberg matrix of this decomposition.
Expand Down
2 changes: 1 addition & 1 deletion nalgebra-lapack/src/lu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ where
);
lapack_panic!(info);

LU { lu: m, p: ipiv }
Self { lu: m, p: ipiv }
}

/// Gets the lower-triangular matrix part of the decomposition.
Expand Down
6 changes: 3 additions & 3 deletions nalgebra-lapack/src/qr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ where DefaultAllocator: Allocator<N, R, C>
+ Allocator<N, DimMinimum<R, C>>
{
/// Computes the QR decomposition of the matrix `m`.
pub fn new(mut m: MatrixMN<N, R, C>) -> QR<N, R, C> {
pub fn new(mut m: MatrixMN<N, R, C>) -> Self {
let (nrows, ncols) = m.data.shape();

let mut info = 0;
let mut tau = unsafe { Matrix::new_uninitialized_generic(nrows.min(ncols), U1) };

if nrows.value() == 0 || ncols.value() == 0 {
return QR { qr: m, tau: tau };
return Self { qr: m, tau: tau };
}

let lwork = N::xgeqrf_work_size(
Expand All @@ -86,7 +86,7 @@ where DefaultAllocator: Allocator<N, R, C>
&mut info,
);

QR { qr: m, tau: tau }
Self { qr: m, tau: tau }
}

/// Retrieves the upper trapezoidal submatrix `R` of this decomposition.
Expand Down
2 changes: 1 addition & 1 deletion nalgebra-lapack/src/symmetric_eigen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ where DefaultAllocator: Allocator<N, D, D> + Allocator<N, D>
pub fn new(m: MatrixN<N, D>) -> Self {
let (vals, vecs) =
Self::do_decompose(m, true).expect("SymmetricEigen: convergence failure.");
SymmetricEigen {
Self {
eigenvalues: vals,
eigenvectors: vecs.unwrap(),
}
Expand Down
14 changes: 7 additions & 7 deletions src/base/dimension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ pub struct Dynamic {
impl Dynamic {
/// A dynamic size equal to `value`.
#[inline]
pub fn new(value: usize) -> Dynamic {
Dynamic { value: value }
pub fn new(value: usize) -> Self {
Self { value: value }
}
}

Expand Down Expand Up @@ -80,7 +80,7 @@ impl Dim for Dynamic {

#[inline]
fn from_usize(dim: usize) -> Self {
Dynamic::new(dim)
Self::new(dim)
}

#[inline]
Expand All @@ -93,17 +93,17 @@ impl Add<usize> for Dynamic {
type Output = Dynamic;

#[inline]
fn add(self, rhs: usize) -> Dynamic {
Dynamic::new(self.value + rhs)
fn add(self, rhs: usize) -> Self {
Self::new(self.value + rhs)
}
}

impl Sub<usize> for Dynamic {
type Output = Dynamic;

#[inline]
fn sub(self, rhs: usize) -> Dynamic {
Dynamic::new(self.value - rhs)
fn sub(self, rhs: usize) -> Self {
Self::new(self.value - rhs)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/base/matrix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ impl<N: Scalar, R: Dim, C: Dim, S> Matrix<N, R, C, S> {
impl<N: Scalar, R: Dim, C: Dim, S: Storage<N, R, C>> Matrix<N, R, C, S> {
/// Creates a new matrix with the given data.
#[inline]
pub fn from_data(data: S) -> Matrix<N, R, C, S> {
pub fn from_data(data: S) -> Self {
unsafe { Self::from_data_statically_unchecked(data) }
}

Expand Down
4 changes: 2 additions & 2 deletions src/base/matrix_alga.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ where
DefaultAllocator: Allocator<N, R, C>,
{
#[inline]
fn two_sided_inverse(&self) -> MatrixMN<N, R, C> {
fn two_sided_inverse(&self) -> Self {
-self
}

Expand Down Expand Up @@ -203,7 +203,7 @@ impl<N: Real, R: DimName, C: DimName> FiniteDimInnerSpace for MatrixMN<N, R, C>
where DefaultAllocator: Allocator<N, R, C>
{
#[inline]
fn orthonormalize(vs: &mut [MatrixMN<N, R, C>]) -> usize {
fn orthonormalize(vs: &mut [Self]) -> usize {
let mut nbasis_elements = 0;

for i in 0..vs.len() {
Expand Down
2 changes: 1 addition & 1 deletion src/base/matrix_slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl<'a, N: Scalar, R: Dim, C: Dim, RStride: Dim, CStride: Dim> Clone
{
#[inline]
fn clone(&self) -> Self {
SliceStorage {
Self {
ptr: self.ptr,
shape: self.shape,
strides: self.strides,
Expand Down
4 changes: 2 additions & 2 deletions src/base/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl<N: Scalar, R: Dim, C: Dim, S: Storage<N, R, C>> Index<usize> for Matrix<N,
type Output = N;

#[inline]
fn index(&self, i: usize) -> &N {
fn index(&self, i: usize) -> &Self::Output {
let ij = self.vector_to_matrix_index(i);
&self[ij]
}
Expand All @@ -38,7 +38,7 @@ where
type Output = N;

#[inline]
fn index(&self, ij: (usize, usize)) -> &N {
fn index(&self, ij: (usize, usize)) -> &Self::Output {
let shape = self.shape();
assert!(
ij.0 < shape.0 && ij.1 < shape.1,
Expand Down
4 changes: 2 additions & 2 deletions src/base/vec_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ pub type MatrixVec<N, R, C> = VecStorage<N, R, C>;
impl<N, R: Dim, C: Dim> VecStorage<N, R, C> {
/// Creates a new dynamic matrix data storage from the given vector and shape.
#[inline]
pub fn new(nrows: R, ncols: C, data: Vec<N>) -> VecStorage<N, R, C> {
pub fn new(nrows: R, ncols: C, data: Vec<N>) -> Self {
assert!(
nrows.value() * ncols.value() == data.len(),
"Data storage buffer dimension mismatch."
);
VecStorage {
Self {
data: data,
nrows: nrows,
ncols: ncols,
Expand Down
10 changes: 5 additions & 5 deletions src/geometry/isometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ where DefaultAllocator: Allocator<N, D>
{
#[inline]
fn clone(&self) -> Self {
Isometry::from_parts(self.translation.clone(), self.rotation.clone())
Self::from_parts(self.translation.clone(), self.rotation.clone())
}
}

Expand All @@ -122,8 +122,8 @@ where DefaultAllocator: Allocator<N, D>
/// assert_relative_eq!(iso * Point3::new(1.0, 2.0, 3.0), Point3::new(-1.0, 2.0, 0.0), epsilon = 1.0e-6);
/// ```
#[inline]
pub fn from_parts(translation: Translation<N, D>, rotation: R) -> Isometry<N, D, R> {
Isometry {
pub fn from_parts(translation: Translation<N, D>, rotation: R) -> Self {
Self {
rotation: rotation,
translation: translation,
_noconstruct: PhantomData,
Expand All @@ -144,7 +144,7 @@ where DefaultAllocator: Allocator<N, D>
/// assert_eq!(inv * (iso * pt), pt);
/// ```
#[inline]
pub fn inverse(&self) -> Isometry<N, D, R> {
pub fn inverse(&self) -> Self {
let mut res = self.clone();
res.inverse_mut();
res
Expand Down Expand Up @@ -306,7 +306,7 @@ where
DefaultAllocator: Allocator<N, D>,
{
#[inline]
fn eq(&self, right: &Isometry<N, D, R>) -> bool {
fn eq(&self, right: &Self) -> bool {
self.translation == right.translation && self.rotation == right.rotation
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/geometry/isometry_alga.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ where
type Translation = Translation<N, D>;

#[inline]
fn decompose(&self) -> (Translation<N, D>, R, Id, R) {
fn decompose(&self) -> (Self::Translation, R, Id, R) {
(
self.translation.clone(),
self.rotation.clone(),
Expand Down
6 changes: 3 additions & 3 deletions src/geometry/orthographic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl<N: Real> Copy for Orthographic3<N> {}
impl<N: Real> Clone for Orthographic3<N> {
#[inline]
fn clone(&self) -> Self {
Orthographic3::from_matrix_unchecked(self.matrix.clone())
Self::from_matrix_unchecked(self.matrix.clone())
}
}

Expand Down Expand Up @@ -57,7 +57,7 @@ impl<'a, N: Real + Deserialize<'a>> Deserialize<'a> for Orthographic3<N> {
where Des: Deserializer<'a> {
let matrix = Matrix4::<N>::deserialize(deserializer)?;

Ok(Orthographic3::from_matrix_unchecked(matrix))
Ok(Self::from_matrix_unchecked(matrix))
}
}

Expand Down Expand Up @@ -135,7 +135,7 @@ impl<N: Real> Orthographic3<N> {
/// ```
#[inline]
pub fn from_matrix_unchecked(matrix: Matrix4<N>) -> Self {
Orthographic3 { matrix: matrix }
Self { matrix: matrix }
}

/// Creates a new orthographic projection matrix from an aspect ratio and the vertical field of view.
Expand Down
8 changes: 4 additions & 4 deletions src/geometry/perspective.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl<N: Real> Copy for Perspective3<N> {}
impl<N: Real> Clone for Perspective3<N> {
#[inline]
fn clone(&self) -> Self {
Perspective3::from_matrix_unchecked(self.matrix.clone())
Self::from_matrix_unchecked(self.matrix.clone())
}
}

Expand Down Expand Up @@ -58,7 +58,7 @@ impl<'a, N: Real + Deserialize<'a>> Deserialize<'a> for Perspective3<N> {
where Des: Deserializer<'a> {
let matrix = Matrix4::<N>::deserialize(deserializer)?;

Ok(Perspective3::from_matrix_unchecked(matrix))
Ok(Self::from_matrix_unchecked(matrix))
}
}

Expand All @@ -75,7 +75,7 @@ impl<N: Real> Perspective3<N> {
);

let matrix = Matrix4::identity();
let mut res = Perspective3::from_matrix_unchecked(matrix);
let mut res = Self::from_matrix_unchecked(matrix);

res.set_fovy(fovy);
res.set_aspect(aspect);
Expand All @@ -93,7 +93,7 @@ impl<N: Real> Perspective3<N> {
/// projection.
#[inline]
pub fn from_matrix_unchecked(matrix: Matrix4<N>) -> Self {
Perspective3 { matrix: matrix }
Self { matrix: matrix }
}

/// Retrieves the inverse of the underlying homogeneous matrix.
Expand Down
6 changes: 3 additions & 3 deletions src/geometry/point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ where
where Des: Deserializer<'a> {
let coords = VectorN::<N, D>::deserialize(deserializer)?;

Ok(Point::from(coords))
Ok(Self::from(coords))
}
}

Expand Down Expand Up @@ -126,8 +126,8 @@ where DefaultAllocator: Allocator<N, D>
/// Creates a new point with the given coordinates.
#[deprecated(note = "Use Point::from(vector) instead.")]
#[inline]
pub fn from_coordinates(coords: VectorN<N, D>) -> Point<N, D> {
Point { coords: coords }
pub fn from_coordinates(coords: VectorN<N, D>) -> Self {
Self { coords: coords }
}

/// The dimension of this point.
Expand Down
6 changes: 3 additions & 3 deletions src/geometry/point_alga.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ where
{
#[inline]
fn meet(&self, other: &Self) -> Self {
Point::from(self.coords.meet(&other.coords))
Self::from(self.coords.meet(&other.coords))
}
}

Expand All @@ -65,7 +65,7 @@ where
{
#[inline]
fn join(&self, other: &Self) -> Self {
Point::from(self.coords.join(&other.coords))
Self::from(self.coords.join(&other.coords))
}
}

Expand All @@ -78,6 +78,6 @@ where
fn meet_join(&self, other: &Self) -> (Self, Self) {
let (meet, join) = self.coords.meet_join(&other.coords);

(Point::from(meet), Point::from(join))
(Self::from(meet), Self::from(join))
}
}

0 comments on commit 975d72f

Please sign in to comment.