Replace explicit types with Self where possible.

This commit is contained in:
adamnemecek 2019-02-16 13:29:41 -08:00 committed by Sébastien Crozet
parent fac709b0c0
commit 975d72f070
42 changed files with 163 additions and 163 deletions

View File

@ -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.

View File

@ -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),
@ -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,
@ -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),
@ -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,

View File

@ -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;
@ -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.

View File

@ -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.

View File

@ -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(
@ -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.

View File

@ -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(),
}

View File

@ -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 }
}
}
@ -80,7 +80,7 @@ impl Dim for Dynamic {
#[inline]
fn from_usize(dim: usize) -> Self {
Dynamic::new(dim)
Self::new(dim)
}
#[inline]
@ -93,8 +93,8 @@ 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)
}
}
@ -102,8 +102,8 @@ 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)
}
}

View File

@ -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) }
}

View File

@ -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
}
@ -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() {

View File

@ -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,

View File

@ -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]
}
@ -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,

View File

@ -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,

View File

@ -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())
}
}
@ -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,
@ -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
@ -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
}
}

View File

@ -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(),

View File

@ -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())
}
}
@ -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))
}
}
@ -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.

View File

@ -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())
}
}
@ -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))
}
}
@ -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);
@ -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.

View File

@ -66,7 +66,7 @@ where
where Des: Deserializer<'a> {
let coords = VectorN::<N, D>::deserialize(deserializer)?;
Ok(Point::from(coords))
Ok(Self::from(coords))
}
}
@ -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.

View File

@ -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))
}
}
@ -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))
}
}
@ -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))
}
}

View File

