From 314b4dd1031200e580b82235c082dac7f9395702 Mon Sep 17 00:00:00 2001 From: CAD97 Date: Mon, 5 Jul 2021 19:04:10 -0500 Subject: [PATCH 1/2] Remove scalar bound from geometry type defs This was inconsistently applied, with some types having , some having , and some having . This unifies all types to match the convention of Matrix: Just declare at type def time, and apply bounds on impls only. A significant advantage of this approach is const fn construction. Const fn generics currently still can't have trait bounds, so any generic const fn needs to only move opaque types around. Construction methods such as new_unchecked or from_parts can be made const by removing their generic bounds after this PR. Actual constification is left to a follow-up PR. Note that na::Transform is _not_ loosened here, as it has more complicated definition requirements. --- src/geometry/dual_quaternion.rs | 13 +++++++++++-- src/geometry/isometry.rs | 2 +- src/geometry/orthographic.rs | 2 +- src/geometry/perspective.rs | 4 ++-- src/geometry/reflection.rs | 4 ++-- src/geometry/rotation.rs | 2 +- src/geometry/similarity.rs | 2 +- 7 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/geometry/dual_quaternion.rs b/src/geometry/dual_quaternion.rs index 631488360..17533dfb2 100644 --- a/src/geometry/dual_quaternion.rs +++ b/src/geometry/dual_quaternion.rs @@ -38,14 +38,23 @@ use simba::scalar::{ClosedNeg, RealField}; /// 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 #[repr(C)] -#[derive(Debug, Eq, PartialEq, Copy, Clone)] -pub struct DualQuaternion { +#[derive(Debug, Copy, Clone)] +pub struct DualQuaternion { /// The real component of the quaternion pub real: Quaternion, /// The dual component of the quaternion pub dual: Quaternion, } +impl Eq for DualQuaternion {} + +impl PartialEq for DualQuaternion { + #[inline] + fn eq(&self, right: &Self) -> bool { + self.real == right.real && self.dual == right.dual + } +} + impl Default for DualQuaternion { fn default() -> Self { Self { diff --git a/src/geometry/isometry.rs b/src/geometry/isometry.rs index 7d8c6e959..4e6c15d75 100755 --- a/src/geometry/isometry.rs +++ b/src/geometry/isometry.rs @@ -68,7 +68,7 @@ use crate::geometry::{AbstractRotation, Point, Translation}; DefaultAllocator: Allocator>, Owned>: Deserialize<'de>")) )] -pub struct Isometry { +pub struct Isometry { /// The pure rotational part of this isometry. pub rotation: R, /// The pure translational part of this isometry. diff --git a/src/geometry/orthographic.rs b/src/geometry/orthographic.rs index 17a5b9691..36c6ae7f7 100644 --- a/src/geometry/orthographic.rs +++ b/src/geometry/orthographic.rs @@ -18,7 +18,7 @@ use crate::base::{Matrix4, Vector, Vector3}; use crate::geometry::{Point3, Projective3}; /// A 3D orthographic projection stored as a homogeneous 4x4 matrix. -pub struct Orthographic3 { +pub struct Orthographic3 { matrix: Matrix4, } diff --git a/src/geometry/perspective.rs b/src/geometry/perspective.rs index 6ad9707ff..5c849a603 100644 --- a/src/geometry/perspective.rs +++ b/src/geometry/perspective.rs @@ -14,12 +14,12 @@ use simba::scalar::RealField; use crate::base::dimension::U3; use crate::base::storage::Storage; -use crate::base::{Matrix4, Scalar, Vector, Vector3}; +use crate::base::{Matrix4, Vector, Vector3}; use crate::geometry::{Point3, Projective3}; /// A 3D perspective projection stored as a homogeneous 4x4 matrix. -pub struct Perspective3 { +pub struct Perspective3 { matrix: Matrix4, } diff --git a/src/geometry/reflection.rs b/src/geometry/reflection.rs index dcc754c2f..51ee4e45c 100644 --- a/src/geometry/reflection.rs +++ b/src/geometry/reflection.rs @@ -1,5 +1,5 @@ use crate::base::constraint::{AreMultipliable, DimEq, SameNumberOfRows, ShapeConstraint}; -use crate::base::{Const, Matrix, Scalar, Unit, Vector}; +use crate::base::{Const, Matrix, Unit, Vector}; use crate::dimension::{Dim, U1}; use crate::storage::{Storage, StorageMut}; use simba::scalar::ComplexField; @@ -7,7 +7,7 @@ use simba::scalar::ComplexField; use crate::geometry::Point; /// A reflection wrt. a plane. -pub struct Reflection> { +pub struct Reflection { axis: Vector, bias: T, } diff --git a/src/geometry/rotation.rs b/src/geometry/rotation.rs index f3127fb91..3e74af656 100755 --- a/src/geometry/rotation.rs +++ b/src/geometry/rotation.rs @@ -55,7 +55,7 @@ use crate::geometry::Point; /// #[repr(C)] #[derive(Debug)] -pub struct Rotation { +pub struct Rotation { matrix: SMatrix, } diff --git a/src/geometry/similarity.rs b/src/geometry/similarity.rs index 48ce6a85e..6ae79c81b 100755 --- a/src/geometry/similarity.rs +++ b/src/geometry/similarity.rs @@ -39,7 +39,7 @@ use crate::geometry::{AbstractRotation, Isometry, Point, Translation}; DefaultAllocator: Allocator>, Owned>: Deserialize<'de>")) )] -pub struct Similarity { +pub struct Similarity { /// The part of this similarity that does not include the scaling factor. pub isometry: Isometry, scaling: T, From 85d07b22a3b07951f0022871fda1b88d449fcf71 Mon Sep 17 00:00:00 2001 From: CAD97 Date: Fri, 9 Jul 2021 15:30:06 -0500 Subject: [PATCH 2/2] FIx serde impl bounds --- src/geometry/isometry.rs | 6 ++++-- src/geometry/similarity.rs | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/geometry/isometry.rs b/src/geometry/isometry.rs index 4e6c15d75..333468b37 100755 --- a/src/geometry/isometry.rs +++ b/src/geometry/isometry.rs @@ -60,13 +60,15 @@ use crate::geometry::{AbstractRotation, Point, Translation}; feature = "serde-serialize-no-std", serde(bound(serialize = "R: Serialize, DefaultAllocator: Allocator>, - Owned>: Serialize")) + Owned>: Serialize, + T: Scalar")) )] #[cfg_attr( feature = "serde-serialize-no-std", serde(bound(deserialize = "R: Deserialize<'de>, DefaultAllocator: Allocator>, - Owned>: Deserialize<'de>")) + Owned>: Deserialize<'de>, + T: Scalar")) )] pub struct Isometry { /// The pure rotational part of this isometry. diff --git a/src/geometry/similarity.rs b/src/geometry/similarity.rs index 6ae79c81b..191644390 100755 --- a/src/geometry/similarity.rs +++ b/src/geometry/similarity.rs @@ -27,14 +27,14 @@ use crate::geometry::{AbstractRotation, Isometry, Point, Translation}; #[cfg_attr(feature = "serde-serialize-no-std", derive(Serialize, Deserialize))] #[cfg_attr( feature = "serde-serialize-no-std", - serde(bound(serialize = "T: Serialize, + serde(bound(serialize = "T: Scalar + Serialize, R: Serialize, DefaultAllocator: Allocator>, Owned>: Serialize")) )] #[cfg_attr( feature = "serde-serialize-no-std", - serde(bound(deserialize = "T: Deserialize<'de>, + serde(bound(deserialize = "T: Scalar + Deserialize<'de>, R: Deserialize<'de>, DefaultAllocator: Allocator>, Owned>: Deserialize<'de>"))