From cb0812aaf31f573dc0724240fa306d57bdfcec70 Mon Sep 17 00:00:00 2001 From: CAD97 Date: Mon, 28 Jun 2021 20:36:28 -0500 Subject: [PATCH 01/13] Add bytemuck impls to geometry types --- src/geometry/dual_quaternion.rs | 6 ++++++ src/geometry/orthographic.rs | 6 ++++++ src/geometry/perspective.rs | 6 ++++++ src/geometry/rotation.rs | 16 ++++++++++++++++ src/geometry/transform.rs | 18 ++++++++++++++++++ src/geometry/translation.rs | 16 ++++++++++++++++ 6 files changed, 68 insertions(+) diff --git a/src/geometry/dual_quaternion.rs b/src/geometry/dual_quaternion.rs index 63148836..d745f1d3 100644 --- a/src/geometry/dual_quaternion.rs +++ b/src/geometry/dual_quaternion.rs @@ -241,6 +241,12 @@ where } } +#[cfg(feature = "bytemuck")] +unsafe impl bytemuck::Zeroable for DualQuaternion where Quaternion: bytemuck::Zeroable {} + +#[cfg(feature = "bytemuck")] +unsafe impl bytemuck::Pod for DualQuaternion where Quaternion: bytemuck::Pod {} + #[cfg(feature = "serde-serialize-no-std")] impl Serialize for DualQuaternion where diff --git a/src/geometry/orthographic.rs b/src/geometry/orthographic.rs index 17a5b969..ade84092 100644 --- a/src/geometry/orthographic.rs +++ b/src/geometry/orthographic.rs @@ -44,6 +44,12 @@ impl PartialEq for Orthographic3 { } } +#[cfg(feature = "bytemuck")] +unsafe impl bytemuck::Zeroable for Orthographic3 where Matrix4: bytemuck::Zeroable {} + +#[cfg(feature = "bytemuck")] +unsafe impl bytemuck::Pod for Orthographic3 where Matrix4: bytemuck::Pod {} + #[cfg(feature = "serde-serialize-no-std")] impl Serialize for Orthographic3 { fn serialize(&self, serializer: S) -> Result diff --git a/src/geometry/perspective.rs b/src/geometry/perspective.rs index 6ad9707f..c7dd8b3e 100644 --- a/src/geometry/perspective.rs +++ b/src/geometry/perspective.rs @@ -45,6 +45,12 @@ impl PartialEq for Perspective3 { } } +#[cfg(feature = "bytemuck")] +unsafe impl bytemuck::Zeroable for Perspective3 where Matrix4: bytemuck::Zeroable {} + +#[cfg(feature = "bytemuck")] +unsafe impl bytemuck::Pod for Perspective3 where Matrix4: bytemuck::Pod {} + #[cfg(feature = "serde-serialize-no-std")] impl Serialize for Perspective3 { fn serialize(&self, serializer: S) -> Result diff --git a/src/geometry/rotation.rs b/src/geometry/rotation.rs index f3127fb9..89bc082f 100755 --- a/src/geometry/rotation.rs +++ b/src/geometry/rotation.rs @@ -83,6 +83,22 @@ where } } +#[cfg(feature = "bytemuck")] +unsafe impl bytemuck::Zeroable for Rotation +where + T: Scalar, + SMatrix: bytemuck::Zeroable, +{ +} + +#[cfg(feature = "bytemuck")] +unsafe impl bytemuck::Pod for Rotation +where + T: Scalar, + SMatrix: bytemuck::Pod, +{ +} + #[cfg(feature = "abomonation-serialize")] impl Abomonation for Rotation where diff --git a/src/geometry/transform.rs b/src/geometry/transform.rs index 682d2bd6..051fd3d5 100755 --- a/src/geometry/transform.rs +++ b/src/geometry/transform.rs @@ -194,6 +194,24 @@ where } } +#[cfg(feature = "bytemuck")] +unsafe impl bytemuck::Zeroable for Transform +where + Const: DimNameAdd, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, + OMatrix, U1>, DimNameSum, U1>>: bytemuck::Zeroable, +{ +} + +#[cfg(feature = "bytemuck")] +unsafe impl bytemuck::Pod for Transform +where + Const: DimNameAdd, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, + OMatrix, U1>, DimNameSum, U1>>: bytemuck::Pod, +{ +} + #[cfg(feature = "serde-serialize-no-std")] impl Serialize for Transform where diff --git a/src/geometry/translation.rs b/src/geometry/translation.rs index 18fa7e04..758a21ca 100755 --- a/src/geometry/translation.rs +++ b/src/geometry/translation.rs @@ -50,6 +50,22 @@ where } } +#[cfg(feature = "bytemuck")] +unsafe impl bytemuck::Zeroable for Translation +where + T: Scalar, + SVector: bytemuck::Zeroable, +{ +} + +#[cfg(feature = "bytemuck")] +unsafe impl bytemuck::Pod for Translation +where + T: Scalar, + SVector: bytemuck::Pod, +{ +} + #[cfg(feature = "abomonation-serialize")] impl Abomonation for Translation where From 396d3d661512284f147b3ba3500beb3e3c9a5751 Mon Sep 17 00:00:00 2001 From: CAD97 Date: Mon, 28 Jun 2021 20:49:57 -0500 Subject: [PATCH 02/13] Add missing repr(C) on bytemuckable geometry types --- src/geometry/orthographic.rs | 1 + src/geometry/perspective.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/src/geometry/orthographic.rs b/src/geometry/orthographic.rs index ade84092..836edc93 100644 --- a/src/geometry/orthographic.rs +++ b/src/geometry/orthographic.rs @@ -18,6 +18,7 @@ use crate::base::{Matrix4, Vector, Vector3}; use crate::geometry::{Point3, Projective3}; /// A 3D orthographic projection stored as a homogeneous 4x4 matrix. +#[repr(C)] pub struct Orthographic3 { matrix: Matrix4, } diff --git a/src/geometry/perspective.rs b/src/geometry/perspective.rs index c7dd8b3e..08b2608b 100644 --- a/src/geometry/perspective.rs +++ b/src/geometry/perspective.rs @@ -19,6 +19,7 @@ use crate::base::{Matrix4, Scalar, Vector, Vector3}; use crate::geometry::{Point3, Projective3}; /// A 3D perspective projection stored as a homogeneous 4x4 matrix. +#[repr(C)] pub struct Perspective3 { matrix: Matrix4, } From 22ba88353a78420e6f523b8293f7e521a22b6b1d Mon Sep 17 00:00:00 2001 From: CAD97 Date: Fri, 9 Jul 2021 15:23:08 -0500 Subject: [PATCH 03/13] Fix bounds for bytemuck impls --- src/geometry/dual_quaternion.rs | 14 ++++++++++++-- src/geometry/orthographic.rs | 14 ++++++++++++-- src/geometry/perspective.rs | 14 ++++++++++++-- src/geometry/rotation.rs | 4 ++-- src/geometry/transform.rs | 7 +++++-- src/geometry/translation.rs | 4 ++-- 6 files changed, 45 insertions(+), 12 deletions(-) diff --git a/src/geometry/dual_quaternion.rs b/src/geometry/dual_quaternion.rs index d745f1d3..376c5fbb 100644 --- a/src/geometry/dual_quaternion.rs +++ b/src/geometry/dual_quaternion.rs @@ -242,10 +242,20 @@ where } #[cfg(feature = "bytemuck")] -unsafe impl bytemuck::Zeroable for DualQuaternion where Quaternion: bytemuck::Zeroable {} +unsafe impl bytemuck::Zeroable for DualQuaternion +where + T: Scalar + bytemuck::Zeroable, + Quaternion: bytemuck::Zeroable, +{ +} #[cfg(feature = "bytemuck")] -unsafe impl bytemuck::Pod for DualQuaternion where Quaternion: bytemuck::Pod {} +unsafe impl bytemuck::Pod for DualQuaternion +where + T: Scalar + bytemuck::Pod, + Quaternion: bytemuck::Pod, +{ +} #[cfg(feature = "serde-serialize-no-std")] impl Serialize for DualQuaternion diff --git a/src/geometry/orthographic.rs b/src/geometry/orthographic.rs index 836edc93..4f7b909b 100644 --- a/src/geometry/orthographic.rs +++ b/src/geometry/orthographic.rs @@ -46,10 +46,20 @@ impl PartialEq for Orthographic3 { } #[cfg(feature = "bytemuck")] -unsafe impl bytemuck::Zeroable for Orthographic3 where Matrix4: bytemuck::Zeroable {} +unsafe impl bytemuck::Zeroable for Orthographic3 +where + T: RealField + bytemuck::Zeroable, + Matrix4: bytemuck::Zeroable, +{ +} #[cfg(feature = "bytemuck")] -unsafe impl bytemuck::Pod for Orthographic3 where Matrix4: bytemuck::Pod {} +unsafe impl bytemuck::Pod for Orthographic3 +where + T: RealField + bytemuck::Pod, + Matrix4: bytemuck::Pod, +{ +} #[cfg(feature = "serde-serialize-no-std")] impl Serialize for Orthographic3 { diff --git a/src/geometry/perspective.rs b/src/geometry/perspective.rs index 08b2608b..90cf95d8 100644 --- a/src/geometry/perspective.rs +++ b/src/geometry/perspective.rs @@ -47,10 +47,20 @@ impl PartialEq for Perspective3 { } #[cfg(feature = "bytemuck")] -unsafe impl bytemuck::Zeroable for Perspective3 where Matrix4: bytemuck::Zeroable {} +unsafe impl bytemuck::Zeroable for Perspective3 +where + T: RealField + bytemuck::Zeroable, + Matrix4: bytemuck::Zeroable, +{ +} #[cfg(feature = "bytemuck")] -unsafe impl bytemuck::Pod for Perspective3 where Matrix4: bytemuck::Pod {} +unsafe impl bytemuck::Pod for Perspective3 +where + T: RealField + bytemuck::Pod, + Matrix4: bytemuck::Pod, +{ +} #[cfg(feature = "serde-serialize-no-std")] impl Serialize for Perspective3 { diff --git a/src/geometry/rotation.rs b/src/geometry/rotation.rs index 89bc082f..6fd9e803 100755 --- a/src/geometry/rotation.rs +++ b/src/geometry/rotation.rs @@ -86,7 +86,7 @@ where #[cfg(feature = "bytemuck")] unsafe impl bytemuck::Zeroable for Rotation where - T: Scalar, + T: Scalar + bytemuck::Zeroable, SMatrix: bytemuck::Zeroable, { } @@ -94,7 +94,7 @@ where #[cfg(feature = "bytemuck")] unsafe impl bytemuck::Pod for Rotation where - T: Scalar, + T: Scalar + bytemuck::Pod, SMatrix: bytemuck::Pod, { } diff --git a/src/geometry/transform.rs b/src/geometry/transform.rs index 051fd3d5..51a8f64d 100755 --- a/src/geometry/transform.rs +++ b/src/geometry/transform.rs @@ -195,8 +195,9 @@ where } #[cfg(feature = "bytemuck")] -unsafe impl bytemuck::Zeroable for Transform +unsafe impl bytemuck::Zeroable for Transform where + T: RealField + bytemuck::Zeroable, Const: DimNameAdd, DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, OMatrix, U1>, DimNameSum, U1>>: bytemuck::Zeroable, @@ -204,11 +205,13 @@ where } #[cfg(feature = "bytemuck")] -unsafe impl bytemuck::Pod for Transform +unsafe impl bytemuck::Pod for Transform where + T: RealField + bytemuck::Pod, Const: DimNameAdd, DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, OMatrix, U1>, DimNameSum, U1>>: bytemuck::Pod, + Owned, U1>, DimNameSum, U1>>: Copy, { } diff --git a/src/geometry/translation.rs b/src/geometry/translation.rs index 758a21ca..7de9bb04 100755 --- a/src/geometry/translation.rs +++ b/src/geometry/translation.rs @@ -53,7 +53,7 @@ where #[cfg(feature = "bytemuck")] unsafe impl bytemuck::Zeroable for Translation where - T: Scalar, + T: Scalar + bytemuck::Zeroable, SVector: bytemuck::Zeroable, { } @@ -61,7 +61,7 @@ where #[cfg(feature = "bytemuck")] unsafe impl bytemuck::Pod for Translation where - T: Scalar, + T: Scalar + bytemuck::Pod, SVector: bytemuck::Pod, { } From b1775ee747df4f2243b59c13b17a9af1fa46c197 Mon Sep 17 00:00:00 2001 From: CAD97 Date: Wed, 14 Jul 2021 23:52:38 -0500 Subject: [PATCH 04/13] =?UTF-8?q?Add=20Transform=20=C3=97=20UnitComplex=20?= =?UTF-8?q?&=20friends?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/geometry/transform_ops.rs | 62 ++++++++++++++++++++++++++++++++--- 1 file changed, 57 insertions(+), 5 deletions(-) diff --git a/src/geometry/transform_ops.rs b/src/geometry/transform_ops.rs index c4ec5cfc..94ef4ab3 100644 --- a/src/geometry/transform_ops.rs +++ b/src/geometry/transform_ops.rs @@ -12,7 +12,7 @@ use crate::base::{Const, DefaultAllocator, OMatrix, SVector, Scalar}; use crate::geometry::{ Isometry, Point, Rotation, Similarity, SubTCategoryOf, SuperTCategoryOf, TAffine, TCategory, - TCategoryMul, TGeneral, TProjective, Transform, Translation, UnitQuaternion, + TCategoryMul, TGeneral, TProjective, Transform, Translation, UnitComplex, UnitQuaternion, }; /* @@ -30,7 +30,7 @@ use crate::geometry::{ * Transform × Similarity * Transform × Transform * Transform × UnitQuaternion - * TODO: Transform × UnitComplex + * Transform × UnitComplex * Transform × Translation * Transform × Vector * Transform × Point @@ -40,7 +40,7 @@ use crate::geometry::{ * Similarity × Transform * Translation × Transform * UnitQuaternion × Transform - * TODO: UnitComplex × Transform + * UnitComplex × Transform * * TODO: Transform ÷ Isometry * Transform ÷ Rotation @@ -65,7 +65,7 @@ use crate::geometry::{ * Transform ×= Isometry * Transform ×= Rotation * Transform ×= UnitQuaternion - * TODO: Transform ×= UnitComplex + * Transform ×= UnitComplex * Transform ×= Translation * * Transform ÷= Transform @@ -73,7 +73,7 @@ use crate::geometry::{ * TODO: Transform ÷= Isometry * Transform ÷= Rotation * Transform ÷= UnitQuaternion - * TODO: Transform ÷= UnitComplex + * Transform ÷= UnitComplex * */ @@ -225,6 +225,20 @@ md_impl_all!( [ref ref] => Self::Output::from_matrix_unchecked(self.matrix() * rhs.to_homogeneous()); ); +// Transform × UnitComplex +md_impl_all!( + Mul, mul where T: RealField; + (U3, U3), (U2, U1) + const; + for C; + where C: TCategoryMul; + self: Transform, rhs: UnitComplex, Output = Transform; + [val val] => Self::Output::from_matrix_unchecked(self.into_inner() * rhs.to_homogeneous()); + [ref val] => Self::Output::from_matrix_unchecked(self.matrix() * rhs.to_homogeneous()); + [val ref] => Self::Output::from_matrix_unchecked(self.into_inner() * rhs.to_homogeneous()); + [ref ref] => Self::Output::from_matrix_unchecked(self.matrix() * rhs.to_homogeneous()); +); + // UnitQuaternion × Transform md_impl_all!( Mul, mul where T: RealField; @@ -239,6 +253,20 @@ md_impl_all!( [ref ref] => Self::Output::from_matrix_unchecked(self.to_homogeneous() * rhs.matrix()); ); +// UnitComplex × Transform +md_impl_all!( + Mul, mul where T: RealField; + (U2, U1), (U3, U3) + const; + for C; + where C: TCategoryMul; + self: UnitComplex, rhs: Transform, Output = Transform; + [val val] => Self::Output::from_matrix_unchecked(self.to_homogeneous() * rhs.into_inner()); + [ref val] => Self::Output::from_matrix_unchecked(self.to_homogeneous() * rhs.into_inner()); + [val ref] => Self::Output::from_matrix_unchecked(self.to_homogeneous() * rhs.matrix()); + [ref ref] => Self::Output::from_matrix_unchecked(self.to_homogeneous() * rhs.matrix()); +); + // Transform × Isometry md_impl_all!( Mul, mul where T: RealField; @@ -579,6 +607,18 @@ md_assign_impl_all!( [ref] => *self.matrix_mut_unchecked() *= rhs.to_homogeneous(); ); +// Transform ×= UnitComplex +md_assign_impl_all!( + MulAssign, mul_assign where T: RealField; + (U3, U3), (U2, U1) + const; + for C; + where C: TCategory; + self: Transform, rhs: UnitComplex; + [val] => *self.matrix_mut_unchecked() *= rhs.to_homogeneous(); + [ref] => *self.matrix_mut_unchecked() *= rhs.to_homogeneous(); +); + // Transform ÷= Transform md_assign_impl_all!( DivAssign, div_assign where T: RealField; @@ -650,3 +690,15 @@ md_assign_impl_all!( [val] => #[allow(clippy::suspicious_op_assign_impl)] { *self *= rhs.inverse() }; [ref] => #[allow(clippy::suspicious_op_assign_impl)] { *self *= rhs.inverse() }; ); + +// Transform ÷= UnitComplex +md_assign_impl_all!( + DivAssign, div_assign where T: RealField; + (U3, U3), (U2, U1) + const; + for C; + where C: TCategory; + self: Transform, rhs: UnitComplex; + [val] => #[allow(clippy::suspicious_op_assign_impl)] { *self *= rhs.inverse() }; + [ref] => #[allow(clippy::suspicious_op_assign_impl)] { *self *= rhs.inverse() }; +); From 04dd3ff241079252443695abb0ebbd02dd9de17d Mon Sep 17 00:00:00 2001 From: CAD97 Date: Thu, 22 Jul 2021 18:07:12 -0500 Subject: [PATCH 05/13] Make some from_matrix_unchecked const --- src/geometry/orthographic.rs | 46 +++++++++++++++++++----------------- src/geometry/perspective.rs | 20 +++++++++------- src/geometry/rotation.rs | 11 +++------ 3 files changed, 38 insertions(+), 39 deletions(-) diff --git a/src/geometry/orthographic.rs b/src/geometry/orthographic.rs index e9546cdd..60041b5d 100644 --- a/src/geometry/orthographic.rs +++ b/src/geometry/orthographic.rs @@ -66,6 +66,30 @@ impl<'a, T: RealField + Deserialize<'a>> Deserialize<'a> for Orthographic3 { } } +impl Orthographic3 { + /// Wraps the given matrix to interpret it as a 3D orthographic matrix. + /// + /// It is not checked whether or not the given matrix actually represents an orthographic + /// projection. + /// + /// # Example + /// ``` + /// # use nalgebra::{Orthographic3, Point3, Matrix4}; + /// let mat = Matrix4::new( + /// 2.0 / 9.0, 0.0, 0.0, -11.0 / 9.0, + /// 0.0, 2.0 / 18.0, 0.0, -22.0 / 18.0, + /// 0.0, 0.0, -2.0 / 999.9, -1000.1 / 999.9, + /// 0.0, 0.0, 0.0, 1.0 + /// ); + /// let proj = Orthographic3::from_matrix_unchecked(mat); + /// assert_eq!(proj, Orthographic3::new(1.0, 10.0, 2.0, 20.0, 0.1, 1000.0)); + /// ``` + #[inline] + pub const fn from_matrix_unchecked(matrix: Matrix4) -> Self { + Self { matrix } + } +} + impl Orthographic3 { /// Creates a new orthographic projection matrix. /// @@ -121,28 +145,6 @@ impl Orthographic3 { res } - /// Wraps the given matrix to interpret it as a 3D orthographic matrix. - /// - /// It is not checked whether or not the given matrix actually represents an orthographic - /// projection. - /// - /// # Example - /// ``` - /// # use nalgebra::{Orthographic3, Point3, Matrix4}; - /// let mat = Matrix4::new( - /// 2.0 / 9.0, 0.0, 0.0, -11.0 / 9.0, - /// 0.0, 2.0 / 18.0, 0.0, -22.0 / 18.0, - /// 0.0, 0.0, -2.0 / 999.9, -1000.1 / 999.9, - /// 0.0, 0.0, 0.0, 1.0 - /// ); - /// let proj = Orthographic3::from_matrix_unchecked(mat); - /// assert_eq!(proj, Orthographic3::new(1.0, 10.0, 2.0, 20.0, 0.1, 1000.0)); - /// ``` - #[inline] - pub fn from_matrix_unchecked(matrix: Matrix4) -> Self { - Self { matrix } - } - /// Creates a new orthographic projection matrix from an aspect ratio and the vertical field of view. #[inline] pub fn from_fov(aspect: T, vfov: T, znear: T, zfar: T) -> Self { diff --git a/src/geometry/perspective.rs b/src/geometry/perspective.rs index ba8368a2..dbe048fc 100644 --- a/src/geometry/perspective.rs +++ b/src/geometry/perspective.rs @@ -67,6 +67,17 @@ impl<'a, T: RealField + Deserialize<'a>> Deserialize<'a> for Perspective3 { } } +impl Perspective3 { + /// Wraps the given matrix to interpret it as a 3D perspective matrix. + /// + /// It is not checked whether or not the given matrix actually represents a perspective + /// projection. + #[inline] + pub const fn from_matrix_unchecked(matrix: Matrix4) -> Self { + Self { matrix } + } +} + impl Perspective3 { /// Creates a new perspective matrix from the aspect ratio, y field of view, and near/far planes. pub fn new(aspect: T, fovy: T, znear: T, zfar: T) -> Self { @@ -92,15 +103,6 @@ impl Perspective3 { res } - /// Wraps the given matrix to interpret it as a 3D perspective matrix. - /// - /// It is not checked whether or not the given matrix actually represents a perspective - /// projection. - #[inline] - pub fn from_matrix_unchecked(matrix: Matrix4) -> Self { - Self { matrix } - } - /// Retrieves the inverse of the underlying homogeneous matrix. #[inline] #[must_use] diff --git a/src/geometry/rotation.rs b/src/geometry/rotation.rs index 98e8fcbc..25b55944 100755 --- a/src/geometry/rotation.rs +++ b/src/geometry/rotation.rs @@ -130,10 +130,10 @@ where } } -impl Rotation { +impl Rotation { /// Creates a new rotation from the given square matrix. /// - /// The matrix squareness is checked but not its orthonormality. + /// The matrix orthonormality is not checked. /// /// # Example /// ``` @@ -154,12 +154,7 @@ impl Rotation { /// assert_eq!(*rot.matrix(), mat); /// ``` #[inline] - pub fn from_matrix_unchecked(matrix: SMatrix) -> Self { - assert!( - matrix.is_square(), - "Unable to create a rotation from a non-square matrix." - ); - + pub const fn from_matrix_unchecked(matrix: SMatrix) -> Self { Self { matrix } } } From ceb30a68b8c6adf7b1531f66b7310a5e5016bbd3 Mon Sep 17 00:00:00 2001 From: CAD97 Date: Fri, 23 Jul 2021 21:22:59 -0500 Subject: [PATCH 06/13] Fix a few bitrotted user guide links --- src/geometry/orthographic.rs | 2 +- src/geometry/point.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/geometry/orthographic.rs b/src/geometry/orthographic.rs index e9546cdd..3b73d944 100644 --- a/src/geometry/orthographic.rs +++ b/src/geometry/orthographic.rs @@ -77,7 +77,7 @@ impl Orthographic3 { /// # use nalgebra::{Orthographic3, Point3}; /// let proj = Orthographic3::new(1.0, 10.0, 2.0, 20.0, 0.1, 1000.0); /// // Check this projection actually transforms the view cuboid into the double-unit cube. - /// // See https://www.nalgebra.org/projections/#orthographic-projection for more details. + /// // See https://www.nalgebra.org/docs/user_guide/projections#orthographic-projection for more details. /// let p1 = Point3::new(1.0, 2.0, -0.1); /// let p2 = Point3::new(1.0, 2.0, -1000.0); /// let p3 = Point3::new(1.0, 20.0, -0.1); diff --git a/src/geometry/point.rs b/src/geometry/point.rs index d4d9dbfc..faf4f48f 100644 --- a/src/geometry/point.rs +++ b/src/geometry/point.rs @@ -21,7 +21,7 @@ use crate::base::{Const, DefaultAllocator, OVector, Scalar}; /// A point in an euclidean space. /// -/// The difference between a point and a vector is only semantic. See [the user guide](https://www.nalgebra.org/points_and_transformations/) +/// The difference between a point and a vector is only semantic. See [the user guide](https://www.nalgebra.org/docs/user_guide/points_and_transformations) /// for details on the distinction. The most notable difference that vectors ignore translations. /// In particular, an [`Isometry2`](crate::Isometry2) or [`Isometry3`](crate::Isometry3) will /// transform points by applying a rotation and a translation on them. However, these isometries From ed6b34a0d6b9ff8661382423df87e30081d78fd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Lauzier?= Date: Sun, 25 Jul 2021 13:06:14 -0400 Subject: [PATCH 07/13] Fix rust_2018_idioms warnings --- src/base/array_storage.rs | 4 +- src/base/blas.rs | 6 +-- src/base/matrix.rs | 22 ++++----- src/base/matrix_slice.rs | 64 ++++++++++++------------- src/base/ops.rs | 4 +- src/base/statistics.rs | 6 +-- src/geometry/dual_quaternion.rs | 2 +- src/geometry/isometry.rs | 2 +- src/geometry/orthographic.rs | 2 +- src/geometry/perspective.rs | 2 +- src/geometry/point.rs | 6 +-- src/geometry/quaternion.rs | 8 ++-- src/geometry/quaternion_construction.rs | 2 +- src/geometry/rotation.rs | 2 +- src/geometry/similarity.rs | 2 +- src/geometry/translation.rs | 2 +- src/geometry/unit_complex.rs | 2 +- src/lib.rs | 1 + src/linalg/solve.rs | 16 +++---- 19 files changed, 78 insertions(+), 77 deletions(-) diff --git a/src/base/array_storage.rs b/src/base/array_storage.rs index 643bc631..dc4e0df7 100644 --- a/src/base/array_storage.rs +++ b/src/base/array_storage.rs @@ -49,7 +49,7 @@ where impl Debug for ArrayStorage { #[inline] - fn fmt(&self, fmt: &mut Formatter) -> fmt::Result { + fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result { self.0.fmt(fmt) } } @@ -231,7 +231,7 @@ where { type Value = ArrayStorage; - fn expecting(&self, formatter: &mut Formatter) -> fmt::Result { + fn expecting(&self, formatter: &mut Formatter<'_>) -> fmt::Result { formatter.write_str("a matrix array") } diff --git a/src/base/blas.rs b/src/base/blas.rs index b705c6c1..72b00bda 100644 --- a/src/base/blas.rs +++ b/src/base/blas.rs @@ -455,8 +455,8 @@ where x: &Vector, beta: T, dot: impl Fn( - &DVectorSlice, - &DVectorSlice, + &DVectorSlice<'_, T, SB::RStride, SB::CStride>, + &DVectorSlice<'_, T, SC::RStride, SC::CStride>, ) -> T, ) where T: One, @@ -619,7 +619,7 @@ where a: &Matrix, x: &Vector, beta: T, - dot: impl Fn(&VectorSlice, &Vector) -> T, + dot: impl Fn(&VectorSlice<'_, T, R2, SB::RStride, SB::CStride>, &Vector) -> T, ) where T: One, SB: Storage, diff --git a/src/base/matrix.rs b/src/base/matrix.rs index 319e8eb9..ea2c2c40 100644 --- a/src/base/matrix.rs +++ b/src/base/matrix.rs @@ -193,7 +193,7 @@ pub struct Matrix { } impl fmt::Debug for Matrix { - fn fmt(&self, formatter: &mut fmt::Formatter) -> Result<(), fmt::Error> { + fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { formatter .debug_struct("Matrix") .field("data", &self.data) @@ -278,7 +278,7 @@ impl> matrixcompare_core::Matrix< self.ncols() } - fn access(&self) -> matrixcompare_core::Access { + fn access(&self) -> matrixcompare_core::Access<'_, T> { matrixcompare_core::Access::Dense(self) } } @@ -1051,7 +1051,7 @@ impl> Matrix { /// assert_eq!(*it.next().unwrap(), 23); /// assert!(it.next().is_none()); #[inline] - pub fn iter(&self) -> MatrixIter { + pub fn iter(&self) -> MatrixIter<'_, T, R, C, S> { MatrixIter::new(&self.data) } @@ -1067,7 +1067,7 @@ impl> Matrix { /// } /// ``` #[inline] - pub fn row_iter(&self) -> RowIter { + pub fn row_iter(&self) -> RowIter<'_, T, R, C, S> { RowIter::new(self) } @@ -1082,13 +1082,13 @@ impl> Matrix { /// } /// ``` #[inline] - pub fn column_iter(&self) -> ColumnIter { + pub fn column_iter(&self) -> ColumnIter<'_, T, R, C, S> { ColumnIter::new(self) } /// Mutably iterates through this matrix coordinates. #[inline] - pub fn iter_mut(&mut self) -> MatrixIterMut + pub fn iter_mut(&mut self) -> MatrixIterMut<'_, T, R, C, S> where S: StorageMut, { @@ -1111,7 +1111,7 @@ impl> Matrix { /// assert_eq!(a, expected); /// ``` #[inline] - pub fn row_iter_mut(&mut self) -> RowIterMut + pub fn row_iter_mut(&mut self) -> RowIterMut<'_, T, R, C, S> where S: StorageMut, { @@ -1134,7 +1134,7 @@ impl> Matrix { /// assert_eq!(a, expected); /// ``` #[inline] - pub fn column_iter_mut(&mut self) -> ColumnIterMut + pub fn column_iter_mut(&mut self) -> ColumnIterMut<'_, T, R, C, S> where S: StorageMut, { @@ -1820,9 +1820,9 @@ macro_rules! impl_fmt { T: Scalar + $trait, S: Storage, { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { #[cfg(feature = "std")] - fn val_width(val: &T, f: &mut fmt::Formatter) -> usize { + fn val_width(val: &T, f: &mut fmt::Formatter<'_>) -> usize { match f.precision() { Some(precision) => format!($fmt_str_with_precision, val, precision) .chars() @@ -1832,7 +1832,7 @@ macro_rules! impl_fmt { } #[cfg(not(feature = "std"))] - fn val_width(_: &T, _: &mut fmt::Formatter) -> usize { + fn val_width(_: &T, _: &mut fmt::Formatter<'_>) -> usize { 4 } diff --git a/src/base/matrix_slice.rs b/src/base/matrix_slice.rs index 96ebe59c..bd4a66da 100644 --- a/src/base/matrix_slice.rs +++ b/src/base/matrix_slice.rs @@ -315,20 +315,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 { + pub fn $row($me: $Me, i: usize) -> $MatrixSlice<'_, 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 { + pub fn $row_part($me: $Me, i: usize, n: usize) -> $MatrixSlice<'_, 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 { + -> $MatrixSlice<'_, T, Dynamic, C, S::RStride, S::CStride> { $me.$rows_generic(first_row, Dynamic::new(nrows)) } @@ -336,7 +336,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 { + -> $MatrixSlice<'_, T, Dynamic, C, Dynamic, S::CStride> { $me.$rows_generic_with_step(first_row, Dynamic::new(nrows), step) } @@ -344,7 +344,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, C, S::RStride, S::CStride> { + -> $MatrixSlice<'_, T, Const, C, S::RStride, S::CStride> { $me.$rows_generic(first_row, Const::) } @@ -353,7 +353,7 @@ macro_rules! matrix_slice_impl( /// rows. #[inline] pub fn $fixed_rows_with_step($me: $Me, first_row: usize, step: usize) - -> $MatrixSlice, C, Dynamic, S::CStride> { + -> $MatrixSlice<'_, T, Const, C, Dynamic, S::CStride> { $me.$rows_generic_with_step(first_row, Const::, step) } @@ -362,7 +362,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 { + -> $MatrixSlice<'_, T, RSlice, C, S::RStride, S::CStride> { let my_shape = $me.data.shape(); $me.assert_slice_index((row_start, 0), (nrows.value(), my_shape.1.value()), (0, 0)); @@ -379,7 +379,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 + -> $MatrixSlice<'_, T, RSlice, C, Dynamic, S::CStride> where RSlice: Dim { let my_shape = $me.data.shape(); @@ -402,20 +402,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 { + pub fn $column($me: $Me, i: usize) -> $MatrixSlice<'_, 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 { + pub fn $column_part($me: $Me, i: usize, n: usize) -> $MatrixSlice<'_, 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 { + -> $MatrixSlice<'_, T, R, Dynamic, S::RStride, S::CStride> { $me.$columns_generic(first_col, Dynamic::new(ncols)) } @@ -424,7 +424,7 @@ macro_rules! matrix_slice_impl( /// columns. #[inline] pub fn $columns_with_step($me: $Me, first_col: usize, ncols: usize, step: usize) - -> $MatrixSlice { + -> $MatrixSlice<'_, T, R, Dynamic, S::RStride, Dynamic> { $me.$columns_generic_with_step(first_col, Dynamic::new(ncols), step) } @@ -432,7 +432,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, S::RStride, S::CStride> { + -> $MatrixSlice<'_, T, R, Const, S::RStride, S::CStride> { $me.$columns_generic(first_col, Const::) } @@ -441,7 +441,7 @@ macro_rules! matrix_slice_impl( /// `step` columns. #[inline] pub fn $fixed_columns_with_step($me: $Me, first_col: usize, step: usize) - -> $MatrixSlice, S::RStride, Dynamic> { + -> $MatrixSlice<'_, T, R, Const, S::RStride, Dynamic> { $me.$columns_generic_with_step(first_col, Const::, step) } @@ -450,7 +450,7 @@ macro_rules! matrix_slice_impl( /// known at compile-time. #[inline] pub fn $columns_generic($me: $Me, first_col: usize, ncols: CSlice) - -> $MatrixSlice { + -> $MatrixSlice<'_, T, R, CSlice, S::RStride, S::CStride> { let my_shape = $me.data.shape(); $me.assert_slice_index((0, first_col), (my_shape.0.value(), ncols.value()), (0, 0)); @@ -467,7 +467,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 { + -> $MatrixSlice<'_, T, R, CSlice, S::RStride, Dynamic> { let my_shape = $me.data.shape(); let my_strides = $me.data.strides(); @@ -492,7 +492,7 @@ macro_rules! matrix_slice_impl( /// consecutive elements. #[inline] pub fn $slice($me: $Me, start: (usize, usize), shape: (usize, usize)) - -> $MatrixSlice { + -> $MatrixSlice<'_, 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)); @@ -510,7 +510,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 { + -> $MatrixSlice<'_, T, Dynamic, Dynamic, Dynamic, Dynamic> { let shape = (Dynamic::new(shape.0), Dynamic::new(shape.1)); $me.$generic_slice_with_steps(start, shape, steps) @@ -520,7 +520,7 @@ macro_rules! matrix_slice_impl( /// CSlice::dim())` consecutive components. #[inline] pub fn $fixed_slice($me: $Me, irow: usize, icol: usize) - -> $MatrixSlice, Const, S::RStride, S::CStride> { + -> $MatrixSlice<'_, T, Const, Const, S::RStride, S::CStride> { $me.assert_slice_index((irow, icol), (RSLICE, CSLICE), (0, 0)); let shape = (Const::, Const::); @@ -537,7 +537,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, Const, Dynamic, Dynamic> { + -> $MatrixSlice<'_, T, Const, Const, Dynamic, Dynamic> { let shape = (Const::, Const::); $me.$generic_slice_with_steps(start, shape, steps) } @@ -545,7 +545,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 + -> $MatrixSlice<'_, T, RSlice, CSlice, S::RStride, S::CStride> where RSlice: Dim, CSlice: Dim { @@ -563,7 +563,7 @@ macro_rules! matrix_slice_impl( start: (usize, usize), shape: (RSlice, CSlice), steps: (usize, usize)) - -> $MatrixSlice + -> $MatrixSlice<'_, T, RSlice, CSlice, Dynamic, Dynamic> where RSlice: Dim, CSlice: Dim { @@ -589,8 +589,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, - $MatrixSlice) { + -> ($MatrixSlice<'_, T, Range1::Size, C, S::RStride, S::CStride>, + $MatrixSlice<'_, T, Range2::Size, C, S::RStride, S::CStride>) { let (nrows, ncols) = $me.data.shape(); let strides = $me.data.strides(); @@ -625,8 +625,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, - $MatrixSlice) { + -> ($MatrixSlice<'_, T, R, Range1::Size, S::RStride, S::CStride>, + $MatrixSlice<'_, T, R, Range2::Size, S::RStride, S::CStride>) { let (nrows, ncols) = $me.data.shape(); let strides = $me.data.strides(); @@ -870,7 +870,7 @@ impl> Matrix { &self, rows: RowRange, cols: ColRange, - ) -> MatrixSlice + ) -> MatrixSlice<'_, T, RowRange::Size, ColRange::Size, S::RStride, S::CStride> where RowRange: SliceRange, ColRange: SliceRange, @@ -888,7 +888,7 @@ impl> Matrix { pub fn rows_range>( &self, rows: RowRange, - ) -> MatrixSlice { + ) -> MatrixSlice<'_, T, RowRange::Size, C, S::RStride, S::CStride> { self.slice_range(rows, ..) } @@ -898,7 +898,7 @@ impl> Matrix { pub fn columns_range>( &self, cols: ColRange, - ) -> MatrixSlice { + ) -> MatrixSlice<'_, T, R, ColRange::Size, S::RStride, S::CStride> { self.slice_range(.., cols) } } @@ -912,7 +912,7 @@ impl> Matrix { &mut self, rows: RowRange, cols: ColRange, - ) -> MatrixSliceMut + ) -> MatrixSliceMut<'_, T, RowRange::Size, ColRange::Size, S::RStride, S::CStride> where RowRange: SliceRange, ColRange: SliceRange, @@ -929,7 +929,7 @@ impl> Matrix { pub fn rows_range_mut>( &mut self, rows: RowRange, - ) -> MatrixSliceMut { + ) -> MatrixSliceMut<'_, T, RowRange::Size, C, S::RStride, S::CStride> { self.slice_range_mut(rows, ..) } @@ -938,7 +938,7 @@ impl> Matrix { pub fn columns_range_mut>( &mut self, cols: ColRange, - ) -> MatrixSliceMut { + ) -> MatrixSliceMut<'_, T, R, ColRange::Size, S::RStride, S::CStride> { self.slice_range_mut(.., cols) } } diff --git a/src/base/ops.rs b/src/base/ops.rs index 852f6490..f9401cc7 100644 --- a/src/base/ops.rs +++ b/src/base/ops.rs @@ -708,8 +708,8 @@ where rhs: &Matrix, out: &mut Matrix, dot: impl Fn( - &VectorSlice, - &VectorSlice, + &VectorSlice<'_, T, R1, SA::RStride, SA::CStride>, + &VectorSlice<'_, T, R2, SB::RStride, SB::CStride>, ) -> T, ) where SB: Storage, diff --git a/src/base/statistics.rs b/src/base/statistics.rs index 59d78482..dbb2231c 100644 --- a/src/base/statistics.rs +++ b/src/base/statistics.rs @@ -12,7 +12,7 @@ impl> Matrix { #[must_use] pub fn compress_rows( &self, - f: impl Fn(VectorSlice) -> T, + f: impl Fn(VectorSlice<'_, T, R, S::RStride, S::CStride>) -> T, ) -> RowOVector where DefaultAllocator: Allocator, @@ -39,7 +39,7 @@ impl> Matrix { #[must_use] pub fn compress_rows_tr( &self, - f: impl Fn(VectorSlice) -> T, + f: impl Fn(VectorSlice<'_, T, R, S::RStride, S::CStride>) -> T, ) -> OVector where DefaultAllocator: Allocator, @@ -64,7 +64,7 @@ impl> Matrix { pub fn compress_columns( &self, init: OVector, - f: impl Fn(&mut OVector, VectorSlice), + f: impl Fn(&mut OVector, VectorSlice<'_, T, R, S::RStride, S::CStride>), ) -> OVector where DefaultAllocator: Allocator, diff --git a/src/geometry/dual_quaternion.rs b/src/geometry/dual_quaternion.rs index 01ea9dcc..e20b3778 100644 --- a/src/geometry/dual_quaternion.rs +++ b/src/geometry/dual_quaternion.rs @@ -896,7 +896,7 @@ impl Default for UnitDualQuaternion { } impl fmt::Display for UnitDualQuaternion { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { if let Some(axis) = self.rotation().axis() { let axis = axis.into_inner(); write!( diff --git a/src/geometry/isometry.rs b/src/geometry/isometry.rs index 333468b3..f8e63d07 100755 --- a/src/geometry/isometry.rs +++ b/src/geometry/isometry.rs @@ -642,7 +642,7 @@ impl fmt::Display for Isometry fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let precision = f.precision().unwrap_or(3); writeln!(f, "Isometry {{")?; diff --git a/src/geometry/orthographic.rs b/src/geometry/orthographic.rs index 3b73d944..1b908f33 100644 --- a/src/geometry/orthographic.rs +++ b/src/geometry/orthographic.rs @@ -32,7 +32,7 @@ impl Clone for Orthographic3 { } impl fmt::Debug for Orthographic3 { - fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { self.matrix.fmt(f) } } diff --git a/src/geometry/perspective.rs b/src/geometry/perspective.rs index ba8368a2..f9246af1 100644 --- a/src/geometry/perspective.rs +++ b/src/geometry/perspective.rs @@ -33,7 +33,7 @@ impl Clone for Perspective3 { } impl fmt::Debug for Perspective3 { - fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { self.matrix.fmt(f) } } diff --git a/src/geometry/point.rs b/src/geometry/point.rs index faf4f48f..40936d75 100644 --- a/src/geometry/point.rs +++ b/src/geometry/point.rs @@ -273,7 +273,7 @@ where #[inline] pub fn iter( &self, - ) -> MatrixIter, >::Buffer> { + ) -> MatrixIter<'_, T, D, Const<1>, >::Buffer> { self.coords.iter() } @@ -299,7 +299,7 @@ where #[inline] pub fn iter_mut( &mut self, - ) -> MatrixIterMut, >::Buffer> { + ) -> MatrixIterMut<'_, T, D, Const<1>, >::Buffer> { self.coords.iter_mut() } @@ -454,7 +454,7 @@ impl fmt::Display for OPoint where DefaultAllocator: Allocator, { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{{")?; let mut it = self.coords.iter(); diff --git a/src/geometry/quaternion.rs b/src/geometry/quaternion.rs index 3449f1ae..cd248c94 100755 --- a/src/geometry/quaternion.rs +++ b/src/geometry/quaternion.rs @@ -241,7 +241,7 @@ where /// ``` #[inline] #[must_use] - pub fn vector(&self) -> MatrixSlice, CStride> { + pub fn vector(&self) -> MatrixSlice<'_, T, U3, U1, RStride, CStride> { self.coords.fixed_rows::<3>(0) } @@ -633,7 +633,7 @@ where #[inline] pub fn vector_mut( &mut self, - ) -> MatrixSliceMut, CStride> { + ) -> MatrixSliceMut<'_, T, U3, U1, RStride, CStride> { self.coords.fixed_rows_mut::<3>(0) } @@ -1046,7 +1046,7 @@ impl> UlpsEq for Quaternion { } impl fmt::Display for Quaternion { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!( f, "Quaternion {} − ({}, {}, {})", @@ -1692,7 +1692,7 @@ impl Default for UnitQuaternion { } impl fmt::Display for UnitQuaternion { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { if let Some(axis) = self.axis() { let axis = axis.into_inner(); write!( diff --git a/src/geometry/quaternion_construction.rs b/src/geometry/quaternion_construction.rs index 7a681bb2..f93069b4 100644 --- a/src/geometry/quaternion_construction.rs +++ b/src/geometry/quaternion_construction.rs @@ -894,9 +894,9 @@ where #[cfg(test)] #[cfg(feature = "rand")] mod tests { - extern crate rand_xorshift; use super::*; use rand::SeedableRng; + use rand_xorshift; #[test] fn random_unit_quats_are_unit() { diff --git a/src/geometry/rotation.rs b/src/geometry/rotation.rs index 98e8fcbc..bbe6f60b 100755 --- a/src/geometry/rotation.rs +++ b/src/geometry/rotation.rs @@ -565,7 +565,7 @@ impl fmt::Display for Rotation where T: RealField + fmt::Display, { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let precision = f.precision().unwrap_or(3); writeln!(f, "Rotation matrix {{")?; diff --git a/src/geometry/similarity.rs b/src/geometry/similarity.rs index 19164439..32a19772 100755 --- a/src/geometry/similarity.rs +++ b/src/geometry/similarity.rs @@ -429,7 +429,7 @@ where T: RealField + fmt::Display, R: AbstractRotation + fmt::Display, { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let precision = f.precision().unwrap_or(3); writeln!(f, "Similarity {{")?; diff --git a/src/geometry/translation.rs b/src/geometry/translation.rs index c667a512..76c771a7 100755 --- a/src/geometry/translation.rs +++ b/src/geometry/translation.rs @@ -332,7 +332,7 @@ where * */ impl fmt::Display for Translation { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let precision = f.precision().unwrap_or(3); writeln!(f, "Translation {{")?; diff --git a/src/geometry/unit_complex.rs b/src/geometry/unit_complex.rs index d6a7316c..d6f3d0dc 100755 --- a/src/geometry/unit_complex.rs +++ b/src/geometry/unit_complex.rs @@ -412,7 +412,7 @@ where } impl fmt::Display for UnitComplex { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "UnitComplex angle: {}", self.angle()) } } diff --git a/src/lib.rs b/src/lib.rs index c5c4dcd8..28767346 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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(rust_2018_idioms)] #![doc( html_favicon_url = "https://nalgebra.org/img/favicon.ico", html_root_url = "https://docs.rs/nalgebra/0.25.0" diff --git a/src/linalg/solve.rs b/src/linalg/solve.rs index 7f9b7dae..32221fec 100644 --- a/src/linalg/solve.rs +++ b/src/linalg/solve.rs @@ -376,8 +376,8 @@ impl> SquareMatrix { b: &mut Vector, conjugate: impl Fn(T) -> T, dot: impl Fn( - &DVectorSlice, - &DVectorSlice, + &DVectorSlice<'_, T, S::RStride, S::CStride>, + &DVectorSlice<'_, T, S2::RStride, S2::CStride>, ) -> T, ) -> bool where @@ -411,8 +411,8 @@ impl> SquareMatrix { b: &mut Vector, conjugate: impl Fn(T) -> T, dot: impl Fn( - &DVectorSlice, - &DVectorSlice, + &DVectorSlice<'_, T, S::RStride, S::CStride>, + &DVectorSlice<'_, T, S2::RStride, S2::CStride>, ) -> T, ) -> bool where @@ -734,8 +734,8 @@ impl> SquareMatrix { b: &mut Vector, conjugate: impl Fn(T) -> T, dot: impl Fn( - &DVectorSlice, - &DVectorSlice, + &DVectorSlice<'_, T, S::RStride, S::CStride>, + &DVectorSlice<'_, T, S2::RStride, S2::CStride>, ) -> T, ) where S2: StorageMut, @@ -760,8 +760,8 @@ impl> SquareMatrix { b: &mut Vector, conjugate: impl Fn(T) -> T, dot: impl Fn( - &DVectorSlice, - &DVectorSlice, + &DVectorSlice<'_, T, S::RStride, S::CStride>, + &DVectorSlice<'_, T, S2::RStride, S2::CStride>, ) -> T, ) where S2: StorageMut, From de540aa7ffdddc0dca3572e18f9536e3954f22db Mon Sep 17 00:00:00 2001 From: Andreas Longva Date: Mon, 26 Jul 2021 17:57:21 +0200 Subject: [PATCH 08/13] Do not require T: (De)Serialize for OPoint impl The bounds recently got a little too strict by accident. --- src/geometry/point.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/geometry/point.rs b/src/geometry/point.rs index faf4f48f..2893bcf9 100644 --- a/src/geometry/point.rs +++ b/src/geometry/point.rs @@ -82,7 +82,7 @@ where } #[cfg(feature = "serde-serialize-no-std")] -impl Serialize for OPoint +impl Serialize for OPoint where DefaultAllocator: Allocator, >::Buffer: Serialize, @@ -96,7 +96,7 @@ where } #[cfg(feature = "serde-serialize-no-std")] -impl<'a, T: Scalar + Deserialize<'a>, D: DimName> Deserialize<'a> for OPoint +impl<'a, T: Scalar, D: DimName> Deserialize<'a> for OPoint where DefaultAllocator: Allocator, >::Buffer: Deserialize<'a>, From 7dd12e8e7a244ea8211fbd9f89bd9fb11b9622a5 Mon Sep 17 00:00:00 2001 From: Jeff Petkau Date: Mon, 26 Jul 2021 10:13:58 -0700 Subject: [PATCH 09/13] Include "rand" in feature list for docs.rs Random support was gated by the "rand" feature in version 0.25.1, but not added to the docs.rs list, causing the gated functions to disappear from docs. --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 8f4c7876..d10db84a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -119,4 +119,4 @@ lto = true [package.metadata.docs.rs] # Enable certain features when building docs for docs.rs -features = [ "proptest-support", "compare", "macros" ] +features = [ "proptest-support", "compare", "macros", "rand" ] From 06e20b4b95e42c47a7d80782ee734c8f0e2c1a98 Mon Sep 17 00:00:00 2001 From: Rouven Spreckels Date: Tue, 27 Jul 2021 15:17:30 +0200 Subject: [PATCH 10/13] Add getter for reflection bias. Fix typos. --- src/geometry/reflection.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/geometry/reflection.rs b/src/geometry/reflection.rs index 87166b81..a48b8024 100644 --- a/src/geometry/reflection.rs +++ b/src/geometry/reflection.rs @@ -22,7 +22,7 @@ impl>, const D: usize> Reflection> Reflection { - /// Creates a new reflection wrt the plane orthogonal to the given axis and bias. + /// Creates a new reflection wrt. the plane orthogonal to the given axis and bias. /// /// 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. @@ -33,12 +33,21 @@ impl> Reflection { } } - /// The reflexion axis. + /// The reflection axis. #[must_use] pub fn axis(&self) -> &Vector { &self.axis } + /// The reflection bias. + /// + /// 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. + #[must_use] + pub fn bias(&self) -> T { + self.bias + } + // TODO: naming convention: reflect_to, reflect_assign ? /// Applies the reflection to the columns of `rhs`. pub fn reflect(&self, rhs: &mut Matrix) From 9824fbc67b8416d6abc519ff264bc9c6ead4d0c0 Mon Sep 17 00:00:00 2001 From: Rouven Spreckels Date: Tue, 27 Jul 2021 15:18:07 +0200 Subject: [PATCH 11/13] Add reflection alias. --- src/geometry/mod.rs | 2 ++ src/geometry/reflection_alias.rs | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 src/geometry/reflection_alias.rs diff --git a/src/geometry/mod.rs b/src/geometry/mod.rs index 2675817e..37ca57f9 100644 --- a/src/geometry/mod.rs +++ b/src/geometry/mod.rs @@ -73,6 +73,7 @@ mod transform_ops; mod transform_simba; mod reflection; +mod reflection_alias; mod orthographic; mod perspective; @@ -104,6 +105,7 @@ pub use self::transform::*; pub use self::transform_alias::*; pub use self::reflection::*; +pub use self::reflection_alias::*; pub use self::orthographic::Orthographic3; pub use self::perspective::Perspective3; diff --git a/src/geometry/reflection_alias.rs b/src/geometry/reflection_alias.rs new file mode 100644 index 00000000..14f55a3a --- /dev/null +++ b/src/geometry/reflection_alias.rs @@ -0,0 +1,21 @@ +use crate::base::ArrayStorage; +use crate::geometry::Reflection; +use crate::Const; + +/// A 1-dimensional reflection. +pub type Reflection1 = Reflection, ArrayStorage>; + +/// A 2-dimensional reflection. +pub type Reflection2 = Reflection, ArrayStorage>; + +/// A 3-dimensional reflection. +pub type Reflection3 = Reflection, ArrayStorage>; + +/// A 4-dimensional reflection. +pub type Reflection4 = Reflection, ArrayStorage>; + +/// A 5-dimensional reflection. +pub type Reflection5 = Reflection, ArrayStorage>; + +/// A 6-dimensional reflection. +pub type Reflection6 = Reflection, ArrayStorage>; From c35f792b4f8d80f7cc1a18f06e1859d2fc6c1537 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Lauzier?= Date: Tue, 27 Jul 2021 19:18:29 -0400 Subject: [PATCH 12/13] Fix some warnings --- clippy.toml | 2 + nalgebra-glm/src/lib.rs | 10 +++ nalgebra-lapack/src/hessenberg.rs | 2 +- nalgebra-lapack/src/qr.rs | 4 +- nalgebra-lapack/src/schur.rs | 2 +- nalgebra-macros/src/lib.rs | 17 +++- nalgebra-sparse/src/cs.rs | 16 ++-- nalgebra-sparse/src/csc.rs | 28 +++--- nalgebra-sparse/src/csr.rs | 28 +++--- nalgebra-sparse/src/factorization/cholesky.rs | 2 +- nalgebra-sparse/src/lib.rs | 19 ++-- nalgebra-sparse/src/matrixcompare.rs | 4 +- nalgebra-sparse/src/ops/serial/cs.rs | 4 +- nalgebra-sparse/src/ops/serial/csc.rs | 8 +- nalgebra-sparse/src/ops/serial/csr.rs | 4 +- nalgebra-sparse/src/ops/serial/mod.rs | 2 +- nalgebra-sparse/src/pattern.rs | 4 +- rustfmt.toml | 3 + src/base/allocator.rs | 4 +- src/base/cg.rs | 6 +- src/base/constraint.rs | 1 + src/base/construction.rs | 10 +-- src/base/default_allocator.rs | 1 + src/base/iter.rs | 7 +- src/base/matrix.rs | 6 +- src/base/matrix_slice.rs | 4 +- src/base/norm.rs | 3 + src/base/unit.rs | 2 +- src/base/vec_storage.rs | 2 +- src/geometry/dual_quaternion.rs | 4 +- src/geometry/isometry_construction.rs | 2 +- src/geometry/orthographic.rs | 2 +- src/geometry/perspective.rs | 2 +- src/geometry/quaternion_construction.rs | 4 +- src/geometry/rotation.rs | 2 +- src/geometry/rotation_specialization.rs | 2 +- src/geometry/similarity_construction.rs | 2 +- src/geometry/transform.rs | 2 +- src/lib.rs | 90 +++++++++---------- src/linalg/balancing.rs | 2 +- src/linalg/col_piv_qr.rs | 2 +- src/linalg/schur.rs | 2 +- src/proptest/mod.rs | 6 +- src/sparse/cs_matrix.rs | 4 +- src/third_party/alga/alga_isometry.rs | 6 +- src/third_party/alga/alga_rotation.rs | 12 +-- src/third_party/alga/alga_similarity.rs | 2 +- src/third_party/alga/alga_translation.rs | 12 +-- 48 files changed, 201 insertions(+), 164 deletions(-) create mode 100644 clippy.toml diff --git a/clippy.toml b/clippy.toml new file mode 100644 index 00000000..77a873e1 --- /dev/null +++ b/clippy.toml @@ -0,0 +1,2 @@ +too-many-arguments-threshold = 8 +type-complexity-threshold = 675 diff --git a/nalgebra-glm/src/lib.rs b/nalgebra-glm/src/lib.rs index 391391f4..9ca3856f 100644 --- a/nalgebra-glm/src/lib.rs +++ b/nalgebra-glm/src/lib.rs @@ -110,6 +110,16 @@ and keep in mind it is possible to convert, e.g., an `Isometry3` to a `Mat4` and vice-versa (see the [conversions section](#conversions)). */ +#![deny( + nonstandard_style, + unused, + missing_docs, + rust_2018_idioms, + rust_2018_compatibility, + future_incompatible, + missing_copy_implementations, + missing_debug_implementations +)] #![doc(html_favicon_url = "https://nalgebra.org/img/favicon.ico")] #![cfg_attr(not(feature = "std"), no_std)] diff --git a/nalgebra-lapack/src/hessenberg.rs b/nalgebra-lapack/src/hessenberg.rs index c5765022..0d911cf8 100644 --- a/nalgebra-lapack/src/hessenberg.rs +++ b/nalgebra-lapack/src/hessenberg.rs @@ -84,7 +84,7 @@ where ); lapack_panic!(info); - Self { h: m, tau: tau } + Self { h: m, tau } } /// Computes the hessenberg matrix of this decomposition. diff --git a/nalgebra-lapack/src/qr.rs b/nalgebra-lapack/src/qr.rs index 7b2d5df6..7f00d058 100644 --- a/nalgebra-lapack/src/qr.rs +++ b/nalgebra-lapack/src/qr.rs @@ -62,7 +62,7 @@ where }; if nrows.value() == 0 || ncols.value() == 0 { - return Self { qr: m, tau: tau }; + return Self { qr: m, tau }; } let lwork = T::xgeqrf_work_size( @@ -87,7 +87,7 @@ where &mut info, ); - Self { qr: m, tau: tau } + Self { qr: m, tau } } /// Retrieves the upper trapezoidal submatrix `R` of this decomposition. diff --git a/nalgebra-lapack/src/schur.rs b/nalgebra-lapack/src/schur.rs index 3bee2635..644f8a5c 100644 --- a/nalgebra-lapack/src/schur.rs +++ b/nalgebra-lapack/src/schur.rs @@ -125,7 +125,7 @@ where re: wr, im: wi, t: m, - q: q, + q, }) } diff --git a/nalgebra-macros/src/lib.rs b/nalgebra-macros/src/lib.rs index beddfc74..9a403e0d 100644 --- a/nalgebra-macros/src/lib.rs +++ b/nalgebra-macros/src/lib.rs @@ -3,7 +3,18 @@ //! This crate is not intended for direct consumption. Instead, the macros are re-exported by //! `nalgebra` if the `macros` feature is enabled (enabled by default). -extern crate proc_macro; +#![deny( + nonstandard_style, + unused, + missing_docs, + rust_2018_idioms, + rust_2018_compatibility, + future_incompatible, + missing_copy_implementations, + missing_debug_implementations, + clippy::all, + clippy::pedantic +)] use proc_macro::TokenStream; use quote::{quote, ToTokens, TokenStreamExt}; @@ -60,7 +71,7 @@ impl Matrix { type MatrixRowSyntax = Punctuated; impl Parse for Matrix { - fn parse(input: ParseStream) -> Result { + fn parse(input: ParseStream<'_>) -> Result { let mut rows = Vec::new(); let mut ncols = None; @@ -205,7 +216,7 @@ impl Vector { } impl Parse for Vector { - fn parse(input: ParseStream) -> Result { + fn parse(input: ParseStream<'_>) -> Result { // The syntax of a vector is just the syntax of a single matrix row if input.is_empty() { Ok(Self { diff --git a/nalgebra-sparse/src/cs.rs b/nalgebra-sparse/src/cs.rs index cde0a3e2..e0775b26 100644 --- a/nalgebra-sparse/src/cs.rs +++ b/nalgebra-sparse/src/cs.rs @@ -116,7 +116,7 @@ impl CsMatrix { /// Returns an entry for the given major/minor indices, or `None` if the indices are out /// of bounds. #[must_use] - pub fn get_entry(&self, major_index: usize, minor_index: usize) -> Option> { + pub fn get_entry(&self, major_index: usize, minor_index: usize) -> Option> { let row_range = self.get_index_range(major_index)?; let (_, minor_indices, values) = self.cs_data(); let minor_indices = &minor_indices[row_range.clone()]; @@ -135,7 +135,7 @@ impl CsMatrix { &mut self, major_index: usize, minor_index: usize, - ) -> Option> { + ) -> Option> { let row_range = self.get_index_range(major_index)?; let minor_dim = self.pattern().minor_dim(); let (_, minor_indices, values) = self.cs_data_mut(); @@ -145,7 +145,7 @@ impl CsMatrix { } #[must_use] - pub fn get_lane(&self, index: usize) -> Option> { + pub fn get_lane(&self, index: usize) -> Option> { let range = self.get_index_range(index)?; let (_, minor_indices, values) = self.cs_data(); Some(CsLane { @@ -157,7 +157,7 @@ impl CsMatrix { #[inline] #[must_use] - pub fn get_lane_mut(&mut self, index: usize) -> Option> { + pub fn get_lane_mut(&mut self, index: usize) -> Option> { let range = self.get_index_range(index)?; let minor_dim = self.pattern().minor_dim(); let (_, minor_indices, values) = self.cs_data_mut(); @@ -169,12 +169,12 @@ impl CsMatrix { } #[inline] - pub fn lane_iter(&self) -> CsLaneIter { + pub fn lane_iter(&self) -> CsLaneIter<'_, T> { CsLaneIter::new(self.pattern(), self.values()) } #[inline] - pub fn lane_iter_mut(&mut self) -> CsLaneIterMut { + pub fn lane_iter_mut(&mut self) -> CsLaneIterMut<'_, T> { CsLaneIterMut::new(&self.sparsity_pattern, &mut self.values) } @@ -406,7 +406,7 @@ macro_rules! impl_cs_lane_common_methods { #[inline] #[must_use] - pub fn get_entry(&self, global_col_index: usize) -> Option> { + pub fn get_entry(&self, global_col_index: usize) -> Option> { get_entry_from_slices( self.minor_dim, self.minor_indices, @@ -431,7 +431,7 @@ impl<'a, T> CsLaneMut<'a, T> { } #[must_use] - pub fn get_entry_mut(&mut self, global_minor_index: usize) -> Option> { + pub fn get_entry_mut(&mut self, global_minor_index: usize) -> Option> { get_mut_entry_from_slices( self.minor_dim, self.minor_indices, diff --git a/nalgebra-sparse/src/csc.rs b/nalgebra-sparse/src/csc.rs index 15e0746c..607cc0cf 100644 --- a/nalgebra-sparse/src/csc.rs +++ b/nalgebra-sparse/src/csc.rs @@ -260,7 +260,7 @@ impl CscMatrix { /// let triplets: Vec<_> = csc.triplet_iter().map(|(i, j, v)| (i, j, *v)).collect(); /// assert_eq!(triplets, vec![(0, 0, 1), (2, 0, 3), (1, 1, 2), (0, 2, 4)]); /// ``` - pub fn triplet_iter(&self) -> CscTripletIter { + pub fn triplet_iter(&self) -> CscTripletIter<'_, T> { CscTripletIter { pattern_iter: self.pattern().entries(), values_iter: self.values().iter(), @@ -290,7 +290,7 @@ impl CscMatrix { /// let triplets: Vec<_> = csc.triplet_iter().map(|(i, j, v)| (i, j, *v)).collect(); /// assert_eq!(triplets, vec![(0, 0, 1), (2, 0, 0), (1, 1, 2), (0, 2, 4)]); /// ``` - pub fn triplet_iter_mut(&mut self) -> CscTripletIterMut { + pub fn triplet_iter_mut(&mut self) -> CscTripletIterMut<'_, T> { let (pattern, values) = self.cs.pattern_and_values_mut(); CscTripletIterMut { pattern_iter: pattern.entries(), @@ -305,7 +305,7 @@ impl CscMatrix { /// Panics if column index is out of bounds. #[inline] #[must_use] - pub fn col(&self, index: usize) -> CscCol { + pub fn col(&self, index: usize) -> CscCol<'_, T> { self.get_col(index).expect("Row index must be in bounds") } @@ -315,7 +315,7 @@ impl CscMatrix { /// ------ /// Panics if column index is out of bounds. #[inline] - pub fn col_mut(&mut self, index: usize) -> CscColMut { + pub fn col_mut(&mut self, index: usize) -> CscColMut<'_, T> { self.get_col_mut(index) .expect("Row index must be in bounds") } @@ -323,26 +323,26 @@ impl CscMatrix { /// Return the column at the given column index, or `None` if out of bounds. #[inline] #[must_use] - pub fn get_col(&self, index: usize) -> Option> { + pub fn get_col(&self, index: usize) -> Option> { self.cs.get_lane(index).map(|lane| CscCol { lane }) } /// Mutable column access for the given column index, or `None` if out of bounds. #[inline] #[must_use] - pub fn get_col_mut(&mut self, index: usize) -> Option> { + pub fn get_col_mut(&mut self, index: usize) -> Option> { self.cs.get_lane_mut(index).map(|lane| CscColMut { lane }) } /// An iterator over columns in the matrix. - pub fn col_iter(&self) -> CscColIter { + pub fn col_iter(&self) -> CscColIter<'_, T> { CscColIter { lane_iter: CsLaneIter::new(self.pattern(), self.values()), } } /// A mutable iterator over columns in the matrix. - pub fn col_iter_mut(&mut self) -> CscColIterMut { + pub fn col_iter_mut(&mut self) -> CscColIterMut<'_, T> { let (pattern, values) = self.cs.pattern_and_values_mut(); CscColIterMut { lane_iter: CsLaneIterMut::new(pattern, values), @@ -408,7 +408,7 @@ impl CscMatrix { /// Each call to this function incurs the cost of a binary search among the explicitly /// stored row entries for the given column. #[must_use] - pub fn get_entry(&self, row_index: usize, col_index: usize) -> Option> { + pub fn get_entry(&self, row_index: usize, col_index: usize) -> Option> { self.cs.get_entry(col_index, row_index) } @@ -421,7 +421,7 @@ impl CscMatrix { &mut self, row_index: usize, col_index: usize, - ) -> Option> { + ) -> Option> { self.cs.get_entry_mut(col_index, row_index) } @@ -434,7 +434,7 @@ impl CscMatrix { /// ------ /// Panics if `row_index` or `col_index` is out of bounds. #[must_use] - pub fn index_entry(&self, row_index: usize, col_index: usize) -> SparseEntry { + pub fn index_entry(&self, row_index: usize, col_index: usize) -> SparseEntry<'_, T> { self.get_entry(row_index, col_index) .expect("Out of bounds matrix indices encountered") } @@ -447,7 +447,7 @@ impl CscMatrix { /// Panics /// ------ /// Panics if `row_index` or `col_index` is out of bounds. - pub fn index_entry_mut(&mut self, row_index: usize, col_index: usize) -> SparseEntryMut { + pub fn index_entry_mut(&mut self, row_index: usize, col_index: usize) -> SparseEntryMut<'_, T> { self.get_entry_mut(row_index, col_index) .expect("Out of bounds matrix indices encountered") } @@ -666,7 +666,7 @@ macro_rules! impl_csc_col_common_methods { /// Each call to this function incurs the cost of a binary search among the explicitly /// stored row entries. #[must_use] - pub fn get_entry(&self, global_row_index: usize) -> Option> { + pub fn get_entry(&self, global_row_index: usize) -> Option> { self.lane.get_entry(global_row_index) } } @@ -693,7 +693,7 @@ impl<'a, T> CscColMut<'a, T> { /// Returns a mutable entry for the given global row index. #[must_use] - pub fn get_entry_mut(&mut self, global_row_index: usize) -> Option> { + pub fn get_entry_mut(&mut self, global_row_index: usize) -> Option> { self.lane.get_entry_mut(global_row_index) } } diff --git a/nalgebra-sparse/src/csr.rs b/nalgebra-sparse/src/csr.rs index 4c65908b..c64be915 100644 --- a/nalgebra-sparse/src/csr.rs +++ b/nalgebra-sparse/src/csr.rs @@ -262,7 +262,7 @@ impl CsrMatrix { /// let triplets: Vec<_> = csr.triplet_iter().map(|(i, j, v)| (i, j, *v)).collect(); /// assert_eq!(triplets, vec![(0, 0, 1), (0, 2, 2), (1, 1, 3), (2, 0, 4)]); /// ``` - pub fn triplet_iter(&self) -> CsrTripletIter { + pub fn triplet_iter(&self) -> CsrTripletIter<'_, T> { CsrTripletIter { pattern_iter: self.pattern().entries(), values_iter: self.values().iter(), @@ -292,7 +292,7 @@ impl CsrMatrix { /// let triplets: Vec<_> = csr.triplet_iter().map(|(i, j, v)| (i, j, *v)).collect(); /// assert_eq!(triplets, vec![(0, 0, 1), (0, 2, 2), (1, 1, 3), (2, 0, 0)]); /// ``` - pub fn triplet_iter_mut(&mut self) -> CsrTripletIterMut { + pub fn triplet_iter_mut(&mut self) -> CsrTripletIterMut<'_, T> { let (pattern, values) = self.cs.pattern_and_values_mut(); CsrTripletIterMut { pattern_iter: pattern.entries(), @@ -307,7 +307,7 @@ impl CsrMatrix { /// Panics if row index is out of bounds. #[inline] #[must_use] - pub fn row(&self, index: usize) -> CsrRow { + pub fn row(&self, index: usize) -> CsrRow<'_, T> { self.get_row(index).expect("Row index must be in bounds") } @@ -317,7 +317,7 @@ impl CsrMatrix { /// ------ /// Panics if row index is out of bounds. #[inline] - pub fn row_mut(&mut self, index: usize) -> CsrRowMut { + pub fn row_mut(&mut self, index: usize) -> CsrRowMut<'_, T> { self.get_row_mut(index) .expect("Row index must be in bounds") } @@ -325,26 +325,26 @@ impl CsrMatrix { /// Return the row at the given row index, or `None` if out of bounds. #[inline] #[must_use] - pub fn get_row(&self, index: usize) -> Option> { + pub fn get_row(&self, index: usize) -> Option> { self.cs.get_lane(index).map(|lane| CsrRow { lane }) } /// Mutable row access for the given row index, or `None` if out of bounds. #[inline] #[must_use] - pub fn get_row_mut(&mut self, index: usize) -> Option> { + pub fn get_row_mut(&mut self, index: usize) -> Option> { self.cs.get_lane_mut(index).map(|lane| CsrRowMut { lane }) } /// An iterator over rows in the matrix. - pub fn row_iter(&self) -> CsrRowIter { + pub fn row_iter(&self) -> CsrRowIter<'_, T> { CsrRowIter { lane_iter: CsLaneIter::new(self.pattern(), self.values()), } } /// A mutable iterator over rows in the matrix. - pub fn row_iter_mut(&mut self) -> CsrRowIterMut { + pub fn row_iter_mut(&mut self) -> CsrRowIterMut<'_, T> { let (pattern, values) = self.cs.pattern_and_values_mut(); CsrRowIterMut { lane_iter: CsLaneIterMut::new(pattern, values), @@ -410,7 +410,7 @@ impl CsrMatrix { /// Each call to this function incurs the cost of a binary search among the explicitly /// stored column entries for the given row. #[must_use] - pub fn get_entry(&self, row_index: usize, col_index: usize) -> Option> { + pub fn get_entry(&self, row_index: usize, col_index: usize) -> Option> { self.cs.get_entry(row_index, col_index) } @@ -423,7 +423,7 @@ impl CsrMatrix { &mut self, row_index: usize, col_index: usize, - ) -> Option> { + ) -> Option> { self.cs.get_entry_mut(row_index, col_index) } @@ -436,7 +436,7 @@ impl CsrMatrix { /// ------ /// Panics if `row_index` or `col_index` is out of bounds. #[must_use] - pub fn index_entry(&self, row_index: usize, col_index: usize) -> SparseEntry { + pub fn index_entry(&self, row_index: usize, col_index: usize) -> SparseEntry<'_, T> { self.get_entry(row_index, col_index) .expect("Out of bounds matrix indices encountered") } @@ -449,7 +449,7 @@ impl CsrMatrix { /// Panics /// ------ /// Panics if `row_index` or `col_index` is out of bounds. - pub fn index_entry_mut(&mut self, row_index: usize, col_index: usize) -> SparseEntryMut { + pub fn index_entry_mut(&mut self, row_index: usize, col_index: usize) -> SparseEntryMut<'_, T> { self.get_entry_mut(row_index, col_index) .expect("Out of bounds matrix indices encountered") } @@ -667,7 +667,7 @@ macro_rules! impl_csr_row_common_methods { /// stored column entries. #[inline] #[must_use] - pub fn get_entry(&self, global_col_index: usize) -> Option> { + pub fn get_entry(&self, global_col_index: usize) -> Option> { self.lane.get_entry(global_col_index) } } @@ -697,7 +697,7 @@ impl<'a, T> CsrRowMut<'a, T> { /// Returns a mutable entry for the given global column index. #[inline] #[must_use] - pub fn get_entry_mut(&mut self, global_col_index: usize) -> Option> { + pub fn get_entry_mut(&mut self, global_col_index: usize) -> Option> { self.lane.get_entry_mut(global_col_index) } } diff --git a/nalgebra-sparse/src/factorization/cholesky.rs b/nalgebra-sparse/src/factorization/cholesky.rs index 0acc428d..f2e2065b 100644 --- a/nalgebra-sparse/src/factorization/cholesky.rs +++ b/nalgebra-sparse/src/factorization/cholesky.rs @@ -72,7 +72,7 @@ pub struct CscCholesky { work_c: Vec, } -#[derive(Debug, PartialEq, Eq, Clone)] +#[derive(Debug, PartialEq, Eq, Copy, Clone)] #[non_exhaustive] /// Possible errors produced by the Cholesky factorization. pub enum CholeskyError { diff --git a/nalgebra-sparse/src/lib.rs b/nalgebra-sparse/src/lib.rs index d50d8e15..bf845757 100644 --- a/nalgebra-sparse/src/lib.rs +++ b/nalgebra-sparse/src/lib.rs @@ -131,12 +131,15 @@ //! assert_matrix_eq!(y, y_expected, comp = abs, tol = 1e-9); //! } //! ``` -#![deny(non_camel_case_types)] -#![deny(unused_parens)] -#![deny(non_upper_case_globals)] -#![deny(unused_qualifications)] -#![deny(unused_results)] -#![deny(missing_docs)] +#![deny( + nonstandard_style, + unused, + missing_docs, + rust_2018_idioms, + rust_2018_compatibility, + future_incompatible, + missing_copy_implementations +)] pub extern crate nalgebra as na; pub mod convert; @@ -190,7 +193,7 @@ impl SparseFormatError { /// The type of format error described by a [SparseFormatError](struct.SparseFormatError.html). #[non_exhaustive] -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Copy, Clone, PartialEq, Eq)] pub enum SparseFormatErrorKind { /// Indicates that the index data associated with the format contains at least one index /// out of bounds. @@ -208,7 +211,7 @@ pub enum SparseFormatErrorKind { } impl fmt::Display for SparseFormatError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.error) } } diff --git a/nalgebra-sparse/src/matrixcompare.rs b/nalgebra-sparse/src/matrixcompare.rs index 9c48ae40..a5f614ab 100644 --- a/nalgebra-sparse/src/matrixcompare.rs +++ b/nalgebra-sparse/src/matrixcompare.rs @@ -28,7 +28,7 @@ macro_rules! impl_matrix_for_csr_csc { self.ncols() } - fn access(&self) -> Access { + fn access(&self) -> Access<'_, T> { Access::Sparse(self) } } @@ -59,7 +59,7 @@ impl matrixcompare_core::Matrix for CooMatrix { self.ncols() } - fn access(&self) -> Access { + fn access(&self) -> Access<'_, T> { Access::Sparse(self) } } diff --git a/nalgebra-sparse/src/ops/serial/cs.rs b/nalgebra-sparse/src/ops/serial/cs.rs index 66b0ad76..db057705 100644 --- a/nalgebra-sparse/src/ops/serial/cs.rs +++ b/nalgebra-sparse/src/ops/serial/cs.rs @@ -131,10 +131,10 @@ where /// the transposed operation must be specified for the CSC matrix. pub fn spmm_cs_dense( beta: T, - mut c: DMatrixSliceMut, + mut c: DMatrixSliceMut<'_, T>, alpha: T, a: Op<&CsMatrix>, - b: Op>, + b: Op>, ) where T: Scalar + ClosedAdd + ClosedMul + Zero + One, { diff --git a/nalgebra-sparse/src/ops/serial/csc.rs b/nalgebra-sparse/src/ops/serial/csc.rs index 95350d91..25e59f26 100644 --- a/nalgebra-sparse/src/ops/serial/csc.rs +++ b/nalgebra-sparse/src/ops/serial/csc.rs @@ -27,10 +27,10 @@ pub fn spmm_csc_dense<'a, T>( fn spmm_csc_dense_( beta: T, - c: DMatrixSliceMut, + c: DMatrixSliceMut<'_, T>, alpha: T, a: Op<&CscMatrix>, - b: Op>, + b: Op>, ) where T: Scalar + ClosedAdd + ClosedMul + Zero + One, { @@ -147,7 +147,7 @@ pub fn spsolve_csc_lower_triangular<'a, T: RealField>( fn spsolve_csc_lower_triangular_no_transpose( l: &CscMatrix, - b: DMatrixSliceMut, + b: DMatrixSliceMut<'_, T>, ) -> Result<(), OperationError> { let mut x = b; @@ -205,7 +205,7 @@ fn spsolve_encountered_zero_diagonal() -> Result<(), OperationError> { fn spsolve_csc_lower_triangular_transpose( l: &CscMatrix, - b: DMatrixSliceMut, + b: DMatrixSliceMut<'_, T>, ) -> Result<(), OperationError> { let mut x = b; diff --git a/nalgebra-sparse/src/ops/serial/csr.rs b/nalgebra-sparse/src/ops/serial/csr.rs index f6fcc62a..fa317bbf 100644 --- a/nalgebra-sparse/src/ops/serial/csr.rs +++ b/nalgebra-sparse/src/ops/serial/csr.rs @@ -22,10 +22,10 @@ pub fn spmm_csr_dense<'a, T>( fn spmm_csr_dense_( beta: T, - c: DMatrixSliceMut, + c: DMatrixSliceMut<'_, T>, alpha: T, a: Op<&CsrMatrix>, - b: Op>, + b: Op>, ) where T: Scalar + ClosedAdd + ClosedMul + Zero + One, { diff --git a/nalgebra-sparse/src/ops/serial/mod.rs b/nalgebra-sparse/src/ops/serial/mod.rs index 4b0cc904..87285525 100644 --- a/nalgebra-sparse/src/ops/serial/mod.rs +++ b/nalgebra-sparse/src/ops/serial/mod.rs @@ -74,7 +74,7 @@ pub struct OperationError { /// The different kinds of operation errors that may occur. #[non_exhaustive] -#[derive(Clone, Debug)] +#[derive(Copy, Clone, Debug)] pub enum OperationErrorKind { /// Indicates that one or more sparsity patterns involved in the operation violate the /// expectations of the routine. diff --git a/nalgebra-sparse/src/pattern.rs b/nalgebra-sparse/src/pattern.rs index 2e490285..85f6bc1a 100644 --- a/nalgebra-sparse/src/pattern.rs +++ b/nalgebra-sparse/src/pattern.rs @@ -205,7 +205,7 @@ impl SparsityPattern { /// ``` /// #[must_use] - pub fn entries(&self) -> SparsityPatternIter { + pub fn entries(&self) -> SparsityPatternIter<'_> { SparsityPatternIter::from_pattern(self) } @@ -260,7 +260,7 @@ impl SparsityPattern { /// Error type for `SparsityPattern` format errors. #[non_exhaustive] -#[derive(Debug, PartialEq, Eq)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] pub enum SparsityPatternFormatError { /// Indicates an invalid number of offsets. /// diff --git a/rustfmt.toml b/rustfmt.toml index e69de29b..91b5446c 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -0,0 +1,3 @@ +edition = "2018" +use_try_shorthand = true +use_field_init_shorthand = true diff --git a/src/base/allocator.rs b/src/base/allocator.rs index 64871635..b0f6537b 100644 --- a/src/base/allocator.rs +++ b/src/base/allocator.rs @@ -32,8 +32,8 @@ pub trait Allocator: Any + Sized { ) -> Self::Buffer; } -/// A matrix reallocator. Changes the size of the memory buffer that initially contains (RFrom × -/// CFrom) elements to a smaller or larger size (RTo, CTo). +/// A matrix reallocator. Changes the size of the memory buffer that initially contains (`RFrom` × +/// `CFrom`) elements to a smaller or larger size (`RTo`, `CTo`). pub trait Reallocator: Allocator + Allocator { diff --git a/src/base/cg.rs b/src/base/cg.rs index 742824c7..a6ed784f 100644 --- a/src/base/cg.rs +++ b/src/base/cg.rs @@ -79,7 +79,7 @@ impl Matrix3 { /// Creates a new homogeneous matrix that applies a scaling factor for each dimension with respect to point. /// - /// Can be used to implement "zoom_to" functionality. + /// Can be used to implement `zoom_to` functionality. #[inline] pub fn new_nonuniform_scaling_wrt_point(scaling: &Vector2, pt: &Point2) -> Self { let zero = T::zero(); @@ -119,7 +119,7 @@ impl Matrix4 { /// Creates a new homogeneous matrix that applies a scaling factor for each dimension with respect to point. /// - /// Can be used to implement "zoom_to" functionality. + /// Can be used to implement `zoom_to` functionality. #[inline] pub fn new_nonuniform_scaling_wrt_point(scaling: &Vector3, pt: &Point3) -> Self { let zero = T::zero(); @@ -187,7 +187,7 @@ impl Matrix4 { IsometryMatrix3::face_towards(eye, target, up).to_homogeneous() } - /// Deprecated: Use [Matrix4::face_towards] instead. + /// Deprecated: Use [`Matrix4::face_towards`] instead. #[deprecated(note = "renamed to `face_towards`")] pub fn new_observer_frame(eye: &Point3, target: &Point3, up: &Vector3) -> Self { Matrix4::face_towards(eye, target, up) diff --git a/src/base/constraint.rs b/src/base/constraint.rs index f681dc25..b8febd03 100644 --- a/src/base/constraint.rs +++ b/src/base/constraint.rs @@ -3,6 +3,7 @@ use crate::base::dimension::{Dim, DimName, Dynamic}; /// A type used in `where` clauses for enforcing constraints. +#[derive(Copy, Clone, Debug)] pub struct ShapeConstraint; /// Constraints `C1` and `R2` to be equivalent. diff --git a/src/base/construction.rs b/src/base/construction.rs index d5ecc7c1..cde4f924 100644 --- a/src/base/construction.rs +++ b/src/base/construction.rs @@ -888,19 +888,19 @@ macro_rules! transpose_array( [$([$a]),*] }; [$($a: ident),*; $($b: ident),*;] => { - [$([$a, $b]),*]; + [$([$a, $b]),*] }; [$($a: ident),*; $($b: ident),*; $($c: ident),*;] => { - [$([$a, $b, $c]),*]; + [$([$a, $b, $c]),*] }; [$($a: ident),*; $($b: ident),*; $($c: ident),*; $($d: ident),*;] => { - [$([$a, $b, $c, $d]),*]; + [$([$a, $b, $c, $d]),*] }; [$($a: ident),*; $($b: ident),*; $($c: ident),*; $($d: ident),*; $($e: ident),*;] => { - [$([$a, $b, $c, $d, $e]),*]; + [$([$a, $b, $c, $d, $e]),*] }; [$($a: ident),*; $($b: ident),*; $($c: ident),*; $($d: ident),*; $($e: ident),*; $($f: ident),*;] => { - [$([$a, $b, $c, $d, $e, $f]),*]; + [$([$a, $b, $c, $d, $e, $f]),*] }; ); diff --git a/src/base/default_allocator.rs b/src/base/default_allocator.rs index 4bfa11a8..b053c829 100644 --- a/src/base/default_allocator.rs +++ b/src/base/default_allocator.rs @@ -28,6 +28,7 @@ use crate::base::Scalar; */ /// An allocator based on `GenericArray` and `VecStorage` for statically-sized and dynamically-sized /// matrices respectively. +#[derive(Copy, Clone, Debug)] pub struct DefaultAllocator; // Static - Static diff --git a/src/base/iter.rs b/src/base/iter.rs index 0e13e4d3..6baeab25 100644 --- a/src/base/iter.rs +++ b/src/base/iter.rs @@ -11,6 +11,7 @@ use crate::base::{Matrix, MatrixSlice, MatrixSliceMut, Scalar}; macro_rules! iterator { (struct $Name:ident for $Storage:ident.$ptr: ident -> $Ptr:ty, $Ref:ty, $SRef: ty) => { /// An iterator through a dense matrix with arbitrary strides matrix. + #[derive(Debug)] pub struct $Name<'a, T: Scalar, R: Dim, C: Dim, S: 'a + $Storage> { ptr: $Ptr, inner_ptr: $Ptr, @@ -180,7 +181,7 @@ iterator!(struct MatrixIterMut for StorageMut.ptr_mut -> *mut T, &'a mut T, &'a * Row iterators. * */ -#[derive(Clone)] +#[derive(Clone, Debug)] /// An iterator through the rows of a matrix. pub struct RowIter<'a, T: Scalar, R: Dim, C: Dim, S: Storage> { mat: &'a Matrix, @@ -231,6 +232,7 @@ impl<'a, T: Scalar, R: Dim, C: Dim, S: 'a + Storage> ExactSizeIterator } /// An iterator through the mutable rows of a matrix. +#[derive(Debug)] pub struct RowIterMut<'a, T: Scalar, R: Dim, C: Dim, S: StorageMut> { mat: *mut Matrix, curr: usize, @@ -292,7 +294,7 @@ impl<'a, T: Scalar, R: Dim, C: Dim, S: 'a + StorageMut> ExactSizeIterat * Column iterators. * */ -#[derive(Clone)] +#[derive(Clone, Debug)] /// An iterator through the columns of a matrix. pub struct ColumnIter<'a, T: Scalar, R: Dim, C: Dim, S: Storage> { mat: &'a Matrix, @@ -345,6 +347,7 @@ impl<'a, T: Scalar, R: Dim, C: Dim, S: 'a + Storage> ExactSizeIterator } /// An iterator through the mutable columns of a matrix. +#[derive(Debug)] pub struct ColumnIterMut<'a, T: Scalar, R: Dim, C: Dim, S: StorageMut> { mat: *mut Matrix, curr: usize, diff --git a/src/base/matrix.rs b/src/base/matrix.rs index ea2c2c40..2f3d9dff 100644 --- a/src/base/matrix.rs +++ b/src/base/matrix.rs @@ -368,7 +368,7 @@ impl Matrix { } impl SMatrix { - /// Creates a new statically-allocated matrix from the given [ArrayStorage]. + /// Creates a new statically-allocated matrix from the given [`ArrayStorage`]. /// /// This method exists primarily as a workaround for the fact that `from_data` can not /// work in `const fn` contexts. @@ -384,7 +384,7 @@ impl SMatrix { // `from_data` const fn compatible #[cfg(any(feature = "std", feature = "alloc"))] impl DMatrix { - /// Creates a new heap-allocated matrix from the given [VecStorage]. + /// Creates a new heap-allocated matrix from the given [`VecStorage`]. /// /// This method exists primarily as a workaround for the fact that `from_data` can not /// work in `const fn` contexts. @@ -399,7 +399,7 @@ impl DMatrix { // `from_data` const fn compatible #[cfg(any(feature = "std", feature = "alloc"))] impl DVector { - /// Creates a new heap-allocated matrix from the given [VecStorage]. + /// Creates a new heap-allocated matrix from the given [`VecStorage`]. /// /// This method exists primarily as a workaround for the fact that `from_data` can not /// work in `const fn` contexts. diff --git a/src/base/matrix_slice.rs b/src/base/matrix_slice.rs index bd4a66da..29aeb5ec 100644 --- a/src/base/matrix_slice.rs +++ b/src/base/matrix_slice.rs @@ -584,7 +584,7 @@ macro_rules! matrix_slice_impl( * Splitting. * */ - /// Splits this NxM matrix into two parts delimited by two ranges. + /// Splits this `NxM` matrix into two parts delimited by two ranges. /// /// Panics if the ranges overlap or if the first range is empty. #[inline] @@ -620,7 +620,7 @@ macro_rules! matrix_slice_impl( } } - /// Splits this NxM matrix into two parts delimited by two ranges. + /// Splits this `NxM` matrix into two parts delimited by two ranges. /// /// Panics if the ranges overlap or if the first range is empty. #[inline] diff --git a/src/base/norm.rs b/src/base/norm.rs index 09e11f7e..a8548ddd 100644 --- a/src/base/norm.rs +++ b/src/base/norm.rs @@ -40,10 +40,13 @@ pub trait Norm { } /// Euclidean norm. +#[derive(Copy, Clone, Debug)] pub struct EuclideanNorm; /// Lp norm. +#[derive(Copy, Clone, Debug)] pub struct LpNorm(pub i32); /// L-infinite norm aka. Chebytchev norm aka. uniform norm aka. suppremum norm. +#[derive(Copy, Clone, Debug)] pub struct UniformNorm; impl Norm for EuclideanNorm { diff --git a/src/base/unit.rs b/src/base/unit.rs index a6ca33f3..fb2f6efe 100644 --- a/src/base/unit.rs +++ b/src/base/unit.rs @@ -238,7 +238,7 @@ impl Unit { } /// Retrieves the underlying value. - /// Deprecated: use [Unit::into_inner] instead. + /// Deprecated: use [`Unit::into_inner`] instead. #[deprecated(note = "use `.into_inner()` instead")] #[inline] pub fn unwrap(self) -> T { diff --git a/src/base/vec_storage.rs b/src/base/vec_storage.rs index be567094..20cc5171 100644 --- a/src/base/vec_storage.rs +++ b/src/base/vec_storage.rs @@ -79,7 +79,7 @@ where } #[deprecated(note = "renamed to `VecStorage`")] -/// Renamed to [VecStorage]. +/// Renamed to [`VecStorage`]. pub type MatrixVec = VecStorage; impl VecStorage { diff --git a/src/geometry/dual_quaternion.rs b/src/geometry/dual_quaternion.rs index 6f54910b..6dd8936d 100644 --- a/src/geometry/dual_quaternion.rs +++ b/src/geometry/dual_quaternion.rs @@ -16,7 +16,7 @@ use simba::scalar::{ClosedNeg, RealField}; /// /// # Indexing /// -/// DualQuaternions are stored as \[..real, ..dual\]. +/// `DualQuaternions` are stored as \[..real, ..dual\]. /// Both of the quaternion components are laid out in `i, j, k, w` order. /// /// ``` @@ -36,7 +36,7 @@ use simba::scalar::{ClosedNeg, RealField}; /// NOTE: /// As of December 2020, dual quaternion support is a work in progress. /// If a feature that you need is missing, feel free to open an issue or a PR. -/// See https://github.com/dimforge/nalgebra/issues/487 +/// See #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct DualQuaternion { diff --git a/src/geometry/isometry_construction.rs b/src/geometry/isometry_construction.rs index 39a1d763..9b855599 100644 --- a/src/geometry/isometry_construction.rs +++ b/src/geometry/isometry_construction.rs @@ -308,7 +308,7 @@ macro_rules! look_at_isometry_construction_impl( $RotId::face_towards(&(target - eye), up)) } - /// Deprecated: Use [Isometry::face_towards] instead. + /// Deprecated: Use [`Isometry::face_towards`] instead. #[deprecated(note="renamed to `face_towards`")] pub fn new_observer_frame(eye: &Point3, target: &Point3, diff --git a/src/geometry/orthographic.rs b/src/geometry/orthographic.rs index 3a512d0b..b349a621 100644 --- a/src/geometry/orthographic.rs +++ b/src/geometry/orthographic.rs @@ -314,7 +314,7 @@ impl Orthographic3 { } /// Retrieves the underlying homogeneous matrix. - /// Deprecated: Use [Orthographic3::into_inner] instead. + /// Deprecated: Use [`Orthographic3::into_inner`] instead. #[deprecated(note = "use `.into_inner()` instead")] #[inline] pub fn unwrap(self) -> Matrix4 { diff --git a/src/geometry/perspective.rs b/src/geometry/perspective.rs index 86b4fd13..d5a6fe42 100644 --- a/src/geometry/perspective.rs +++ b/src/geometry/perspective.rs @@ -175,7 +175,7 @@ impl Perspective3 { } /// Retrieves the underlying homogeneous matrix. - /// Deprecated: Use [Perspective3::into_inner] instead. + /// Deprecated: Use [`Perspective3::into_inner`] instead. #[deprecated(note = "use `.into_inner()` instead")] #[inline] pub fn unwrap(self) -> Matrix4 { diff --git a/src/geometry/quaternion_construction.rs b/src/geometry/quaternion_construction.rs index f93069b4..61b1fe3e 100644 --- a/src/geometry/quaternion_construction.rs +++ b/src/geometry/quaternion_construction.rs @@ -591,7 +591,7 @@ where Self::from_rotation_matrix(&Rotation3::face_towards(dir, up)) } - /// Deprecated: Use [UnitQuaternion::face_towards] instead. + /// Deprecated: Use [`UnitQuaternion::face_towards`] instead. #[deprecated(note = "renamed to `face_towards`")] pub fn new_observer_frames(dir: &Vector, up: &Vector) -> Self where @@ -785,7 +785,7 @@ where Self::new_eps(axisangle, eps) } - /// Create the mean unit quaternion from a data structure implementing IntoIterator + /// Create the mean unit quaternion from a data structure implementing `IntoIterator` /// returning unit quaternions. /// /// The method will panic if the iterator does not return any quaternions. diff --git a/src/geometry/rotation.rs b/src/geometry/rotation.rs index dfaab9d7..33e42dda 100755 --- a/src/geometry/rotation.rs +++ b/src/geometry/rotation.rs @@ -244,7 +244,7 @@ impl Rotation { } /// Unwraps the underlying matrix. - /// Deprecated: Use [Rotation::into_inner] instead. + /// Deprecated: Use [`Rotation::into_inner`] instead. #[deprecated(note = "use `.into_inner()` instead")] #[inline] pub fn unwrap(self) -> SMatrix { diff --git a/src/geometry/rotation_specialization.rs b/src/geometry/rotation_specialization.rs index 2ad73c69..5cd44119 100644 --- a/src/geometry/rotation_specialization.rs +++ b/src/geometry/rotation_specialization.rs @@ -483,7 +483,7 @@ where )) } - /// Deprecated: Use [Rotation3::face_towards] instead. + /// Deprecated: Use [`Rotation3::face_towards`] instead. #[deprecated(note = "renamed to `face_towards`")] pub fn new_observer_frames(dir: &Vector, up: &Vector) -> Self where diff --git a/src/geometry/similarity_construction.rs b/src/geometry/similarity_construction.rs index 3c1b2b42..feb5719b 100644 --- a/src/geometry/similarity_construction.rs +++ b/src/geometry/similarity_construction.rs @@ -306,7 +306,7 @@ macro_rules! similarity_construction_impl( Self::from_isometry(Isometry::<_, $Rot, 3>::face_towards(eye, target, up), scaling) } - /// Deprecated: Use [SimilarityMatrix3::face_towards] instead. + /// Deprecated: Use [`SimilarityMatrix3::face_towards`] instead. #[deprecated(note="renamed to `face_towards`")] pub fn new_observer_frames(eye: &Point3, target: &Point3, diff --git a/src/geometry/transform.rs b/src/geometry/transform.rs index 435bac59..71544b59 100755 --- a/src/geometry/transform.rs +++ b/src/geometry/transform.rs @@ -305,7 +305,7 @@ where } /// Retrieves the underlying matrix. - /// Deprecated: Use [Transform::into_inner] instead. + /// Deprecated: Use [`Transform::into_inner`] instead. #[deprecated(note = "use `.into_inner()` instead")] #[inline] pub fn unwrap(self) -> OMatrix, U1>, DimNameSum, U1>> { diff --git a/src/lib.rs b/src/lib.rs index 28767346..e21f0709 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,3 @@ -#![allow(clippy::type_complexity)] /*! # nalgebra @@ -72,17 +71,18 @@ an optimized set of tools for computer graphics and physics. Those features incl * Insertion and removal of rows of columns of a matrix. */ -// #![feature(plugin)] -// -// #![plugin(clippy)] - -#![deny(non_camel_case_types)] -#![deny(unused_parens)] -#![deny(non_upper_case_globals)] -#![deny(unused_qualifications)] -#![deny(unused_results)] -#![deny(missing_docs)] -#![deny(rust_2018_idioms)] +#![allow(unused_variables, unused_mut)] +#![deny( + nonstandard_style, + unused_parens, + unused_qualifications, + unused_results, + missing_docs, + rust_2018_idioms, + rust_2018_compatibility, + future_incompatible, + missing_copy_implementations +)] #![doc( html_favicon_url = "https://nalgebra.org/img/favicon.ico", html_root_url = "https://docs.rs/nalgebra/0.25.0" @@ -246,7 +246,7 @@ pub fn min(a: T, b: T) -> T { /// The absolute value of `a`. /// -/// Deprecated: Use [Matrix::abs] or [RealField::abs] instead. +/// Deprecated: Use [`Matrix::abs`] or [`RealField::abs`] instead. #[deprecated(note = "use the inherent method `Matrix::abs` or `RealField::abs` instead")] #[inline] pub fn abs(a: &T) -> T { @@ -385,7 +385,7 @@ pub fn partial_sort2<'a, T: PartialOrd>(a: &'a T, b: &'a T) -> Option<(&'a T, &' /// # See also: /// /// * [distance](fn.distance.html) -/// * [distance_squared](fn.distance_squared.html) +/// * [`distance_squared`](fn.distance_squared.html) #[inline] pub fn center( p1: &Point, @@ -399,7 +399,7 @@ pub fn center( /// # See also: /// /// * [center](fn.center.html) -/// * [distance_squared](fn.distance_squared.html) +/// * [`distance_squared`](fn.distance_squared.html) #[inline] pub fn distance( p1: &Point, @@ -431,11 +431,11 @@ pub fn distance_squared( /// /// # See also: /// -/// * [convert_ref](fn.convert_ref.html) -/// * [convert_ref_unchecked](fn.convert_ref_unchecked.html) -/// * [is_convertible](../nalgebra/fn.is_convertible.html) -/// * [try_convert](fn.try_convert.html) -/// * [try_convert_ref](fn.try_convert_ref.html) +/// * [`convert_ref`](fn.convert_ref.html) +/// * [`convert_ref_unchecked`](fn.convert_ref_unchecked.html) +/// * [`is_convertible`](../nalgebra/fn.is_convertible.html) +/// * [`try_convert`](fn.try_convert.html) +/// * [`try_convert_ref`](fn.try_convert_ref.html) #[inline] pub fn convert>(t: From) -> To { To::from_subset(&t) @@ -448,10 +448,10 @@ pub fn convert>(t: From) -> To { /// # See also: /// /// * [convert](fn.convert.html) -/// * [convert_ref](fn.convert_ref.html) -/// * [convert_ref_unchecked](fn.convert_ref_unchecked.html) -/// * [is_convertible](../nalgebra/fn.is_convertible.html) -/// * [try_convert_ref](fn.try_convert_ref.html) +/// * [`convert_ref`](fn.convert_ref.html) +/// * [`convert_ref_unchecked`](fn.convert_ref_unchecked.html) +/// * [`is_convertible`](../nalgebra/fn.is_convertible.html) +/// * [`try_convert_ref`](fn.try_convert_ref.html) #[inline] pub fn try_convert, To>(t: From) -> Option { t.to_subset() @@ -463,10 +463,10 @@ pub fn try_convert, To>(t: From) -> Option { /// # See also: /// /// * [convert](fn.convert.html) -/// * [convert_ref](fn.convert_ref.html) -/// * [convert_ref_unchecked](fn.convert_ref_unchecked.html) -/// * [try_convert](fn.try_convert.html) -/// * [try_convert_ref](fn.try_convert_ref.html) +/// * [`convert_ref`](fn.convert_ref.html) +/// * [`convert_ref_unchecked`](fn.convert_ref_unchecked.html) +/// * [`try_convert`](fn.try_convert.html) +/// * [`try_convert_ref`](fn.try_convert_ref.html) #[inline] pub fn is_convertible, To>(t: &From) -> bool { t.is_in_subset() @@ -478,11 +478,11 @@ pub fn is_convertible, To>(t: &From) -> bool { /// # See also: /// /// * [convert](fn.convert.html) -/// * [convert_ref](fn.convert_ref.html) -/// * [convert_ref_unchecked](fn.convert_ref_unchecked.html) -/// * [is_convertible](../nalgebra/fn.is_convertible.html) -/// * [try_convert](fn.try_convert.html) -/// * [try_convert_ref](fn.try_convert_ref.html) +/// * [`convert_ref`](fn.convert_ref.html) +/// * [`convert_ref_unchecked`](fn.convert_ref_unchecked.html) +/// * [`is_convertible`](../nalgebra/fn.is_convertible.html) +/// * [`try_convert`](fn.try_convert.html) +/// * [`try_convert_ref`](fn.try_convert_ref.html) #[inline] pub fn convert_unchecked, To>(t: From) -> To { t.to_subset_unchecked() @@ -493,10 +493,10 @@ pub fn convert_unchecked, To>(t: From) -> To { /// # See also: /// /// * [convert](fn.convert.html) -/// * [convert_ref_unchecked](fn.convert_ref_unchecked.html) -/// * [is_convertible](../nalgebra/fn.is_convertible.html) -/// * [try_convert](fn.try_convert.html) -/// * [try_convert_ref](fn.try_convert_ref.html) +/// * [`convert_ref_unchecked`](fn.convert_ref_unchecked.html) +/// * [`is_convertible`](../nalgebra/fn.is_convertible.html) +/// * [`try_convert`](fn.try_convert.html) +/// * [`try_convert_ref`](fn.try_convert_ref.html) #[inline] pub fn convert_ref>(t: &From) -> To { To::from_subset(t) @@ -507,10 +507,10 @@ pub fn convert_ref>(t: &From) -> To { /// # See also: /// /// * [convert](fn.convert.html) -/// * [convert_ref](fn.convert_ref.html) -/// * [convert_ref_unchecked](fn.convert_ref_unchecked.html) -/// * [is_convertible](../nalgebra/fn.is_convertible.html) -/// * [try_convert](fn.try_convert.html) +/// * [`convert_ref`](fn.convert_ref.html) +/// * [`convert_ref_unchecked`](fn.convert_ref_unchecked.html) +/// * [`is_convertible`](../nalgebra/fn.is_convertible.html) +/// * [`try_convert`](fn.try_convert.html) #[inline] pub fn try_convert_ref, To>(t: &From) -> Option { t.to_subset() @@ -522,10 +522,10 @@ pub fn try_convert_ref, To>(t: &From) -> Option { /// # See also: /// /// * [convert](fn.convert.html) -/// * [convert_ref](fn.convert_ref.html) -/// * [is_convertible](../nalgebra/fn.is_convertible.html) -/// * [try_convert](fn.try_convert.html) -/// * [try_convert_ref](fn.try_convert_ref.html) +/// * [`convert_ref`](fn.convert_ref.html) +/// * [`is_convertible`](../nalgebra/fn.is_convertible.html) +/// * [`try_convert`](fn.try_convert.html) +/// * [`try_convert_ref`](fn.try_convert_ref.html) #[inline] pub fn convert_ref_unchecked, To>(t: &From) -> To { t.to_subset_unchecked() diff --git a/src/linalg/balancing.rs b/src/linalg/balancing.rs index 3965caf1..f4f8b659 100644 --- a/src/linalg/balancing.rs +++ b/src/linalg/balancing.rs @@ -11,7 +11,7 @@ use crate::base::{Const, DefaultAllocator, OMatrix, OVector}; /// Applies in-place a modified Parlett and Reinsch matrix balancing with 2-norm to the matrix and returns /// the corresponding diagonal transformation. /// -/// See https://arxiv.org/pdf/1401.5766.pdf +/// See pub fn balance_parlett_reinsch(matrix: &mut OMatrix) -> OVector where DefaultAllocator: Allocator + Allocator, diff --git a/src/linalg/col_piv_qr.rs b/src/linalg/col_piv_qr.rs index 1a56d2cb..fcd0f376 100644 --- a/src/linalg/col_piv_qr.rs +++ b/src/linalg/col_piv_qr.rs @@ -60,7 +60,7 @@ where + Allocator> + Allocator<(usize, usize), DimMinimum>, { - /// Computes the ColPivQR decomposition using householder reflections. + /// Computes the `ColPivQR` decomposition using householder reflections. pub fn new(mut matrix: OMatrix) -> Self { let (nrows, ncols) = matrix.data.shape(); let min_nrows_ncols = nrows.min(ncols); diff --git a/src/linalg/schur.rs b/src/linalg/schur.rs index c03f6f08..3b650c52 100644 --- a/src/linalg/schur.rs +++ b/src/linalg/schur.rs @@ -19,7 +19,7 @@ use crate::linalg::Hessenberg; /// Schur decomposition of a square matrix. /// -/// If this is a real matrix, this will be a RealField Schur decomposition. +/// If this is a real matrix, this will be a `RealField` Schur decomposition. #[cfg_attr(feature = "serde-serialize-no-std", derive(Serialize, Deserialize))] #[cfg_attr( feature = "serde-serialize-no-std", diff --git a/src/proptest/mod.rs b/src/proptest/mod.rs index 794080fe..a7cbe549 100644 --- a/src/proptest/mod.rs +++ b/src/proptest/mod.rs @@ -2,12 +2,12 @@ //! //! **This module is only available when the `proptest-support` feature is enabled in `nalgebra`**. //! -//! `proptest` is a library for *property-based testing*. While similar to QuickCheck, +//! `proptest` is a library for *property-based testing*. While similar to `QuickCheck`, //! which may be more familiar to some users, it has a more sophisticated design that //! provides users with automatic invariant-preserving shrinking. This means that when using //! `proptest`, you rarely need to write your own shrinkers - which is usually very difficult - //! and can instead get this "for free". Moreover, `proptest` does not rely on a canonical -//! `Arbitrary` trait implementation like QuickCheck, though it does also provide this. For +//! `Arbitrary` trait implementation like `QuickCheck`, though it does also provide this. For //! more information, check out the [proptest docs](https://docs.rs/proptest/0.10.1/proptest/) //! and the [proptest book](https://altsysrq.github.io/proptest-book/intro.html). //! @@ -316,7 +316,7 @@ where /// with length in the provided range. /// /// This is a convenience function for calling -/// [matrix(value_strategy, length, U1)](fn.matrix.html) and should +/// [`matrix(value_strategy, length, U1)`](fn.matrix.html) and should /// be used when you only want to generate column vectors, as it's simpler and makes the intent /// clear. pub fn vector( diff --git a/src/sparse/cs_matrix.rs b/src/sparse/cs_matrix.rs index cdacd044..0fc3fed7 100644 --- a/src/sparse/cs_matrix.rs +++ b/src/sparse/cs_matrix.rs @@ -46,7 +46,7 @@ impl<'a, T: Clone> Iterator for ColumnEntries<'a, T> { pub trait CsStorageIter<'a, T, R, C = U1> { /// Iterator through all the rows of a specific columns. /// - /// The elements are given as a tuple (row_index, value). + /// The elements are given as a tuple (`row_index`, value). type ColumnEntries: Iterator; /// Iterator through the row indices of a specific column. type ColumnRowIndices: Iterator; @@ -63,7 +63,7 @@ pub trait CsStorageIterMut<'a, T: 'a, R, C = U1> { type ValuesMut: Iterator; /// Mutable iterator through all the rows of a specific columns. /// - /// The elements are given as a tuple (row_index, value). + /// The elements are given as a tuple (`row_index`, value). type ColumnEntriesMut: Iterator; /// A mutable iterator through the values buffer of the sparse matrix. diff --git a/src/third_party/alga/alga_isometry.rs b/src/third_party/alga/alga_isometry.rs index e0ec2924..7633bf5c 100755 --- a/src/third_party/alga/alga_isometry.rs +++ b/src/third_party/alga/alga_isometry.rs @@ -120,7 +120,7 @@ where #[inline] fn decompose(&self) -> (Self::Translation, R, Id, R) { ( - self.translation.clone(), + self.translation, self.rotation.clone(), Id::new(), >::identity(), @@ -145,7 +145,7 @@ where #[inline] fn prepend_rotation(&self, r: &Self::Rotation) -> Self { - Isometry::from_parts(self.translation.clone(), self.rotation.prepend_rotation(r)) + Isometry::from_parts(self.translation, self.rotation.prepend_rotation(r)) } #[inline] @@ -175,7 +175,7 @@ where #[inline] fn translation(&self) -> Translation { - self.translation.clone() + self.translation } #[inline] diff --git a/src/third_party/alga/alga_rotation.rs b/src/third_party/alga/alga_rotation.rs index a63d7f84..cec4ae7d 100755 --- a/src/third_party/alga/alga_rotation.rs +++ b/src/third_party/alga/alga_rotation.rs @@ -105,17 +105,17 @@ impl AffineTransformati #[inline] fn decompose(&self) -> (Id, Self, Id, Self) { - (Id::new(), self.clone(), Id::new(), Self::identity()) + (Id::new(), *self, Id::new(), Self::identity()) } #[inline] fn append_translation(&self, _: &Self::Translation) -> Self { - self.clone() + *self } #[inline] fn prepend_translation(&self, _: &Self::Translation) -> Self { - self.clone() + *self } #[inline] @@ -130,12 +130,12 @@ impl AffineTransformati #[inline] fn append_scaling(&self, _: &Self::NonUniformScaling) -> Self { - self.clone() + *self } #[inline] fn prepend_scaling(&self, _: &Self::NonUniformScaling) -> Self { - self.clone() + *self } } @@ -151,7 +151,7 @@ impl Similarity Self { - self.clone() + *self } #[inline] diff --git a/src/third_party/alga/alga_similarity.rs b/src/third_party/alga/alga_similarity.rs index 3825b1c8..f0d29867 100755 --- a/src/third_party/alga/alga_similarity.rs +++ b/src/third_party/alga/alga_similarity.rs @@ -117,7 +117,7 @@ where #[inline] fn decompose(&self) -> (Translation, R, T, R) { ( - self.isometry.translation.clone(), + self.isometry.translation, self.isometry.rotation.clone(), self.scaling(), >::identity(), diff --git a/src/third_party/alga/alga_translation.rs b/src/third_party/alga/alga_translation.rs index 76a68355..246fe640 100755 --- a/src/third_party/alga/alga_translation.rs +++ b/src/third_party/alga/alga_translation.rs @@ -106,7 +106,7 @@ impl AffineTransformati #[inline] fn decompose(&self) -> (Self, Id, Id, Id) { - (self.clone(), Id::new(), Id::new(), Id::new()) + (*self, Id::new(), Id::new(), Id::new()) } #[inline] @@ -121,22 +121,22 @@ impl AffineTransformati #[inline] fn append_rotation(&self, _: &Self::Rotation) -> Self { - self.clone() + *self } #[inline] fn prepend_rotation(&self, _: &Self::Rotation) -> Self { - self.clone() + *self } #[inline] fn append_scaling(&self, _: &Self::NonUniformScaling) -> Self { - self.clone() + *self } #[inline] fn prepend_scaling(&self, _: &Self::NonUniformScaling) -> Self { - self.clone() + *self } } @@ -147,7 +147,7 @@ impl Similarity Self { - self.clone() + *self } #[inline] From 6eb642625b990d2206cdc6bafe3bc09609d81d6e Mon Sep 17 00:00:00 2001 From: Zacchary Dempsey-Plante Date: Fri, 30 Jul 2021 16:18:31 +0000 Subject: [PATCH 13/13] Fix a typo in the doc comment for `Mat2x3` Currently, the doc comment for `Mat2x3` incorrectly describes it as a 2x2 matrix. Obviously this is a very minor issue, but I figured it was worth fixing. --- nalgebra-glm/src/aliases.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nalgebra-glm/src/aliases.rs b/nalgebra-glm/src/aliases.rs index 0bf7b639..ad16828f 100644 --- a/nalgebra-glm/src/aliases.rs +++ b/nalgebra-glm/src/aliases.rs @@ -320,7 +320,7 @@ pub type DMat4x4 = Matrix4; pub type Mat2 = Matrix2; /// A 2x2 matrix with `f32` components. pub type Mat2x2 = Matrix2; -/// A 2x2 matrix with `f32` components. +/// A 2x3 matrix with `f32` components. pub type Mat2x3 = Matrix2x3; /// A 2x4 matrix with `f32` components. pub type Mat2x4 = Matrix2x4;