@ -145,7 +145,7 @@ where
{
#[inline]
fn arbitrary<G: Gen>(g: &mut G) -> Self {
Point::from(VectorN::arbitrary(g))
Self::from(VectorN::arbitrary(g))
}
}
@ -163,7 +163,7 @@ macro_rules! componentwise_constructors_impl(
#[doc = $doc]
#[doc = "```"]
#[inline]
pub fn new($($args: N),*) -> Point<N, $D> {
pub fn new($($args: N),*) -> Self {
unsafe {
let mut res = Self::new_uninitialized();
$( *res.get_unchecked_mut($irow) = $args; )*
@ -194,7 +194,7 @@ macro_rules! from_array_impl(
($($D: ty, $len: expr);*) => {$(
impl <N: Scalar> From<[N; $len]> for Point<N, $D> {
fn from (coords: [N; $len]) -> Self {
Point {
Self {
coords: coords.into()
}
}

View File

@ -45,7 +45,7 @@ where
#[inline]
unsafe fn from_superset_unchecked(m: &Point<N2, D>) -> Self {
Point::from(Matrix::from_superset_unchecked(&m.coords))
Self::from(Matrix::from_superset_unchecked(&m.coords))
}
}

View File

@ -46,11 +46,11 @@ where DefaultAllocator: Allocator<N, D>
impl<N: Scalar + ClosedNeg, D: DimName> Neg for Point<N, D>
where DefaultAllocator: Allocator<N, D>
{
type Output = Point<N, D>;
type Output = Self;
#[inline]
fn neg(self) -> Self::Output {
Point::from(-self.coords)
Self::Output::from(-self.coords)
}
}
@ -61,7 +61,7 @@ where DefaultAllocator: Allocator<N, D>
#[inline]
fn neg(self) -> Self::Output {
Point::from(-&self.coords)
Self::Output::from(-&self.coords)
}
}

View File

@ -68,7 +68,7 @@ impl<N: Real> Copy for Quaternion<N> {}
impl<N: Real> Clone for Quaternion<N> {
#[inline]
fn clone(&self) -> Self {
Quaternion::from(self.coords.clone())
Self::from(self.coords.clone())
}
}
@ -90,7 +90,7 @@ where Owned<N, U4>: Deserialize<'a>
where Des: Deserializer<'a> {
let coords = Vector4::<N>::deserialize(deserializer)?;
Ok(Quaternion::from(coords))
Ok(Self::from(coords))
}
}
@ -98,15 +98,15 @@ impl<N: Real> Quaternion<N> {
/// Moves this unit quaternion into one that owns its data.
#[inline]
#[deprecated(note = "This method is a no-op and will be removed in a future release.")]
pub fn into_owned(self) -> Quaternion<N> {
pub fn into_owned(self) -> Self {
self
}
/// Clones this unit quaternion into one that owns its data.
#[inline]
#[deprecated(note = "This method is a no-op and will be removed in a future release.")]
pub fn clone_owned(&self) -> Quaternion<N> {
Quaternion::from(self.coords.clone_owned())
pub fn clone_owned(&self) -> Self {
Self::from(self.coords.clone_owned())
}
/// Normalizes this quaternion.
@ -120,8 +120,8 @@ impl<N: Real> Quaternion<N> {
/// relative_eq!(q_normalized.norm(), 1.0);
/// ```
#[inline]
pub fn normalize(&self) -> Quaternion<N> {
Quaternion::from(self.coords.normalize())
pub fn normalize(&self) -> Self {
Self::from(self.coords.normalize())
}
/// The conjugate of this quaternion.
@ -134,14 +134,14 @@ impl<N: Real> Quaternion<N> {
/// assert!(conj.i == -2.0 && conj.j == -3.0 && conj.k == -4.0 && conj.w == 1.0);
/// ```
#[inline]
pub fn conjugate(&self) -> Quaternion<N> {
pub fn conjugate(&self) -> Self {
let v = Vector4::new(
-self.coords[0],
-self.coords[1],
-self.coords[2],
self.coords[3],
);
Quaternion::from(v)
Self::from(v)
}
/// Inverts this quaternion if it is not zero.
@ -163,8 +163,8 @@ impl<N: Real> Quaternion<N> {
/// assert!(inv_q.is_none());
/// ```
#[inline]
pub fn try_inverse(&self) -> Option<Quaternion<N>> {
let mut res = Quaternion::from(self.coords.clone_owned());
pub fn try_inverse(&self) -> Option<Self> {
let mut res = Self::from(self.coords.clone_owned());
if res.try_inverse_mut() {
Some(res)
@ -186,7 +186,7 @@ impl<N: Real> Quaternion<N> {
/// assert_eq!(q1.lerp(&q2, 0.1), Quaternion::new(1.9, 3.8, 5.7, 7.6));
/// ```
#[inline]
pub fn lerp(&self, other: &Quaternion<N>, t: N) -> Quaternion<N> {
pub fn lerp(&self, other: &Self, t: N) -> Self {
self * (N::one() - t) + other * t
}
@ -346,12 +346,12 @@ impl<N: Real> Quaternion<N> {
/// assert_relative_eq!(q.ln(), Quaternion::new(1.683647, 1.190289, 0.0, 0.0), epsilon = 1.0e-6)
/// ```
#[inline]
pub fn ln(&self) -> Quaternion<N> {
pub fn ln(&self) -> Self {
let n = self.norm();
let v = self.vector();
let s = self.scalar();
Quaternion::from_parts(n.ln(), v.normalize() * (s / n).acos())
Self::from_parts(n.ln(), v.normalize() * (s / n).acos())
}
/// Compute the exponential of a quaternion.
@ -364,7 +364,7 @@ impl<N: Real> Quaternion<N> {
/// assert_relative_eq!(q.exp(), Quaternion::new(2.0, 5.0, 0.0, 0.0), epsilon = 1.0e-5)
/// ```
#[inline]
pub fn exp(&self) -> Quaternion<N> {
pub fn exp(&self) -> Self {
self.exp_eps(N::default_epsilon())
}
@ -383,18 +383,18 @@ impl<N: Real> Quaternion<N> {
/// assert_eq!(q.exp_eps(1.0e-6), Quaternion::identity());
/// ```
#[inline]
pub fn exp_eps(&self, eps: N) -> Quaternion<N> {
pub fn exp_eps(&self, eps: N) -> Self {
let v = self.vector();
let nn = v.norm_squared();
if nn <= eps * eps {
Quaternion::identity()
Self::identity()
} else {
let w_exp = self.scalar().exp();
let n = nn.sqrt();
let nv = v * (w_exp * n.sin() / n);
Quaternion::from_parts(w_exp * n.cos(), nv)
Self::from_parts(w_exp * n.cos(), nv)
}
}
@ -408,7 +408,7 @@ impl<N: Real> Quaternion<N> {
/// assert_relative_eq!(q.powf(1.5), Quaternion::new( -6.2576659, 4.1549037, 6.2323556, 8.3098075), epsilon = 1.0e-6);
/// ```
#[inline]
pub fn powf(&self, n: N) -> Quaternion<N> {
pub fn powf(&self, n: N) -> Self {
(self.ln() * n).exp()
}
@ -577,7 +577,7 @@ impl<N: Real> UnitQuaternion<N> {
#[deprecated(
note = "This method is unnecessary and will be removed in a future release. Use `.clone()` instead."
)]
pub fn into_owned(self) -> UnitQuaternion<N> {
pub fn into_owned(self) -> Self {
self
}
@ -586,7 +586,7 @@ impl<N: Real> UnitQuaternion<N> {
#[deprecated(
note = "This method is unnecessary and will be removed in a future release. Use `.clone()` instead."
)]
pub fn clone_owned(&self) -> UnitQuaternion<N> {
pub fn clone_owned(&self) -> Self {
*self
}
@ -637,8 +637,8 @@ impl<N: Real> UnitQuaternion<N> {
/// assert_eq!(conj, UnitQuaternion::from_axis_angle(&-axis, 1.78));
/// ```
#[inline]
pub fn conjugate(&self) -> UnitQuaternion<N> {
UnitQuaternion::new_unchecked(self.as_ref().conjugate())
pub fn conjugate(&self) -> Self {
Self::new_unchecked(self.as_ref().conjugate())
}
/// Inverts this quaternion if it is not zero.
@ -653,7 +653,7 @@ impl<N: Real> UnitQuaternion<N> {
/// assert_eq!(inv * rot, UnitQuaternion::identity());
/// ```
#[inline]
pub fn inverse(&self) -> UnitQuaternion<N> {
pub fn inverse(&self) -> Self {
self.conjugate()
}
@ -668,7 +668,7 @@ impl<N: Real> UnitQuaternion<N> {
/// assert_relative_eq!(rot1.angle_to(&rot2), 1.0045657, epsilon = 1.0e-6);
/// ```
#[inline]
pub fn angle_to(&self, other: &UnitQuaternion<N>) -> N {
pub fn angle_to(&self, other: &Self) -> N {
let delta = self.rotation_to(other);
delta.angle()
}
@ -687,7 +687,7 @@ impl<N: Real> UnitQuaternion<N> {
/// assert_relative_eq!(rot_to * rot1, rot2, epsilon = 1.0e-6);
/// ```
#[inline]
pub fn rotation_to(&self, other: &UnitQuaternion<N>) -> UnitQuaternion<N> {
pub fn rotation_to(&self, other: &Self) -> Self{
other / self
}
@ -703,7 +703,7 @@ impl<N: Real> UnitQuaternion<N> {
/// assert_eq!(q1.lerp(&q2, 0.1), Quaternion::new(0.9, 0.1, 0.0, 0.0));
/// ```
#[inline]
pub fn lerp(&self, other: &UnitQuaternion<N>, t: N) -> Quaternion<N> {
pub fn lerp(&self, other: &Self, t: N) -> Quaternion<N> {
self.as_ref().lerp(other.as_ref(), t)
}
@ -719,11 +719,11 @@ impl<N: Real> UnitQuaternion<N> {
/// assert_eq!(q1.nlerp(&q2, 0.1), UnitQuaternion::new_normalize(Quaternion::new(0.9, 0.1, 0.0, 0.0)));
/// ```
#[inline]
pub fn nlerp(&self, other: &UnitQuaternion<N>, t: N) -> UnitQuaternion<N> {
pub fn nlerp(&self, other: &Self, t: N) -> Self {
let mut res = self.lerp(other, t);
let _ = res.normalize_mut();
UnitQuaternion::new_unchecked(res)
Self::new_unchecked(res)
}
/// Spherical linear interpolation between two unit quaternions.
@ -731,7 +731,7 @@ impl<N: Real> UnitQuaternion<N> {
/// Panics if the angle between both quaternion is 180 degrees (in which case the interpolation
/// is not well-defined). Use `.try_slerp` instead to avoid the panic.
#[inline]
pub fn slerp(&self, other: &UnitQuaternion<N>, t: N) -> UnitQuaternion<N> {
pub fn slerp(&self, other: &Self, t: N) -> Self {
Unit::new_unchecked(Quaternion::from(
Unit::new_unchecked(self.coords)
.slerp(&Unit::new_unchecked(other.coords), t)
@ -752,10 +752,10 @@ impl<N: Real> UnitQuaternion<N> {
#[inline]
pub fn try_slerp(
&self,
other: &UnitQuaternion<N>,
other: &Self,
t: N,
epsilon: N,
) -> Option<UnitQuaternion<N>>
) -> Option<Self>
{
Unit::new_unchecked(self.coords)
.try_slerp(&Unit::new_unchecked(other.coords), t, epsilon)
@ -902,11 +902,11 @@ impl<N: Real> UnitQuaternion<N> {
/// assert_eq!(pow.angle(), 2.4);
/// ```
#[inline]
pub fn powf(&self, n: N) -> UnitQuaternion<N> {
pub fn powf(&self, n: N) -> Self {
if let Some(v) = self.axis() {
UnitQuaternion::from_axis_angle(&v, self.angle() * n)
Self::from_axis_angle(&v, self.angle() * n)
} else {
UnitQuaternion::identity()
Self::identity()
}
}

View File

@ -25,7 +25,7 @@ impl<N: Real> Quaternion<N> {
#[inline]
#[deprecated(note = "Use `::from` instead.")]
pub fn from_vector(vector: Vector4<N>) -> Self {
Quaternion { coords: vector }
Self { coords: vector }
}
/// Creates a new quaternion from its individual components. Note that the arguments order does
@ -130,7 +130,7 @@ where Owned<N, U4>: Send
{
#[inline]
fn arbitrary<G: Gen>(g: &mut G) -> Self {
Quaternion::new(
Self::new(
N::arbitrary(g),
N::arbitrary(g),
N::arbitrary(g),
@ -683,7 +683,7 @@ where
#[inline]
fn arbitrary<G: Gen>(g: &mut G) -> Self {
let axisangle = Vector3::arbitrary(g);
UnitQuaternion::from_scaled_axis(axisangle)
Self::from_scaled_axis(axisangle)
}
}

View File

@ -103,7 +103,7 @@ impl<N1, N2, R> SubsetOf<Isometry<N2, U3, R>> for UnitQuaternion<N1>
where
N1: Real,
N2: Real + SupersetOf<N1>,
R: AlgaRotation<Point3<N2>> + SupersetOf<UnitQuaternion<N1>>,
R: AlgaRotation<Point3<N2>> + SupersetOf<Self>,
{
#[inline]
fn to_superset(&self) -> Isometry<N2, U3, R> {
@ -125,7 +125,7 @@ impl<N1, N2, R> SubsetOf<Similarity<N2, U3, R>> for UnitQuaternion<N1>
where
N1: Real,
N2: Real + SupersetOf<N1>,
R: AlgaRotation<Point3<N2>> + SupersetOf<UnitQuaternion<N1>>,
R: AlgaRotation<Point3<N2>> + SupersetOf<Self>,
{
#[inline]
fn to_superset(&self) -> Similarity<N2, U3, R> {
@ -186,7 +186,7 @@ impl<N1: Real, N2: Real + SupersetOf<N1>> SubsetOf<Matrix4<N2>> for UnitQuaterni
#[cfg(feature = "mint")]
impl<N: Real> From<mint::Quaternion<N>> for Quaternion<N> {
fn from(q: mint::Quaternion<N>) -> Self {
Quaternion::new(q.s, q.v.x, q.v.y, q.v.z)
Self::new(q.s, q.v.x, q.v.y, q.v.z)
}
}
@ -220,14 +220,14 @@ impl<N: Real> Into<mint::Quaternion<N>> for UnitQuaternion<N> {
impl<N: Real> From<UnitQuaternion<N>> for Matrix4<N> {
#[inline]
fn from(q: UnitQuaternion<N>) -> Matrix4<N> {
fn from(q: UnitQuaternion<N>) -> Self {
q.to_homogeneous()
}
}
impl<N: Real> From<UnitQuaternion<N>> for Matrix3<N> {
#[inline]
fn from(q: UnitQuaternion<N>) -> Matrix3<N> {
fn from(q: UnitQuaternion<N>) -> Self {
q.to_rotation_matrix().into_inner()
}
}
@ -235,6 +235,6 @@ impl<N: Real> From<UnitQuaternion<N>> for Matrix3<N> {
impl<N: Real> From<Vector4<N>> for Quaternion<N> {
#[inline]
fn from(coords: Vector4<N>) -> Self {
Quaternion { coords }
Self { coords }
}
}

View File

@ -67,7 +67,7 @@ impl<N: Real> Index<usize> for Quaternion<N> {
type Output = N;
#[inline]
fn index(&self, i: usize) -> &N {
fn index(&self, i: usize) -> &Self::Output {
&self.coords[i]
}
}

View File

@ -18,8 +18,8 @@ impl<N: Real, D: Dim, S: Storage<N, D>> Reflection<N, D, S> {
///
/// The bias is the position of the plane on the axis. In particular, a bias equal to zero
/// represents a plane that passes through the origin.
pub fn new(axis: Unit<Vector<N, D, S>>, bias: N) -> Reflection<N, D, S> {
Reflection {
pub fn new(axis: Unit<Vector<N, D, S>>, bias: N) -> Self {
Self {
axis: axis.into_inner(),
bias: bias,
}
@ -30,7 +30,7 @@ impl<N: Real, D: Dim, S: Storage<N, D>> Reflection<N, D, S> {
pub fn new_containing_point(
axis: Unit<Vector<N, D, S>>,
pt: &Point<N, D>,
) -> Reflection<N, D, S>
) -> Self
where
D: DimName,
DefaultAllocator: Allocator<N, D>,

View File

@ -53,7 +53,7 @@ where
{
#[inline]
fn clone(&self) -> Self {
Rotation::from_matrix_unchecked(self.matrix.clone())
Self::from_matrix_unchecked(self.matrix.clone())
}
}
@ -100,7 +100,7 @@ where
where Des: Deserializer<'a> {
let matrix = MatrixN::<N, D>::deserialize(deserializer)?;
Ok(Rotation::from_matrix_unchecked(matrix))
Ok(Self::from_matrix_unchecked(matrix))
}
}
@ -241,13 +241,13 @@ where DefaultAllocator: Allocator<N, D, D>
/// assert_eq!(*rot.matrix(), mat);
/// ```
#[inline]
pub fn from_matrix_unchecked(matrix: MatrixN<N, D>) -> Rotation<N, D> {
pub fn from_matrix_unchecked(matrix: MatrixN<N, D>) -> Self {
assert!(
matrix.is_square(),
"Unable to create a rotation from a non-square matrix."
);
Rotation { matrix: matrix }
Self { matrix: matrix }
}
/// Transposes `self`.
@ -269,8 +269,8 @@ where DefaultAllocator: Allocator<N, D, D>
/// assert_relative_eq!(tr_rot * rot, Rotation2::identity(), epsilon = 1.0e-6);
/// ```
#[inline]
pub fn transpose(&self) -> Rotation<N, D> {
Rotation::from_matrix_unchecked(self.matrix.transpose())
pub fn transpose(&self) -> Self {
Self::from_matrix_unchecked(self.matrix.transpose())
}
/// Inverts `self`.
@ -292,7 +292,7 @@ where DefaultAllocator: Allocator<N, D, D>
/// assert_relative_eq!(inv * rot, Rotation2::identity(), epsilon = 1.0e-6);
/// ```
#[inline]
pub fn inverse(&self) -> Rotation<N, D> {
pub fn inverse(&self) -> Self {
self.transpose()
}
@ -357,7 +357,7 @@ impl<N: Scalar + PartialEq, D: DimName> PartialEq for Rotation<N, D>
where DefaultAllocator: Allocator<N, D, D>
{
#[inline]
fn eq(&self, right: &Rotation<N, D>) -> bool {
fn eq(&self, right: &Self) -> bool {
self.matrix == right.matrix
}
}

View File

@ -102,7 +102,7 @@ impl<N1, N2, D: DimName, R> SubsetOf<Isometry<N2, D, R>> for Rotation<N1, D>
where
N1: Real,
N2: Real + SupersetOf<N1>,
R: AlgaRotation<Point<N2, D>> + SupersetOf<Rotation<N1, D>>,
R: AlgaRotation<Point<N2, D>> + SupersetOf<Self>,
DefaultAllocator: Allocator<N1, D, D> + Allocator<N2, D>,
{
#[inline]
@ -125,7 +125,7 @@ impl<N1, N2, D: DimName, R> SubsetOf<Similarity<N2, D, R>> for Rotation<N1, D>
where
N1: Real,
N2: Real + SupersetOf<N1>,
R: AlgaRotation<Point<N2, D>> + SupersetOf<Rotation<N1, D>>,
R: AlgaRotation<Point<N2, D>> + SupersetOf<Self>,
DefaultAllocator: Allocator<N1, D, D> + Allocator<N2, D>,
{
#[inline]
@ -219,28 +219,28 @@ impl<N: Real> From<mint::EulerAngles<N, mint::IntraXYZ>> for Rotation3<N> {
impl<N: Real> From<Rotation2<N>> for Matrix3<N> {
#[inline]
fn from(q: Rotation2<N>) -> Matrix3<N> {
fn from(q: Rotation2<N>) ->Self {
q.to_homogeneous()
}
}
impl<N: Real> From<Rotation2<N>> for Matrix2<N> {
#[inline]
fn from(q: Rotation2<N>) -> Matrix2<N> {
fn from(q: Rotation2<N>) -> Self {
q.into_inner()
}
}
impl<N: Real> From<Rotation3<N>> for Matrix4<N> {
#[inline]
fn from(q: Rotation3<N>) -> Matrix4<N> {
fn from(q: Rotation3<N>) -> Self {
q.to_homogeneous()
}
}
impl<N: Real> From<Rotation3<N>> for Matrix3<N> {
#[inline]
fn from(q: Rotation3<N>) -> Matrix3<N> {
fn from(q: Rotation3<N>) -> Self {
q.into_inner()
}
}

View File

@ -125,7 +125,7 @@ impl<N: Real> Rotation2<N> {
/// assert_relative_eq!(rot1.angle_to(&rot2), 1.6);
/// ```
#[inline]
pub fn angle_to(&self, other: &Rotation2<N>) -> N {
pub fn angle_to(&self, other: &Self) -> N {
self.rotation_to(other).angle()
}
@ -145,7 +145,7 @@ impl<N: Real> Rotation2<N> {
/// assert_relative_eq!(rot_to.inverse() * rot2, rot1);
/// ```
#[inline]
pub fn rotation_to(&self, other: &Rotation2<N>) -> Rotation2<N> {
pub fn rotation_to(&self, other: &Self) -> Self {
other * self.inverse()
}
@ -161,7 +161,7 @@ impl<N: Real> Rotation2<N> {
/// assert_relative_eq!(pow.angle(), 2.0 * 0.78);
/// ```
#[inline]
pub fn powf(&self, n: N) -> Rotation2<N> {
pub fn powf(&self, n: N) -> Self {
Self::new(self.angle() * n)
}
@ -655,7 +655,7 @@ impl<N: Real> Rotation3<N> {
/// assert_relative_eq!(rot1.angle_to(&rot2), 1.0045657, epsilon = 1.0e-6);
/// ```
#[inline]
pub fn angle_to(&self, other: &Rotation3<N>) -> N {
pub fn angle_to(&self, other: &Self) -> N {
self.rotation_to(other).angle()
}
@ -673,7 +673,7 @@ impl<N: Real> Rotation3<N> {
/// assert_relative_eq!(rot_to * rot1, rot2, epsilon = 1.0e-6);
/// ```
#[inline]
pub fn rotation_to(&self, other: &Rotation3<N>) -> Rotation3<N> {
pub fn rotation_to(&self, other: &Self) -> Self {
other * self.inverse()
}
@ -692,7 +692,7 @@ impl<N: Real> Rotation3<N> {
/// assert_eq!(pow.angle(), 2.4);
/// ```
#[inline]
pub fn powf(&self, n: N) -> Rotation3<N> {
pub fn powf(&self, n: N) -> Self {
if let Some(axis) = self.axis() {
Self::from_axis_angle(&axis, self.angle() * n)
} else if self.matrix()[(0, 0)] < N::zero() {

View File

@ -106,20 +106,20 @@ where
translation: Translation<N, D>,
rotation: R,
scaling: N,
) -> Similarity<N, D, R>
) -> Self
{
Similarity::from_isometry(Isometry::from_parts(translation, rotation), scaling)
Self::from_isometry(Isometry::from_parts(translation, rotation), scaling)
}
/// Creates a new similarity from its rotational and translational parts.
#[inline]
pub fn from_isometry(isometry: Isometry<N, D, R>, scaling: N) -> Similarity<N, D, R> {
pub fn from_isometry(isometry: Isometry<N, D, R>, scaling: N) -> Self {
assert!(
!relative_eq!(scaling, N::zero()),
"The scaling factor must not be zero."
);
Similarity {
Self {
isometry: isometry,
scaling: scaling,
}
@ -127,13 +127,13 @@ where
/// Creates a new similarity that applies only a scaling factor.
#[inline]
pub fn from_scaling(scaling: N) -> Similarity<N, D, R> {
pub fn from_scaling(scaling: N) -> Self {
Self::from_isometry(Isometry::identity(), scaling)
}
/// Inverts `self`.
#[inline]
pub fn inverse(&self) -> Similarity<N, D, R> {
pub fn inverse(&self) -> Self {
let mut res = self.clone();
res.inverse_mut();
res
@ -277,7 +277,7 @@ where
DefaultAllocator: Allocator<N, D>,
{
#[inline]
fn eq(&self, right: &Similarity<N, D, R>) -> bool {
fn eq(&self, right: &Self) -> bool {
self.isometry == right.isometry && self.scaling == right.scaling
}
}

View File

@ -57,7 +57,7 @@ where
#[inline]
unsafe fn from_superset_unchecked(m: &MatrixN<N2, DimNameSum<D, U1>>) -> Self {
Transform::from_matrix_unchecked(::convert_ref_unchecked(m))
Self::from_matrix_unchecked(::convert_ref_unchecked(m))
}
}

View File

@ -108,7 +108,7 @@ impl<N: Real> UnitComplex<N> {
/// ```
#[inline]
pub fn conjugate(&self) -> Self {
UnitComplex::new_unchecked(self.conj())
Self::new_unchecked(self.conj())
}
/// Inverts this complex number if it is not zero.
@ -314,7 +314,7 @@ impl<N: Real> From<UnitComplex<N>> for Matrix3<N> {
impl<N: Real> From<UnitComplex<N>> for Matrix2<N> {
#[inline]
fn from(q: UnitComplex<N>) -> Matrix2<N> {
fn from(q: UnitComplex<N>) -> Self {
q.to_rotation_matrix().into_inner()
}
}

View File

@ -85,7 +85,7 @@ impl<N: Real> UnitComplex<N> {
/// ```
#[inline]
pub fn from_cos_sin_unchecked(cos: N, sin: N) -> Self {
UnitComplex::new_unchecked(Complex::new(cos, sin))
Self::new_unchecked(Complex::new(cos, sin))
}
/// Builds a unit complex rotation from an angle in radian wrapped in a 1-dimensional vector.

View File

@ -74,7 +74,7 @@ impl<N1, N2, R> SubsetOf<Isometry<N2, U2, R>> for UnitComplex<N1>
where
N1: Real,
N2: Real + SupersetOf<N1>,
R: AlgaRotation<Point2<N2>> + SupersetOf<UnitComplex<N1>>,
R: AlgaRotation<Point2<N2>> + SupersetOf<Self>,
{
#[inline]
fn to_superset(&self) -> Isometry<N2, U2, R> {
@ -96,7 +96,7 @@ impl<N1, N2, R> SubsetOf<Similarity<N2, U2, R>> for UnitComplex<N1>
where
N1: Real,
N2: Real + SupersetOf<N1>,
R: AlgaRotation<Point2<N2>> + SupersetOf<UnitComplex<N1>>,
R: AlgaRotation<Point2<N2>> + SupersetOf<Self>,
{
#[inline]
fn to_superset(&self) -> Similarity<N2, U2, R> {

View File

@ -45,11 +45,11 @@ use geometry::{Isometry, Point2, Rotation, Similarity, Translation, UnitComplex}
*/
// UnitComplex × UnitComplex
impl<N: Real> Mul<UnitComplex<N>> for UnitComplex<N> {
type Output = UnitComplex<N>;
impl<N: Real> Mul<Self> for UnitComplex<N> {
type Output = Self;
#[inline]
fn mul(self, rhs: UnitComplex<N>) -> UnitComplex<N> {
fn mul(self, rhs: Self) -> Self {
Unit::new_unchecked(self.into_inner() * rhs.into_inner())
}
}
@ -58,16 +58,16 @@ impl<'a, N: Real> Mul<UnitComplex<N>> for &'a UnitComplex<N> {
type Output = UnitComplex<N>;
#[inline]
fn mul(self, rhs: UnitComplex<N>) -> UnitComplex<N> {
fn mul(self, rhs: UnitComplex<N>) -> Self::Output {
Unit::new_unchecked(self.complex() * rhs.into_inner())
}
}
impl<'b, N: Real> Mul<&'b UnitComplex<N>> for UnitComplex<N> {
type Output = UnitComplex<N>;
type Output = Self;
#[inline]
fn mul(self, rhs: &'b UnitComplex<N>) -> UnitComplex<N> {
fn mul(self, rhs: &'b UnitComplex<N>) -> Self::Output {
Unit::new_unchecked(self.into_inner() * rhs.complex())
}
}
@ -76,17 +76,17 @@ impl<'a, 'b, N: Real> Mul<&'b UnitComplex<N>> for &'a UnitComplex<N> {
type Output = UnitComplex<N>;
#[inline]
fn mul(self, rhs: &'b UnitComplex<N>) -> UnitComplex<N> {
fn mul(self, rhs: &'b UnitComplex<N>) -> Self::Output {
Unit::new_unchecked(self.complex() * rhs.complex())
}
}
// UnitComplex ÷ UnitComplex
impl<N: Real> Div<UnitComplex<N>> for UnitComplex<N> {
type Output = UnitComplex<N>;
impl<N: Real> Div<Self> for UnitComplex<N> {
type Output = Self;
#[inline]
fn div(self, rhs: UnitComplex<N>) -> UnitComplex<N> {
fn div(self, rhs: Self) -> Self::Output {
Unit::new_unchecked(self.into_inner() * rhs.conjugate().into_inner())
}
}
@ -95,16 +95,16 @@ impl<'a, N: Real> Div<UnitComplex<N>> for &'a UnitComplex<N> {
type Output = UnitComplex<N>;
#[inline]
fn div(self, rhs: UnitComplex<N>) -> UnitComplex<N> {
fn div(self, rhs: UnitComplex<N>) -> Self::Output {
Unit::new_unchecked(self.complex() * rhs.conjugate().into_inner())
}
}
impl<'b, N: Real> Div<&'b UnitComplex<N>> for UnitComplex<N> {
type Output = UnitComplex<N>;
type Output = Self;
#[inline]
fn div(self, rhs: &'b UnitComplex<N>) -> UnitComplex<N> {
fn div(self, rhs: &'b UnitComplex<N>) -> Self::Output {
Unit::new_unchecked(self.into_inner() * rhs.conjugate().into_inner())
}
}
@ -113,7 +113,7 @@ impl<'a, 'b, N: Real> Div<&'b UnitComplex<N>> for &'a UnitComplex<N> {
type Output = UnitComplex<N>;
#[inline]
fn div(self, rhs: &'b UnitComplex<N>) -> UnitComplex<N> {
fn div(self, rhs: &'b UnitComplex<N>) -> Self::Output {
Unit::new_unchecked(self.complex() * rhs.conjugate().into_inner())
}
}

View File

@ -61,7 +61,7 @@ where DefaultAllocator: Allocator<N, R, C> + Allocator<(usize, usize), DimMinimu
let mut q = PermutationSequence::identity_generic(min_nrows_ncols);
if min_nrows_ncols.value() == 0 {
return FullPivLU {
return Self {
lu: matrix,
p: p,
q: q,
@ -91,7 +91,7 @@ where DefaultAllocator: Allocator<N, R, C> + Allocator<(usize, usize), DimMinimu
}
}
FullPivLU {
Self {
lu: matrix,
p: p,
q: q,

View File

@ -69,7 +69,7 @@ where DefaultAllocator: Allocator<(usize, usize), D>
#[inline]
pub fn identity_generic(dim: D) -> Self {
unsafe {
PermutationSequence {
Self {
len: 0,
ipiv: VectorN::new_uninitialized_generic(dim, U1),
}

View File

@ -55,7 +55,7 @@ where
+ Allocator<N, D>,
{
/// Computes the Schur decomposition of a square matrix.
pub fn new(m: MatrixN<N, D>) -> RealSchur<N, D> {
pub fn new(m: MatrixN<N, D>) -> Self {
Self::try_new(m, N::default_epsilon(), 0).unwrap()
}
@ -70,7 +70,7 @@ where
/// * `max_niter` maximum total number of iterations performed by the algorithm. If this
/// number of iteration is exceeded, `None` is returned. If `niter == 0`, then the algorithm
/// continues indefinitely until convergence.
pub fn try_new(m: MatrixN<N, D>, eps: N, max_niter: usize) -> Option<RealSchur<N, D>> {
pub fn try_new(m: MatrixN<N, D>, eps: N, max_niter: usize) -> Option<Self> {
let mut work = unsafe { VectorN::new_uninitialized_generic(m.data.shape().0, U1) };
Self::do_decompose(m, &mut work, eps, max_niter, true).map(|(q, t)| RealSchur {

View File

@ -271,7 +271,7 @@ where
}
}
Some(SVD {
Some(Self {
u: u,
v_t: v_t,
singular_values: b.diagonal,

View File

@ -83,7 +83,7 @@ where DefaultAllocator: Allocator<N, D, D> + Allocator<N, DimDiff<D, U1>>
}
}
SymmetricTridiagonal {
Self {
tri: m,
off_diagonal: off_diagonal,
}

View File

@ -21,7 +21,7 @@ impl<'a, N> ColumnEntries<'a, N> {
#[inline]
pub fn new(i: &'a [usize], v: &'a [N]) -> Self {
assert_eq!(i.len(), v.len());
ColumnEntries { curr: 0, i, v }
Self { curr: 0, i, v }
}
}
@ -29,7 +29,7 @@ impl<'a, N: Copy> Iterator for ColumnEntries<'a, N> {
type Item = (usize, N);
#[inline]
fn next(&mut self) -> Option<(usize, N)> {
fn next(&mut self) -> Option<Self::Item> {
if self.curr >= self.i.len() {
None
} else {

View File

@ -138,7 +138,7 @@ where
{
type Output = CsMatrix<N, R1, C2>;
fn mul(self, rhs: &'b CsMatrix<N, R2, C2, S2>) -> CsMatrix<N, R1, C2> {
fn mul(self, rhs: &'b CsMatrix<N, R2, C2, S2>) -> Self::Output {
let (nrows1, ncols1) = self.data.shape();
let (nrows2, ncols2) = rhs.data.shape();
assert_eq!(
@ -231,7 +231,7 @@ where
{
type Output = CsMatrix<N, R1, C2>;
fn add(self, rhs: &'b CsMatrix<N, R2, C2, S2>) -> CsMatrix<N, R1, C2> {
fn add(self, rhs: &'b CsMatrix<N, R2, C2, S2>) -> Self::Output {
let (nrows1, ncols1) = self.data.shape();
let (nrows2, ncols2) = rhs.data.shape();
assert_eq!(
@ -294,7 +294,7 @@ where
{
type Output = Self;
fn mul(mut self, rhs: N) -> Self {
fn mul(mut self, rhs: N) -> Self::Output {
for e in self.values_mut() {
*e *= rhs
}