diff --git a/src/base/alias.rs b/src/base/alias.rs index 42cd37a6..fdfda45a 100644 --- a/src/base/alias.rs +++ b/src/base/alias.rs @@ -4,8 +4,7 @@ use crate::base::dimension::{U1, U2, U3, U4, U5, U6}; use crate::base::storage::Owned; #[cfg(any(feature = "std", feature = "alloc"))] use crate::base::vec_storage::VecStorage; -use crate::base::Matrix; -use crate::base::Unit; +use crate::base::{Const, Matrix, Unit}; /* * @@ -24,11 +23,14 @@ pub type MatrixNM = Matrix>; /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** pub type MatrixMN = Matrix>; +pub type CMatrixMN = + Matrix, Const, Owned, Const>>; /// A statically sized column-major square matrix with `D` rows and columns. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** pub type MatrixN = Matrix>; +pub type CMatrixN = Matrix, Const, Owned, Const>>; /// A dynamically sized column-major matrix. /// @@ -266,6 +268,7 @@ pub type DVector = Matrix>; /// A statically sized D-dimensional column vector. pub type VectorN = Matrix>; +pub type CVectorN = Matrix, U1, Owned, U1>>; /// A stack-allocated, 1-dimensional column vector. pub type Vector1 = Matrix>; diff --git a/src/base/cg.rs b/src/base/cg.rs index f63cca64..8ffec5cf 100644 --- a/src/base/cg.rs +++ b/src/base/cg.rs @@ -416,8 +416,8 @@ where #[inline] pub fn transform_point( &self, - pt: &Point>, - ) -> Point> { + pt: &Point::USIZE }>, + ) -> Point::USIZE }> { let transform = self.fixed_slice::, DimNameDiff>(0, 0); let translation = self.fixed_slice::, U1>(0, D::dim() - 1); let normalizer = self.fixed_slice::>(D::dim() - 1, 0); diff --git a/src/base/dimension.rs b/src/base/dimension.rs index ecc709fb..90a5bdd9 100644 --- a/src/base/dimension.rs +++ b/src/base/dimension.rs @@ -201,6 +201,8 @@ pub struct Const; /// Trait implemented exclusively by type-level integers. pub trait DimName: Dim { + const USIZE: usize; + /// The name of this dimension, i.e., the singleton `Self`. fn name() -> Self; @@ -233,6 +235,8 @@ impl Dim for Const { } impl DimName for Const { + const USIZE: usize = T; + #[inline] fn name() -> Self { Self diff --git a/src/geometry/abstract_rotation.rs b/src/geometry/abstract_rotation.rs index 52471851..2c44e46d 100644 --- a/src/geometry/abstract_rotation.rs +++ b/src/geometry/abstract_rotation.rs @@ -1,11 +1,10 @@ -use crate::allocator::Allocator; use crate::geometry::{Rotation, UnitComplex, UnitQuaternion}; -use crate::{DefaultAllocator, DimName, Point, Scalar, SimdRealField, Unit, VectorN, U2, U3}; +use crate::{CVectorN, Const, Point, Scalar, SimdRealField, Unit, VectorN}; use simba::scalar::ClosedMul; /// Trait implemented by rotations that can be used inside of an `Isometry` or `Similarity`. -pub trait AbstractRotation: PartialEq + ClosedMul + Clone { +pub trait AbstractRotation: PartialEq + ClosedMul + Clone { /// The rotation identity. fn identity() -> Self; /// The rotation inverse. @@ -13,34 +12,34 @@ pub trait AbstractRotation: PartialEq + ClosedMul + Clone /// Change `self` to its inverse. fn inverse_mut(&mut self); /// Apply the rotation to the given vector. - fn transform_vector(&self, v: &VectorN) -> VectorN - where - DefaultAllocator: Allocator; + fn transform_vector(&self, v: &CVectorN) -> CVectorN; + // where + // DefaultAllocator: Allocator; /// Apply the rotation to the given point. - fn transform_point(&self, p: &Point) -> Point - where - DefaultAllocator: Allocator; + fn transform_point(&self, p: &Point) -> Point; + // where + // DefaultAllocator: Allocator; /// Apply the inverse rotation to the given vector. - fn inverse_transform_vector(&self, v: &VectorN) -> VectorN - where - DefaultAllocator: Allocator; + fn inverse_transform_vector(&self, v: &VectorN>) -> VectorN>; + // where + // DefaultAllocator: Allocator; /// Apply the inverse rotation to the given unit vector. - fn inverse_transform_unit_vector(&self, v: &Unit>) -> Unit> - where - DefaultAllocator: Allocator, + fn inverse_transform_unit_vector(&self, v: &Unit>) -> Unit> +// where + // DefaultAllocator: Allocator, { Unit::new_unchecked(self.inverse_transform_vector(&**v)) } /// Apply the inverse rotation to the given point. - fn inverse_transform_point(&self, p: &Point) -> Point - where - DefaultAllocator: Allocator; + fn inverse_transform_point(&self, p: &Point) -> Point; + // where + // DefaultAllocator: Allocator; } -impl AbstractRotation for Rotation +impl AbstractRotation for Rotation where N::Element: SimdRealField, - DefaultAllocator: Allocator, + // DefaultAllocator: Allocator, { #[inline] fn identity() -> Self { @@ -58,47 +57,47 @@ where } #[inline] - fn transform_vector(&self, v: &VectorN) -> VectorN - where - DefaultAllocator: Allocator, + fn transform_vector(&self, v: &CVectorN) -> CVectorN +// where + // DefaultAllocator: Allocator, { self * v } #[inline] fn transform_point(&self, p: &Point) -> Point - where - DefaultAllocator: Allocator, +// where + // DefaultAllocator: Allocator, { self * p } #[inline] - fn inverse_transform_vector(&self, v: &VectorN) -> VectorN - where - DefaultAllocator: Allocator, + fn inverse_transform_vector(&self, v: &CVectorN) -> CVectorN +// where + // DefaultAllocator: Allocator, { self.inverse_transform_vector(v) } #[inline] - fn inverse_transform_unit_vector(&self, v: &Unit>) -> Unit> - where - DefaultAllocator: Allocator, + fn inverse_transform_unit_vector(&self, v: &Unit>) -> Unit> +// where + // DefaultAllocator: Allocator, { self.inverse_transform_unit_vector(v) } #[inline] fn inverse_transform_point(&self, p: &Point) -> Point - where - DefaultAllocator: Allocator, +// where + // DefaultAllocator: Allocator, { self.inverse_transform_point(p) } } -impl AbstractRotation for UnitQuaternion +impl AbstractRotation for UnitQuaternion where N::Element: SimdRealField, { @@ -118,27 +117,27 @@ where } #[inline] - fn transform_vector(&self, v: &VectorN) -> VectorN { + fn transform_vector(&self, v: &CVectorN) -> CVectorN { self * v } #[inline] - fn transform_point(&self, p: &Point) -> Point { + fn transform_point(&self, p: &Point) -> Point { self * p } #[inline] - fn inverse_transform_vector(&self, v: &VectorN) -> VectorN { + fn inverse_transform_vector(&self, v: &CVectorN) -> CVectorN { self.inverse_transform_vector(v) } #[inline] - fn inverse_transform_point(&self, p: &Point) -> Point { + fn inverse_transform_point(&self, p: &Point) -> Point { self.inverse_transform_point(p) } } -impl AbstractRotation for UnitComplex +impl AbstractRotation for UnitComplex where N::Element: SimdRealField, { @@ -158,22 +157,22 @@ where } #[inline] - fn transform_vector(&self, v: &VectorN) -> VectorN { + fn transform_vector(&self, v: &CVectorN) -> CVectorN { self * v } #[inline] - fn transform_point(&self, p: &Point) -> Point { + fn transform_point(&self, p: &Point) -> Point { self * p } #[inline] - fn inverse_transform_vector(&self, v: &VectorN) -> VectorN { + fn inverse_transform_vector(&self, v: &CVectorN) -> CVectorN { self.inverse_transform_vector(v) } #[inline] - fn inverse_transform_point(&self, p: &Point) -> Point { + fn inverse_transform_point(&self, p: &Point) -> Point { self.inverse_transform_point(p) } } diff --git a/src/geometry/dual_quaternion_conversion.rs b/src/geometry/dual_quaternion_conversion.rs index 20c6895a..26f3592e 100644 --- a/src/geometry/dual_quaternion_conversion.rs +++ b/src/geometry/dual_quaternion_conversion.rs @@ -1,7 +1,6 @@ use simba::scalar::{RealField, SubsetOf, SupersetOf}; use simba::simd::SimdRealField; -use crate::base::dimension::U3; use crate::base::{Matrix4, Vector4}; use crate::geometry::{ DualQuaternion, Isometry3, Similarity3, SuperTCategoryOf, TAffine, Transform, Translation3, @@ -14,9 +13,9 @@ use crate::geometry::{ * * DualQuaternion -> DualQuaternion * UnitDualQuaternion -> UnitDualQuaternion - * UnitDualQuaternion -> Isometry - * UnitDualQuaternion -> Similarity - * UnitDualQuaternion -> Transform + * UnitDualQuaternion -> Isometry<3> + * UnitDualQuaternion -> Similarity<3> + * UnitDualQuaternion -> Transform<3> * UnitDualQuaternion -> Matrix (homogeneous) * * NOTE: @@ -115,24 +114,24 @@ where } } -impl SubsetOf> for UnitDualQuaternion +impl SubsetOf> for UnitDualQuaternion where N1: RealField, N2: RealField + SupersetOf, C: SuperTCategoryOf, { #[inline] - fn to_superset(&self) -> Transform { + fn to_superset(&self) -> Transform { Transform::from_matrix_unchecked(self.to_homogeneous().to_superset()) } #[inline] - fn is_in_subset(t: &Transform) -> bool { + fn is_in_subset(t: &Transform) -> bool { >::is_in_subset(t.matrix()) } #[inline] - fn from_superset_unchecked(t: &Transform) -> Self { + fn from_superset_unchecked(t: &Transform) -> Self { Self::from_superset_unchecked(t.matrix()) } } diff --git a/src/geometry/isometry.rs b/src/geometry/isometry.rs index 7e4b703d..144f86b9 100755 --- a/src/geometry/isometry.rs +++ b/src/geometry/isometry.rs @@ -14,9 +14,9 @@ use simba::scalar::{RealField, SubsetOf}; use simba::simd::SimdRealField; use crate::base::allocator::Allocator; -use crate::base::dimension::{DimName, DimNameAdd, DimNameSum, U1}; +use crate::base::dimension::{DimNameAdd, DimNameSum, U1}; use crate::base::storage::Owned; -use crate::base::{DefaultAllocator, MatrixN, Scalar, Unit, VectorN}; +use crate::base::{CVectorN, Const, DefaultAllocator, MatrixN, Scalar, Unit}; use crate::geometry::{AbstractRotation, Point, Translation}; /// A direct isometry, i.e., a rotation followed by a translation (aka. a rigid-body motion). @@ -68,9 +68,9 @@ use crate::geometry::{AbstractRotation, Point, Translation}; DefaultAllocator: Allocator, Owned: Deserialize<'de>")) )] -pub struct Isometry -where - DefaultAllocator: Allocator, +pub struct Isometry +// where +// DefaultAllocator: Allocator, { /// The pure rotational part of this isometry. pub rotation: R, @@ -79,13 +79,12 @@ where } #[cfg(feature = "abomonation-serialize")] -impl Abomonation for Isometry +impl Abomonation for Isometry where N: SimdRealField, - D: DimName, R: Abomonation, Translation: Abomonation, - DefaultAllocator: Allocator, + // DefaultAllocator: Allocator, { unsafe fn entomb(&self, writer: &mut W) -> IOResult<()> { self.rotation.entomb(writer)?; @@ -103,11 +102,10 @@ where } } -impl hash::Hash - for Isometry +impl hash::Hash for Isometry where - DefaultAllocator: Allocator, - Owned: hash::Hash, + // DefaultAllocator: Allocator, + Owned>: hash::Hash, { fn hash(&self, state: &mut H) { self.translation.hash(state); @@ -115,16 +113,15 @@ where } } -impl Copy for Isometry -where - DefaultAllocator: Allocator, - Owned: Copy, +impl Copy for Isometry where + // DefaultAllocator: Allocator, + Owned>: Copy { } -impl Clone for Isometry -where - DefaultAllocator: Allocator, +impl Clone for Isometry +// where +// DefaultAllocator: Allocator, { #[inline] fn clone(&self) -> Self { @@ -135,9 +132,9 @@ where } } /// # From the translation and rotation parts -impl> Isometry -where - DefaultAllocator: Allocator, +impl, const D: usize> Isometry +// where +// DefaultAllocator: Allocator, { /// Creates a new isometry from its rotational and translational parts. /// @@ -163,10 +160,10 @@ where } /// # Inversion and in-place composition -impl> Isometry +impl, const D: usize> Isometry where N::Element: SimdRealField, - DefaultAllocator: Allocator, + // DefaultAllocator: Allocator, { /// Inverts `self`. /// @@ -223,7 +220,7 @@ where /// assert_eq!(iso1.inverse() * iso2, iso1.inv_mul(&iso2)); /// ``` #[inline] - pub fn inv_mul(&self, rhs: &Isometry) -> Self { + pub fn inv_mul(&self, rhs: &Isometry) -> Self { let inv_rot1 = self.rotation.inverse(); let tr_12 = rhs.translation.vector.clone() - self.translation.vector.clone(); Isometry::from_parts( @@ -318,10 +315,10 @@ where } /// # Transformation of a vector or a point -impl> Isometry +impl, const D: usize> Isometry where N::Element: SimdRealField, - DefaultAllocator: Allocator, + // DefaultAllocator: Allocator, { /// Transform the given point by this isometry. /// @@ -364,7 +361,7 @@ where /// assert_relative_eq!(transformed_point, Vector3::new(3.0, 2.0, -1.0), epsilon = 1.0e-6); /// ``` #[inline] - pub fn transform_vector(&self, v: &VectorN) -> VectorN { + pub fn transform_vector(&self, v: &CVectorN) -> CVectorN { self * v } @@ -410,7 +407,7 @@ where /// assert_relative_eq!(transformed_point, Vector3::new(-3.0, 2.0, 1.0), epsilon = 1.0e-6); /// ``` #[inline] - pub fn inverse_transform_vector(&self, v: &VectorN) -> VectorN { + pub fn inverse_transform_vector(&self, v: &CVectorN) -> CVectorN { self.rotation.inverse_transform_vector(v) } @@ -433,7 +430,7 @@ where /// assert_relative_eq!(transformed_point, -Vector3::y_axis(), epsilon = 1.0e-6); /// ``` #[inline] - pub fn inverse_transform_unit_vector(&self, v: &Unit>) -> Unit> { + pub fn inverse_transform_unit_vector(&self, v: &Unit>) -> Unit> { self.rotation.inverse_transform_unit_vector(v) } } @@ -443,9 +440,9 @@ where // This is OK since all constructors of the isometry enforce the Rotation bound already (and // explicit struct construction is prevented by the dummy ZST field). /// # Conversion to a matrix -impl Isometry -where - DefaultAllocator: Allocator, +impl Isometry +// where +// DefaultAllocator: Allocator, { /// Converts this isometry into its equivalent homogeneous transformation matrix. /// @@ -465,14 +462,14 @@ where /// assert_relative_eq!(iso.to_homogeneous(), expected, epsilon = 1.0e-6); /// ``` #[inline] - pub fn to_homogeneous(&self) -> MatrixN> + pub fn to_homogeneous(&self) -> MatrixN, U1>> where - D: DimNameAdd, - R: SubsetOf>>, - DefaultAllocator: Allocator, DimNameSum>, + Const: DimNameAdd, + R: SubsetOf, U1>>>, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, { let mut res: MatrixN = crate::convert_ref(&self.rotation); - res.fixed_slice_mut::(0, D::dim()) + res.fixed_slice_mut::, U1>(0, D) .copy_from(&self.translation.vector); res @@ -496,27 +493,25 @@ where /// assert_relative_eq!(iso.to_matrix(), expected, epsilon = 1.0e-6); /// ``` #[inline] - pub fn to_matrix(&self) -> MatrixN> + pub fn to_matrix(&self) -> MatrixN, U1>> where - D: DimNameAdd, - R: SubsetOf>>, - DefaultAllocator: Allocator, DimNameSum>, + Const: DimNameAdd, + R: SubsetOf, U1>>>, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, { self.to_homogeneous() } } -impl Eq for Isometry -where - R: AbstractRotation + Eq, - DefaultAllocator: Allocator, +impl Eq for Isometry where + R: AbstractRotation + Eq // DefaultAllocator: Allocator, { } -impl PartialEq for Isometry +impl PartialEq for Isometry where R: AbstractRotation + PartialEq, - DefaultAllocator: Allocator, + // DefaultAllocator: Allocator, { #[inline] fn eq(&self, right: &Self) -> bool { @@ -524,10 +519,10 @@ where } } -impl AbsDiffEq for Isometry +impl AbsDiffEq for Isometry where R: AbstractRotation + AbsDiffEq, - DefaultAllocator: Allocator, + // DefaultAllocator: Allocator, N::Epsilon: Copy, { type Epsilon = N::Epsilon; @@ -544,10 +539,10 @@ where } } -impl RelativeEq for Isometry +impl RelativeEq for Isometry where R: AbstractRotation + RelativeEq, - DefaultAllocator: Allocator, + // DefaultAllocator: Allocator, N::Epsilon: Copy, { #[inline] @@ -570,10 +565,10 @@ where } } -impl UlpsEq for Isometry +impl UlpsEq for Isometry where R: AbstractRotation + UlpsEq, - DefaultAllocator: Allocator, + // DefaultAllocator: Allocator, N::Epsilon: Copy, { #[inline] @@ -594,10 +589,10 @@ where * Display * */ -impl fmt::Display for Isometry +impl fmt::Display for Isometry where R: fmt::Display, - DefaultAllocator: Allocator + Allocator, + // DefaultAllocator: Allocator + Allocator, { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let precision = f.precision().unwrap_or(3); diff --git a/src/geometry/isometry_alias.rs b/src/geometry/isometry_alias.rs index 8eecd3ee..3ac2db56 100644 --- a/src/geometry/isometry_alias.rs +++ b/src/geometry/isometry_alias.rs @@ -1,5 +1,3 @@ -use crate::base::dimension::{U2, U3}; - use crate::geometry::{Isometry, Rotation2, Rotation3, UnitComplex, UnitQuaternion}; /// A 2-dimensional direct isometry using a unit complex number for its rotational part. @@ -8,28 +6,28 @@ use crate::geometry::{Isometry, Rotation2, Rotation3, UnitComplex, UnitQuaternio /// /// Also known as a 2D rigid-body motion, or as an element of SE(2). -pub type Isometry2 = Isometry>; +pub type Isometry2 = Isometry, 2>; /// A 3-dimensional direct isometry using a unit quaternion for its rotational part. /// /// **Because this is an alias, not all its methods are listed here. See the [`Isometry`](crate::Isometry) type too.** /// /// Also known as a rigid-body motion, or as an element of SE(3). -pub type Isometry3 = Isometry>; +pub type Isometry3 = Isometry, 3>; /// A 2-dimensional direct isometry using a rotation matrix for its rotational part. /// /// **Because this is an alias, not all its methods are listed here. See the [`Isometry`](crate::Isometry) type too.** /// /// Also known as a rigid-body motion, or as an element of SE(2). -pub type IsometryMatrix2 = Isometry>; +pub type IsometryMatrix2 = Isometry, 2>; /// A 3-dimensional direct isometry using a rotation matrix for its rotational part. /// /// **Because this is an alias, not all its methods are listed here. See the [`Isometry`](crate::Isometry) type too.** /// /// Also known as a rigid-body motion, or as an element of SE(3). -pub type IsometryMatrix3 = Isometry>; +pub type IsometryMatrix3 = Isometry, 3>; // This tests that the types correctly implement `Copy`, without having to run tests // (when targeting no-std for example). diff --git a/src/geometry/isometry_construction.rs b/src/geometry/isometry_construction.rs index 1edf269b..7a6b870f 100644 --- a/src/geometry/isometry_construction.rs +++ b/src/geometry/isometry_construction.rs @@ -13,9 +13,8 @@ use rand::{ use simba::scalar::SupersetOf; use simba::simd::SimdRealField; -use crate::base::allocator::Allocator; -use crate::base::dimension::{DimName, U2}; -use crate::base::{DefaultAllocator, Vector2, Vector3}; +use crate::base::dimension::U2; +use crate::base::{Vector2, Vector3}; use crate::{ AbstractRotation, Isometry, Isometry2, Isometry3, IsometryMatrix2, IsometryMatrix3, Point, @@ -23,10 +22,10 @@ use crate::{ UnitQuaternion, }; -impl> Isometry +impl, const D: usize> Isometry where N::Element: SimdRealField, - DefaultAllocator: Allocator, + // DefaultAllocator: Allocator, { /// Creates a new identity isometry. /// @@ -71,10 +70,10 @@ where } } -impl> One for Isometry +impl, const D: usize> One for Isometry where N::Element: SimdRealField, - DefaultAllocator: Allocator, + // DefaultAllocator: Allocator, { /// Creates a new identity isometry. #[inline] @@ -84,26 +83,26 @@ where } #[cfg(feature = "rand-no-std")] -impl Distribution> for Standard +impl Distribution> for Standard where R: AbstractRotation, Standard: Distribution + Distribution, - DefaultAllocator: Allocator, + // DefaultAllocator: Allocator, { #[inline] - fn sample<'a, G: Rng + ?Sized>(&self, rng: &'a mut G) -> Isometry { + fn sample<'a, G: Rng + ?Sized>(&self, rng: &'a mut G) -> Isometry { Isometry::from_parts(rng.gen(), rng.gen()) } } #[cfg(feature = "arbitrary")] -impl Arbitrary for Isometry +impl Arbitrary for Isometry where N: SimdRealField + Arbitrary + Send, N::Element: SimdRealField, R: AbstractRotation + Arbitrary + Send, Owned: Send, - DefaultAllocator: Allocator, + // DefaultAllocator: Allocator, { #[inline] fn arbitrary(rng: &mut Gen) -> Self { diff --git a/src/geometry/isometry_conversion.rs b/src/geometry/isometry_conversion.rs index 0c89958a..e75570c2 100644 --- a/src/geometry/isometry_conversion.rs +++ b/src/geometry/isometry_conversion.rs @@ -2,8 +2,8 @@ use simba::scalar::{RealField, SubsetOf, SupersetOf}; use simba::simd::{PrimitiveSimdValue, SimdRealField, SimdValue}; use crate::base::allocator::Allocator; -use crate::base::dimension::{DimMin, DimName, DimNameAdd, DimNameSum, U1}; -use crate::base::{DefaultAllocator, MatrixN, Scalar}; +use crate::base::dimension::{DimMin, DimNameAdd, DimNameSum, U1}; +use crate::base::{Const, DefaultAllocator, MatrixN, Scalar}; use crate::geometry::{ AbstractRotation, Isometry, Isometry3, Similarity, SuperTCategoryOf, TAffine, Transform, @@ -21,27 +21,27 @@ use crate::geometry::{ * Isometry -> Matrix (homogeneous) */ -impl SubsetOf> for Isometry +impl SubsetOf> for Isometry where N1: RealField, N2: RealField + SupersetOf, R1: AbstractRotation + SubsetOf, R2: AbstractRotation, - DefaultAllocator: Allocator + Allocator, + // DefaultAllocator: Allocator + Allocator, { #[inline] - fn to_superset(&self) -> Isometry { + fn to_superset(&self) -> Isometry { Isometry::from_parts(self.translation.to_superset(), self.rotation.to_superset()) } #[inline] - fn is_in_subset(iso: &Isometry) -> bool { + fn is_in_subset(iso: &Isometry) -> bool { crate::is_convertible::<_, Translation>(&iso.translation) && crate::is_convertible::<_, R1>(&iso.rotation) } #[inline] - fn from_superset_unchecked(iso: &Isometry) -> Self { + fn from_superset_unchecked(iso: &Isometry) -> Self { Isometry::from_parts( iso.translation.to_subset_unchecked(), iso.rotation.to_subset_unchecked(), @@ -73,102 +73,101 @@ where } } -impl SubsetOf> for Isometry +impl SubsetOf> for Isometry where N1: RealField, N2: RealField + SupersetOf, R1: AbstractRotation + SubsetOf, R2: AbstractRotation, - DefaultAllocator: Allocator + Allocator, + // DefaultAllocator: Allocator + Allocator, { #[inline] - fn to_superset(&self) -> Similarity { + fn to_superset(&self) -> Similarity { Similarity::from_isometry(self.to_superset(), N2::one()) } #[inline] - fn is_in_subset(sim: &Similarity) -> bool { - crate::is_convertible::<_, Isometry>(&sim.isometry) && sim.scaling() == N2::one() + fn is_in_subset(sim: &Similarity) -> bool { + crate::is_convertible::<_, Isometry>(&sim.isometry) && sim.scaling() == N2::one() } #[inline] - fn from_superset_unchecked(sim: &Similarity) -> Self { + fn from_superset_unchecked(sim: &Similarity) -> Self { crate::convert_ref_unchecked(&sim.isometry) } } -impl SubsetOf> for Isometry +impl SubsetOf> for Isometry where N1: RealField, N2: RealField + SupersetOf, C: SuperTCategoryOf, R: AbstractRotation - + SubsetOf>> - + SubsetOf>>, - D: DimNameAdd + DimMin, // needed by .is_special_orthogonal() - DefaultAllocator: Allocator - + Allocator - + Allocator, DimNameSum> - + Allocator, DimNameSum> - + Allocator, DimNameSum> - + Allocator<(usize, usize), D> - + Allocator - + Allocator, + + SubsetOf, U1>>> + + SubsetOf, U1>>>, + Const: DimNameAdd + DimMin, Output = Const>, // needed by .is_special_orthogonal() + DefaultAllocator: Allocator, U1>, DimNameSum, U1>> + + Allocator, U1>, DimNameSum, U1>> + + Allocator, U1>, DimNameSum, U1>>, + // + Allocator + // + Allocator<(usize, usize), D> + // + Allocator + // + Allocator { #[inline] - fn to_superset(&self) -> Transform { + fn to_superset(&self) -> Transform { Transform::from_matrix_unchecked(self.to_homogeneous().to_superset()) } #[inline] - fn is_in_subset(t: &Transform) -> bool { + fn is_in_subset(t: &Transform) -> bool { >::is_in_subset(t.matrix()) } #[inline] - fn from_superset_unchecked(t: &Transform) -> Self { + fn from_superset_unchecked(t: &Transform) -> Self { Self::from_superset_unchecked(t.matrix()) } } -impl SubsetOf>> for Isometry +impl SubsetOf, U1>>> + for Isometry where N1: RealField, N2: RealField + SupersetOf, R: AbstractRotation - + SubsetOf>> - + SubsetOf>>, - D: DimNameAdd + DimMin, // needed by .is_special_orthogonal() - DefaultAllocator: Allocator - + Allocator - + Allocator, DimNameSum> - + Allocator, DimNameSum> - + Allocator, DimNameSum> - + Allocator<(usize, usize), D> - + Allocator - + Allocator, + + SubsetOf, U1>>> + + SubsetOf, U1>>>, + Const: DimNameAdd + DimMin, Output = Const>, // needed by .is_special_orthogonal() + DefaultAllocator: Allocator, U1>, DimNameSum, U1>> + + Allocator, U1>, DimNameSum, U1>> + + Allocator, U1>, DimNameSum, U1>>, // + Allocator<(usize, usize), D> + // + Allocator + // + Allocator + // + Allocator + // + Allocator { #[inline] - fn to_superset(&self) -> MatrixN> { + fn to_superset(&self) -> MatrixN, U1>> { self.to_homogeneous().to_superset() } #[inline] - fn is_in_subset(m: &MatrixN>) -> bool { + fn is_in_subset(m: &MatrixN, U1>>) -> bool { let rot = m.fixed_slice::(0, 0); - let bottom = m.fixed_slice::(D::dim(), 0); + let bottom = m.fixed_slice::(D, 0); // Scalar types agree. m.iter().all(|e| SupersetOf::::is_in_subset(e)) && // The block part is a rotation. rot.is_special_orthogonal(N2::default_epsilon() * crate::convert(100.0)) && // The bottom row is (0, 0, ..., 1) - bottom.iter().all(|e| e.is_zero()) && m[(D::dim(), D::dim())] == N2::one() + bottom.iter().all(|e| e.is_zero()) && m[(D, D)] == N2::one() } #[inline] - fn from_superset_unchecked(m: &MatrixN>) -> Self { - let t = m.fixed_slice::(0, D::dim()).into_owned(); + fn from_superset_unchecked(m: &MatrixN, U1>>) -> Self { + let t = m.fixed_slice::(0, D).into_owned(); let t = Translation { vector: crate::convert_unchecked(t), }; @@ -177,10 +176,10 @@ where } } -impl> From> - for Isometry -where - DefaultAllocator: Allocator, +impl, const D: usize> From> + for Isometry +// where +// DefaultAllocator: Allocator, { #[inline] fn from(tra: Translation) -> Self { @@ -188,30 +187,31 @@ where } } -impl From> for MatrixN> +impl From> + for MatrixN, U1>> where - D: DimNameAdd, - R: SubsetOf>>, - DefaultAllocator: Allocator, DimNameSum> + Allocator, + Const: DimNameAdd, + R: SubsetOf, U1>>>, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, // + Allocator, { #[inline] - fn from(iso: Isometry) -> Self { + fn from(iso: Isometry) -> Self { iso.to_homogeneous() } } -impl From<[Isometry; 2]> - for Isometry +impl + From<[Isometry; 2]> for Isometry where N: From<[::Element; 2]>, R: SimdValue + AbstractRotation + From<[::Element; 2]>, R::Element: AbstractRotation, N::Element: Scalar + Copy, R::Element: Scalar + Copy, - DefaultAllocator: Allocator + Allocator, + // DefaultAllocator: Allocator + Allocator, { #[inline] - fn from(arr: [Isometry; 2]) -> Self { + fn from(arr: [Isometry; 2]) -> Self { let tra = Translation::from([arr[0].translation.clone(), arr[1].translation.clone()]); let rot = R::from([arr[0].rotation, arr[0].rotation]); @@ -219,18 +219,18 @@ where } } -impl From<[Isometry; 4]> - for Isometry +impl + From<[Isometry; 4]> for Isometry where N: From<[::Element; 4]>, R: SimdValue + AbstractRotation + From<[::Element; 4]>, R::Element: AbstractRotation, N::Element: Scalar + Copy, R::Element: Scalar + Copy, - DefaultAllocator: Allocator + Allocator, + // DefaultAllocator: Allocator + Allocator, { #[inline] - fn from(arr: [Isometry; 4]) -> Self { + fn from(arr: [Isometry; 4]) -> Self { let tra = Translation::from([ arr[0].translation.clone(), arr[1].translation.clone(), @@ -248,18 +248,18 @@ where } } -impl From<[Isometry; 8]> - for Isometry +impl + From<[Isometry; 8]> for Isometry where N: From<[::Element; 8]>, R: SimdValue + AbstractRotation + From<[::Element; 8]>, R::Element: AbstractRotation, N::Element: Scalar + Copy, R::Element: Scalar + Copy, - DefaultAllocator: Allocator + Allocator, + // DefaultAllocator: Allocator + Allocator, { #[inline] - fn from(arr: [Isometry; 8]) -> Self { + fn from(arr: [Isometry; 8]) -> Self { let tra = Translation::from([ arr[0].translation.clone(), arr[1].translation.clone(), @@ -285,18 +285,18 @@ where } } -impl From<[Isometry; 16]> - for Isometry +impl + From<[Isometry; 16]> for Isometry where N: From<[::Element; 16]>, R: SimdValue + AbstractRotation + From<[::Element; 16]>, R::Element: AbstractRotation, N::Element: Scalar + Copy, R::Element: Scalar + Copy, - DefaultAllocator: Allocator + Allocator, + // DefaultAllocator: Allocator + Allocator, { #[inline] - fn from(arr: [Isometry; 16]) -> Self { + fn from(arr: [Isometry; 16]) -> Self { let tra = Translation::from([ arr[0].translation.clone(), arr[1].translation.clone(), diff --git a/src/geometry/isometry_simba.rs b/src/geometry/isometry_simba.rs index e5d2c839..1db8dd43 100755 --- a/src/geometry/isometry_simba.rs +++ b/src/geometry/isometry_simba.rs @@ -1,20 +1,17 @@ use simba::simd::SimdValue; -use crate::base::allocator::Allocator; -use crate::base::dimension::DimName; -use crate::base::DefaultAllocator; use crate::SimdRealField; use crate::geometry::{AbstractRotation, Isometry, Translation}; -impl SimdValue for Isometry +impl SimdValue for Isometry where N::Element: SimdRealField, R: SimdValue + AbstractRotation, R::Element: AbstractRotation, - DefaultAllocator: Allocator + Allocator, + // DefaultAllocator: Allocator + Allocator, { - type Element = Isometry; + type Element = Isometry; type SimdBool = N::SimdBool; #[inline] diff --git a/src/geometry/point.rs b/src/geometry/point.rs index 5d8b6fbd..307f0b17 100644 --- a/src/geometry/point.rs +++ b/src/geometry/point.rs @@ -40,54 +40,49 @@ use crate::base::{Const, DefaultAllocator, Scalar, VectorN}; /// of said transformations for details. #[repr(C)] #[derive(Debug, Clone)] -pub struct Point -where - DefaultAllocator: Allocator, -{ +pub struct Point { /// The coordinates of this point, i.e., the shift from the origin. - pub coords: VectorN, + pub coords: VectorN>, } -impl hash::Hash for Point -where - DefaultAllocator: Allocator, - >::Buffer: hash::Hash, +impl hash::Hash for Point +// where +// DefaultAllocator: Allocator, +// >::Buffer: hash::Hash, { fn hash(&self, state: &mut H) { self.coords.hash(state) } } -impl Copy for Point -where - DefaultAllocator: Allocator, - >::Buffer: Copy, +impl Copy for Point +// where +// DefaultAllocator: Allocator, +// >::Buffer: Copy, { } #[cfg(feature = "bytemuck")] -unsafe impl bytemuck::Zeroable for Point -where - VectorN: bytemuck::Zeroable, - DefaultAllocator: Allocator, +unsafe impl bytemuck::Zeroable for Point where + VectorN>: bytemuck::Zeroable // DefaultAllocator: Allocator, { } #[cfg(feature = "bytemuck")] -unsafe impl bytemuck::Pod for Point +unsafe impl bytemuck::Pod for Point where N: Copy, - VectorN: bytemuck::Pod, - DefaultAllocator: Allocator, - >::Buffer: Copy, + VectorN>: bytemuck::Pod, + // DefaultAllocator: Allocator, + // >::Buffer: Copy, { } #[cfg(feature = "serde-serialize")] -impl Serialize for Point -where - DefaultAllocator: Allocator, - >::Buffer: Serialize, +impl Serialize for Point +// where +// DefaultAllocator: Allocator, +// >::Buffer: Serialize, { fn serialize(&self, serializer: S) -> Result where @@ -98,10 +93,10 @@ where } #[cfg(feature = "serde-serialize")] -impl<'a, N: Scalar, D: DimName> Deserialize<'a> for Point -where - DefaultAllocator: Allocator, - >::Buffer: Deserialize<'a>, +impl<'a, N: Scalar, const D: usize> Deserialize<'a> for Point +// where +// DefaultAllocator: Allocator, +// >::Buffer: Deserialize<'a>, { fn deserialize(deserializer: Des) -> Result where @@ -114,12 +109,11 @@ where } #[cfg(feature = "abomonation-serialize")] -impl Abomonation for Point +impl Abomonation for Point where N: Scalar, - D: DimName, - VectorN: Abomonation, - DefaultAllocator: Allocator, + VectorN>: Abomonation, + // DefaultAllocator: Allocator, { unsafe fn entomb(&self, writer: &mut W) -> IOResult<()> { self.coords.entomb(writer) @@ -134,9 +128,9 @@ where } } -impl Point -where - DefaultAllocator: Allocator, +impl Point +// where +// DefaultAllocator: Allocator, { /// Returns a point containing the result of `f` applied to each of its entries. /// @@ -152,8 +146,8 @@ where /// ``` #[inline] pub fn map N2>(&self, f: F) -> Point - where - DefaultAllocator: Allocator, +// where + // DefaultAllocator: Allocator, { self.coords.map(f).into() } @@ -193,20 +187,21 @@ where /// assert_eq!(p.to_homogeneous(), Vector4::new(10.0, 20.0, 30.0, 1.0)); /// ``` #[inline] - pub fn to_homogeneous(&self) -> VectorN> + pub fn to_homogeneous(&self) -> VectorN, U1>> where N: One, - D: DimNameAdd, - DefaultAllocator: Allocator>, + Const: DimNameAdd, + DefaultAllocator: Allocator, U1>>, { let mut res = unsafe { crate::unimplemented_or_uninitialized_generic!( - as DimName>::name(), + , U1> as DimName>::name(), Const::<1> ) }; - res.fixed_slice_mut::(0, 0).copy_from(&self.coords); - res[(D::dim(), 0)] = N::one(); + res.fixed_slice_mut::, U1>(0, 0) + .copy_from(&self.coords); + res[(D, 0)] = N::one(); res } @@ -214,7 +209,7 @@ where /// Creates a new point with the given coordinates. #[deprecated(note = "Use Point::from(vector) instead.")] #[inline] - pub fn from_coordinates(coords: VectorN) -> Self { + pub fn from_coordinates(coords: VectorN>) -> Self { Self { coords } } @@ -269,7 +264,10 @@ where /// assert_eq!(it.next(), Some(3.0)); /// assert_eq!(it.next(), None); #[inline] - pub fn iter(&self) -> MatrixIter>::Buffer> { + pub fn iter( + &self, + ) -> MatrixIter, Const<1>, >>::Buffer> + { self.coords.iter() } @@ -294,7 +292,8 @@ where #[inline] pub fn iter_mut( &mut self, - ) -> MatrixIterMut>::Buffer> { + ) -> MatrixIterMut, Const<1>, >>::Buffer> + { self.coords.iter_mut() } @@ -311,9 +310,9 @@ where } } -impl AbsDiffEq for Point +impl AbsDiffEq for Point where - DefaultAllocator: Allocator, + // DefaultAllocator: Allocator, N::Epsilon: Copy, { type Epsilon = N::Epsilon; @@ -329,9 +328,9 @@ where } } -impl RelativeEq for Point +impl RelativeEq for Point where - DefaultAllocator: Allocator, + // DefaultAllocator: Allocator, N::Epsilon: Copy, { #[inline] @@ -351,9 +350,9 @@ where } } -impl UlpsEq for Point +impl UlpsEq for Point where - DefaultAllocator: Allocator, + // DefaultAllocator: Allocator, N::Epsilon: Copy, { #[inline] @@ -367,11 +366,14 @@ where } } -impl Eq for Point where DefaultAllocator: Allocator {} +impl Eq for Point +// where DefaultAllocator: Allocator +{ +} -impl PartialEq for Point -where - DefaultAllocator: Allocator, +impl PartialEq for Point +// where +// DefaultAllocator: Allocator, { #[inline] fn eq(&self, right: &Self) -> bool { @@ -379,9 +381,9 @@ where } } -impl PartialOrd for Point -where - DefaultAllocator: Allocator, +impl PartialOrd for Point +// where +// DefaultAllocator: Allocator, { #[inline] fn partial_cmp(&self, other: &Self) -> Option { @@ -412,9 +414,9 @@ where /* * inf/sup */ -impl Point -where - DefaultAllocator: Allocator, +impl Point +// where +// DefaultAllocator: Allocator, { /// Computes the infimum (aka. componentwise min) of two points. #[inline] @@ -441,9 +443,9 @@ where * Display * */ -impl fmt::Display for Point -where - DefaultAllocator: Allocator, +impl fmt::Display for Point +// where +// DefaultAllocator: Allocator, { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{{")?; diff --git a/src/geometry/point_alias.rs b/src/geometry/point_alias.rs index 05874ae4..402c1201 100644 --- a/src/geometry/point_alias.rs +++ b/src/geometry/point_alias.rs @@ -1,28 +1,26 @@ -use crate::base::dimension::{U1, U2, U3, U4, U5, U6}; - use crate::geometry::Point; /// A statically sized 1-dimensional column point. /// /// **Because this is an alias, not all its methods are listed here. See the [`Point`](crate::Point) type too.** -pub type Point1 = Point; +pub type Point1 = Point; /// A statically sized 2-dimensional column point. /// /// **Because this is an alias, not all its methods are listed here. See the [`Point`](crate::Point) type too.** -pub type Point2 = Point; +pub type Point2 = Point; /// A statically sized 3-dimensional column point. /// /// **Because this is an alias, not all its methods are listed here. See the [`Point`](crate::Point) type too.** -pub type Point3 = Point; +pub type Point3 = Point; /// A statically sized 4-dimensional column point. /// /// **Because this is an alias, not all its methods are listed here. See the [`Point`](crate::Point) type too.** -pub type Point4 = Point; +pub type Point4 = Point; /// A statically sized 5-dimensional column point. /// /// **Because this is an alias, not all its methods are listed here. See the [`Point`](crate::Point) type too.** -pub type Point5 = Point; +pub type Point5 = Point; /// A statically sized 6-dimensional column point. /// /// **Because this is an alias, not all its methods are listed here. See the [`Point`](crate::Point) type too.** -pub type Point6 = Point; +pub type Point6 = Point; diff --git a/src/geometry/point_construction.rs b/src/geometry/point_construction.rs index ad3cb66d..4ddaf1f9 100644 --- a/src/geometry/point_construction.rs +++ b/src/geometry/point_construction.rs @@ -9,7 +9,7 @@ use rand::{ }; use crate::base::allocator::Allocator; -use crate::base::dimension::{DimName, DimNameAdd, DimNameSum, U1}; +use crate::base::dimension::{DimNameAdd, DimNameSum, U1}; use crate::base::{DefaultAllocator, Scalar, VectorN}; use crate::{ Const, Point1, Point2, Point3, Point4, Point5, Point6, Vector1, Vector2, Vector3, Vector4, @@ -20,16 +20,15 @@ use simba::scalar::{ClosedDiv, SupersetOf}; use crate::geometry::Point; /// # Other construction methods -impl Point -where - DefaultAllocator: Allocator, +impl Point +// where +// DefaultAllocator: Allocator, { /// Creates a new point with uninitialized coordinates. #[inline] pub unsafe fn new_uninitialized() -> Self { Self::from(crate::unimplemented_or_uninitialized_generic!( - D::name(), - Const::<1> + Const::, Const::<1> )) } @@ -106,14 +105,14 @@ where /// assert_eq!(pt, Some(Point2::new(1.0, 2.0))); /// ``` #[inline] - pub fn from_homogeneous(v: VectorN>) -> Option + pub fn from_homogeneous(v: VectorN, U1>>) -> Option where N: Scalar + Zero + One + ClosedDiv, - D: DimNameAdd, - DefaultAllocator: Allocator>, + Const: DimNameAdd, + DefaultAllocator: Allocator, U1>>, { - if !v[D::dim()].is_zero() { - let coords = v.fixed_slice::(0, 0) / v[D::dim()].inlined_clone(); + if !v[D].is_zero() { + let coords = v.fixed_slice::, U1>(0, 0) / v[D].inlined_clone(); Some(Self::from(coords)) } else { None @@ -132,7 +131,7 @@ where pub fn cast(self) -> Point where Point: SupersetOf, - DefaultAllocator: Allocator, + // DefaultAllocator: Allocator, { crate::convert(self) } @@ -143,9 +142,9 @@ where * Traits that build points. * */ -impl Bounded for Point -where - DefaultAllocator: Allocator, +impl Bounded for Point +// where +// DefaultAllocator: Allocator, { #[inline] fn max_value() -> Self { @@ -159,9 +158,9 @@ where } #[cfg(feature = "rand-no-std")] -impl Distribution> for Standard +impl Distribution> for Standard where - DefaultAllocator: Allocator, + // DefaultAllocator: Allocator, Standard: Distribution, { /// Generate a `Point` where each coordinate is an independent variate from `[0, 1)`. @@ -172,10 +171,10 @@ where } #[cfg(feature = "arbitrary")] -impl Arbitrary for Point +impl Arbitrary for Point where - DefaultAllocator: Allocator, - >::Buffer: Send, + // DefaultAllocator: Allocator, + >>::Buffer: Send, { #[inline] fn arbitrary(g: &mut Gen) -> Self { diff --git a/src/geometry/point_conversion.rs b/src/geometry/point_conversion.rs index 6f3d865b..e301f948 100644 --- a/src/geometry/point_conversion.rs +++ b/src/geometry/point_conversion.rs @@ -3,8 +3,8 @@ use simba::scalar::{ClosedDiv, SubsetOf, SupersetOf}; use simba::simd::PrimitiveSimdValue; use crate::base::allocator::Allocator; -use crate::base::dimension::{DimName, DimNameAdd, DimNameSum, U1}; -use crate::base::{DefaultAllocator, Matrix, Scalar, VectorN}; +use crate::base::dimension::{DimNameAdd, DimNameSum, U1}; +use crate::base::{Const, DefaultAllocator, Matrix, Scalar, VectorN}; use crate::geometry::Point; @@ -16,12 +16,11 @@ use crate::geometry::Point; * Point -> Vector (homogeneous) */ -impl SubsetOf> for Point +impl SubsetOf> for Point where - D: DimName, N1: Scalar, N2: Scalar + SupersetOf, - DefaultAllocator: Allocator + Allocator, + // DefaultAllocator: Allocator + Allocator, { #[inline] fn to_superset(&self) -> Point { @@ -41,40 +40,41 @@ where } } -impl SubsetOf>> for Point +impl SubsetOf, U1>>> for Point where - D: DimNameAdd, + Const: DimNameAdd, N1: Scalar, N2: Scalar + Zero + One + ClosedDiv + SupersetOf, - DefaultAllocator: Allocator - + Allocator> - + Allocator> - + Allocator, + DefaultAllocator: + Allocator, U1>> + Allocator, U1>>, + // + Allocator + // + Allocator, { #[inline] - fn to_superset(&self) -> VectorN> { + fn to_superset(&self) -> VectorN, U1>> { let p: Point = self.to_superset(); p.to_homogeneous() } #[inline] - fn is_in_subset(v: &VectorN>) -> bool { - crate::is_convertible::<_, VectorN>>(v) && !v[D::dim()].is_zero() + fn is_in_subset(v: &VectorN, U1>>) -> bool { + crate::is_convertible::<_, VectorN>>(v) && !v[D].is_zero() } #[inline] - fn from_superset_unchecked(v: &VectorN>) -> Self { - let coords = v.fixed_slice::(0, 0) / v[D::dim()].inlined_clone(); + fn from_superset_unchecked(v: &VectorN, U1>>) -> Self { + let coords = v.fixed_slice::(0, 0) / v[D].inlined_clone(); Self { coords: crate::convert_unchecked(coords), } } } -impl From> for VectorN> +impl From> + for VectorN, U1>> where - D: DimNameAdd, - DefaultAllocator: Allocator + Allocator>, + Const: DimNameAdd, + DefaultAllocator: Allocator, U1>>, { #[inline] fn from(t: Point) -> Self { @@ -82,23 +82,23 @@ where } } -impl From> for Point -where - DefaultAllocator: Allocator, +impl From>> for Point +// where +// DefaultAllocator: Allocator, { #[inline] - fn from(coords: VectorN) -> Self { + fn from(coords: VectorN>) -> Self { Point { coords } } } -impl From<[Point; 2]> +impl From<[Point; 2]> for Point where N: From<[::Element; 2]>, N::Element: Scalar + Copy, - DefaultAllocator: Allocator + Allocator, - >::Buffer: Copy, + // DefaultAllocator: Allocator + Allocator, + >>::Buffer: Copy, { #[inline] fn from(arr: [Point; 2]) -> Self { @@ -106,13 +106,13 @@ where } } -impl From<[Point; 4]> +impl From<[Point; 4]> for Point where N: From<[::Element; 4]>, N::Element: Scalar + Copy, - DefaultAllocator: Allocator + Allocator, - >::Buffer: Copy, + // DefaultAllocator: Allocator + Allocator, + >>::Buffer: Copy, { #[inline] fn from(arr: [Point; 4]) -> Self { @@ -125,13 +125,13 @@ where } } -impl From<[Point; 8]> +impl From<[Point; 8]> for Point where N: From<[::Element; 8]>, N::Element: Scalar + Copy, - DefaultAllocator: Allocator + Allocator, - >::Buffer: Copy, + // DefaultAllocator: Allocator + Allocator, + >>::Buffer: Copy, { #[inline] fn from(arr: [Point; 8]) -> Self { @@ -148,13 +148,13 @@ where } } -impl From<[Point; 16]> +impl From<[Point; 16]> for Point where N: From<[::Element; 16]>, N::Element: Scalar + Copy, - DefaultAllocator: Allocator + Allocator, - >::Buffer: Copy, + // DefaultAllocator: Allocator + Allocator, + >>::Buffer: Copy, { #[inline] fn from(arr: [Point; 16]) -> Self { diff --git a/src/geometry/point_coordinates.rs b/src/geometry/point_coordinates.rs index 268c9b0d..3d54d899 100644 --- a/src/geometry/point_coordinates.rs +++ b/src/geometry/point_coordinates.rs @@ -1,9 +1,7 @@ use std::ops::{Deref, DerefMut}; -use crate::base::allocator::Allocator; use crate::base::coordinates::{X, XY, XYZ, XYZW, XYZWA, XYZWAB}; -use crate::base::dimension::{U1, U2, U3, U4, U5, U6}; -use crate::base::{DefaultAllocator, Scalar}; +use crate::base::Scalar; use crate::geometry::Point; @@ -14,9 +12,10 @@ use crate::geometry::Point; */ macro_rules! deref_impl( - ($D: ty, $Target: ident $(, $comps: ident)*) => { + ($D: expr, $Target: ident $(, $comps: ident)*) => { impl Deref for Point - where DefaultAllocator: Allocator { + // where DefaultAllocator: Allocator + { type Target = $Target; #[inline] @@ -26,7 +25,8 @@ macro_rules! deref_impl( } impl DerefMut for Point - where DefaultAllocator: Allocator { + // where DefaultAllocator: Allocator + { #[inline] fn deref_mut(&mut self) -> &mut Self::Target { &mut *self.coords @@ -35,9 +35,9 @@ macro_rules! deref_impl( } ); -deref_impl!(U1, X, x); -deref_impl!(U2, XY, x, y); -deref_impl!(U3, XYZ, x, y, z); -deref_impl!(U4, XYZW, x, y, z, w); -deref_impl!(U5, XYZWA, x, y, z, w, a); -deref_impl!(U6, XYZWAB, x, y, z, w, a, b); +deref_impl!(1, X, x); +deref_impl!(2, XY, x, y); +deref_impl!(3, XYZ, x, y, z); +deref_impl!(4, XYZW, x, y, z, w); +deref_impl!(5, XYZWA, x, y, z, w, a); +deref_impl!(6, XYZWAB, x, y, z, w, a, b); diff --git a/src/geometry/point_ops.rs b/src/geometry/point_ops.rs index 029286ff..48af3a8d 100644 --- a/src/geometry/point_ops.rs +++ b/src/geometry/point_ops.rs @@ -11,7 +11,7 @@ use crate::base::constraint::{ }; use crate::base::dimension::{Dim, DimName, U1}; use crate::base::storage::Storage; -use crate::base::{DefaultAllocator, Matrix, Scalar, Vector, VectorSum}; +use crate::base::{Const, DefaultAllocator, Matrix, Scalar, Vector, VectorSum}; use crate::geometry::Point; @@ -20,9 +20,9 @@ use crate::geometry::Point; * Indexing. * */ -impl Index for Point -where - DefaultAllocator: Allocator, +impl Index for Point +// where +// DefaultAllocator: Allocator, { type Output = N; @@ -32,9 +32,9 @@ where } } -impl IndexMut for Point -where - DefaultAllocator: Allocator, +impl IndexMut for Point +// where +// DefaultAllocator: Allocator, { #[inline] fn index_mut(&mut self, i: usize) -> &mut Self::Output { @@ -47,9 +47,9 @@ where * Neg. * */ -impl Neg for Point -where - DefaultAllocator: Allocator, +impl Neg for Point +// where +// DefaultAllocator: Allocator, { type Output = Self; @@ -59,9 +59,9 @@ where } } -impl<'a, N: Scalar + ClosedNeg, D: DimName> Neg for &'a Point -where - DefaultAllocator: Allocator, +impl<'a, N: Scalar + ClosedNeg, const D: usize> Neg for &'a Point +// where +// DefaultAllocator: Allocator, { type Output = Point; @@ -79,22 +79,22 @@ where // Point - Point add_sub_impl!(Sub, sub, ClosedSub; - (D, U1), (D, U1) for D: DimName; + (D, U1), (D, U1); self: &'a Point, right: &'b Point, Output = VectorSum; &self.coords - &right.coords; 'a, 'b); add_sub_impl!(Sub, sub, ClosedSub; - (D, U1), (D, U1) for D: DimName; + (D, U1), (D, U1); self: &'a Point, right: Point, Output = VectorSum; &self.coords - right.coords; 'a); add_sub_impl!(Sub, sub, ClosedSub; - (D, U1), (D, U1) for D: DimName; + (D, U1), (D, U1); self: Point, right: &'b Point, Output = VectorSum; self.coords - &right.coords; 'b); add_sub_impl!(Sub, sub, ClosedSub; - (D, U1), (D, U1) for D: DimName; + (D, U1), (D, U1); self: Point, right: Point, Output = VectorSum; self.coords - right.coords; ); @@ -143,11 +143,11 @@ add_sub_impl!(Add, add, ClosedAdd; // XXX: replace by the shared macro: add_sub_assign_impl macro_rules! op_assign_impl( ($($TraitAssign: ident, $method_assign: ident, $bound: ident);* $(;)*) => {$( - impl<'b, N, D1: DimName, D2: Dim, SB> $TraitAssign<&'b Vector> for Point + impl<'b, N, D2: Dim, SB, const D1: usize> $TraitAssign<&'b Vector> for Point where N: Scalar + $bound, SB: Storage, - DefaultAllocator: Allocator, - ShapeConstraint: SameNumberOfRows { + // DefaultAllocator: Allocator, + ShapeConstraint: SameNumberOfRows, D2> { #[inline] fn $method_assign(&mut self, right: &'b Vector) { @@ -155,10 +155,10 @@ macro_rules! op_assign_impl( } } - impl $TraitAssign> for Point + impl $TraitAssign> for Point where N: Scalar + $bound, SB: Storage, - DefaultAllocator: Allocator, + // DefaultAllocator: Allocator, ShapeConstraint: SameNumberOfRows { #[inline] @@ -198,8 +198,9 @@ md_impl_all!( macro_rules! componentwise_scalarop_impl( ($Trait: ident, $method: ident, $bound: ident; $TraitAssign: ident, $method_assign: ident) => { - impl $Trait for Point - where DefaultAllocator: Allocator { + impl $Trait for Point + // where DefaultAllocator: Allocator + { type Output = Point; #[inline] @@ -208,8 +209,9 @@ macro_rules! componentwise_scalarop_impl( } } - impl<'a, N: Scalar + $bound, D: DimName> $Trait for &'a Point - where DefaultAllocator: Allocator { + impl<'a, N: Scalar + $bound, const D: usize> $Trait for &'a Point + // where DefaultAllocator: Allocator + { type Output = Point; #[inline] @@ -218,8 +220,9 @@ macro_rules! componentwise_scalarop_impl( } } - impl $TraitAssign for Point - where DefaultAllocator: Allocator { + impl $TraitAssign for Point + /* where DefaultAllocator: Allocator */ + { #[inline] fn $method_assign(&mut self, right: N) { self.coords.$method_assign(right) @@ -233,8 +236,9 @@ componentwise_scalarop_impl!(Div, div, ClosedDiv; DivAssign, div_assign); macro_rules! left_scalar_mul_impl( ($($T: ty),* $(,)*) => {$( - impl Mul> for $T - where DefaultAllocator: Allocator<$T, D> { + impl Mul> for $T + // where DefaultAllocator: Allocator<$T, D> + { type Output = Point<$T, D>; #[inline] @@ -243,8 +247,9 @@ macro_rules! left_scalar_mul_impl( } } - impl<'b, D: DimName> Mul<&'b Point<$T, D>> for $T - where DefaultAllocator: Allocator<$T, D> { + impl<'b, const D: usize> Mul<&'b Point<$T, D>> for $T + // where DefaultAllocator: Allocator<$T, D> + { type Output = Point<$T, D>; #[inline] diff --git a/src/geometry/point_simba.rs b/src/geometry/point_simba.rs index a6c8465e..c597d142 100644 --- a/src/geometry/point_simba.rs +++ b/src/geometry/point_simba.rs @@ -1,15 +1,13 @@ use simba::simd::SimdValue; -use crate::base::allocator::Allocator; -use crate::base::dimension::DimName; -use crate::base::{DefaultAllocator, Scalar, VectorN}; +use crate::base::{Scalar, VectorN}; use crate::geometry::Point; -impl SimdValue for Point +impl SimdValue for Point where N::Element: Scalar, - DefaultAllocator: Allocator + Allocator, + // DefaultAllocator: Allocator + Allocator, { type Element = Point; type SimdBool = N::SimdBool; diff --git a/src/geometry/quaternion.rs b/src/geometry/quaternion.rs index 172f2e66..48a2d2ca 100755 --- a/src/geometry/quaternion.rs +++ b/src/geometry/quaternion.rs @@ -1367,7 +1367,7 @@ where /// assert_relative_eq!(*rot.matrix(), expected, epsilon = 1.0e-6); /// ``` #[inline] - pub fn to_rotation_matrix(&self) -> Rotation { + pub fn to_rotation_matrix(&self) -> Rotation { let i = self.as_ref()[0]; let j = self.as_ref()[1]; let k = self.as_ref()[2]; diff --git a/src/geometry/quaternion_conversion.rs b/src/geometry/quaternion_conversion.rs index c8b5c6ed..c1b18221 100644 --- a/src/geometry/quaternion_conversion.rs +++ b/src/geometry/quaternion_conversion.rs @@ -3,7 +3,6 @@ use num::Zero; use simba::scalar::{RealField, SubsetOf, SupersetOf}; use simba::simd::{PrimitiveSimdValue, SimdRealField, SimdValue}; -use crate::base::dimension::U3; use crate::base::{Matrix3, Matrix4, Scalar, Vector4}; use crate::geometry::{ AbstractRotation, Isometry, Quaternion, Rotation, Rotation3, Similarity, SuperTCategoryOf, @@ -16,11 +15,11 @@ use crate::geometry::{ * * Quaternion -> Quaternion * UnitQuaternion -> UnitQuaternion - * UnitQuaternion -> Rotation - * UnitQuaternion -> Isometry + * UnitQuaternion -> Rotation<3> + * UnitQuaternion -> Isometry<3> * UnitQuaternion -> UnitDualQuaternion - * UnitQuaternion -> Similarity - * UnitQuaternion -> Transform + * UnitQuaternion -> Similarity<3> + * UnitQuaternion -> Transform<3> * UnitQuaternion -> Matrix (homogeneous) * * NOTE: @@ -71,7 +70,7 @@ where } } -impl SubsetOf> for UnitQuaternion +impl SubsetOf> for UnitQuaternion where N1: RealField, N2: RealField + SupersetOf, @@ -94,24 +93,24 @@ where } } -impl SubsetOf> for UnitQuaternion +impl SubsetOf> for UnitQuaternion where N1: RealField, N2: RealField + SupersetOf, - R: AbstractRotation + SupersetOf, + R: AbstractRotation + SupersetOf, { #[inline] - fn to_superset(&self) -> Isometry { + fn to_superset(&self) -> Isometry { Isometry::from_parts(Translation::identity(), crate::convert_ref(self)) } #[inline] - fn is_in_subset(iso: &Isometry) -> bool { + fn is_in_subset(iso: &Isometry) -> bool { iso.translation.vector.is_zero() } #[inline] - fn from_superset_unchecked(iso: &Isometry) -> Self { + fn from_superset_unchecked(iso: &Isometry) -> Self { crate::convert_ref_unchecked(&iso.rotation) } } @@ -138,46 +137,46 @@ where } } -impl SubsetOf> for UnitQuaternion +impl SubsetOf> for UnitQuaternion where N1: RealField, N2: RealField + SupersetOf, - R: AbstractRotation + SupersetOf, + R: AbstractRotation + SupersetOf, { #[inline] - fn to_superset(&self) -> Similarity { + fn to_superset(&self) -> Similarity { Similarity::from_isometry(crate::convert_ref(self), N2::one()) } #[inline] - fn is_in_subset(sim: &Similarity) -> bool { + fn is_in_subset(sim: &Similarity) -> bool { sim.isometry.translation.vector.is_zero() && sim.scaling() == N2::one() } #[inline] - fn from_superset_unchecked(sim: &Similarity) -> Self { + fn from_superset_unchecked(sim: &Similarity) -> Self { crate::convert_ref_unchecked(&sim.isometry) } } -impl SubsetOf> for UnitQuaternion +impl SubsetOf> for UnitQuaternion where N1: RealField, N2: RealField + SupersetOf, C: SuperTCategoryOf, { #[inline] - fn to_superset(&self) -> Transform { + fn to_superset(&self) -> Transform { Transform::from_matrix_unchecked(self.to_homogeneous().to_superset()) } #[inline] - fn is_in_subset(t: &Transform) -> bool { + fn is_in_subset(t: &Transform) -> bool { >::is_in_subset(t.matrix()) } #[inline] - fn from_superset_unchecked(t: &Transform) -> Self { + fn from_superset_unchecked(t: &Transform) -> Self { Self::from_superset_unchecked(t.matrix()) } } diff --git a/src/geometry/reflection.rs b/src/geometry/reflection.rs index d5e950ec..7ed220ca 100644 --- a/src/geometry/reflection.rs +++ b/src/geometry/reflection.rs @@ -1,7 +1,6 @@ -use crate::base::allocator::Allocator; use crate::base::constraint::{AreMultipliable, DimEq, SameNumberOfRows, ShapeConstraint}; -use crate::base::{DefaultAllocator, Matrix, Scalar, Unit, Vector}; -use crate::dimension::{Dim, DimName, U1}; +use crate::base::{Const, Matrix, Scalar, Unit, Vector}; +use crate::dimension::{Dim, U1}; use crate::storage::{Storage, StorageMut}; use simba::scalar::ComplexField; @@ -13,6 +12,15 @@ pub struct Reflection> { bias: N, } +impl>, const D: usize> Reflection, S> { + /// Creates a new reflection wrt. the plane orthogonal to the given axis and that contains the + /// point `pt`. + pub fn new_containing_point(axis: Unit, S>>, pt: &Point) -> Self { + let bias = axis.dotc(&pt.coords); + Self::new(axis, bias) + } +} + impl> Reflection { /// Creates a new reflection wrt the plane orthogonal to the given axis and bias. /// @@ -25,17 +33,6 @@ impl> Reflection { } } - /// Creates a new reflection wrt. the plane orthogonal to the given axis and that contains the - /// point `pt`. - pub fn new_containing_point(axis: Unit>, pt: &Point) -> Self - where - D: DimName, - DefaultAllocator: Allocator, - { - let bias = axis.dotc(&pt.coords); - Self::new(axis, bias) - } - /// The reflexion axis. pub fn axis(&self) -> &Vector { &self.axis diff --git a/src/geometry/rotation.rs b/src/geometry/rotation.rs index e4f69fe6..498886d3 100755 --- a/src/geometry/rotation.rs +++ b/src/geometry/rotation.rs @@ -18,8 +18,8 @@ use simba::scalar::RealField; use simba::simd::SimdRealField; use crate::base::allocator::Allocator; -use crate::base::dimension::{DimName, DimNameAdd, DimNameSum, U1}; -use crate::base::{DefaultAllocator, MatrixN, Scalar, Unit, VectorN}; +use crate::base::dimension::{DimNameAdd, DimNameSum, U1}; +use crate::base::{CMatrixN, CVectorN, Const, DefaultAllocator, MatrixN, Scalar, Unit}; use crate::geometry::Point; /// A rotation matrix. @@ -55,34 +55,33 @@ use crate::geometry::Point; /// #[repr(C)] #[derive(Debug)] -pub struct Rotation -where - DefaultAllocator: Allocator, +pub struct Rotation +// where +// DefaultAllocator: Allocator, { - matrix: MatrixN, + matrix: CMatrixN, } -impl hash::Hash for Rotation +impl hash::Hash for Rotation where - DefaultAllocator: Allocator, - >::Buffer: hash::Hash, + // DefaultAllocator: Allocator, + , Const>>::Buffer: hash::Hash, { fn hash(&self, state: &mut H) { self.matrix.hash(state) } } -impl Copy for Rotation -where - DefaultAllocator: Allocator, - >::Buffer: Copy, +impl Copy for Rotation where + // DefaultAllocator: Allocator, + , Const>>::Buffer: Copy { } -impl Clone for Rotation +impl Clone for Rotation where - DefaultAllocator: Allocator, - >::Buffer: Clone, + // DefaultAllocator: Allocator, + , Const>>::Buffer: Clone, { #[inline] fn clone(&self) -> Self { @@ -91,12 +90,11 @@ where } #[cfg(feature = "abomonation-serialize")] -impl Abomonation for Rotation +impl Abomonation for Rotation where N: Scalar, - D: DimName, - MatrixN: Abomonation, - DefaultAllocator: Allocator, + CMatrixN>: Abomonation, + // DefaultAllocator: Allocator, { unsafe fn entomb(&self, writer: &mut W) -> IOResult<()> { self.matrix.entomb(writer) @@ -112,9 +110,9 @@ where } #[cfg(feature = "serde-serialize")] -impl Serialize for Rotation +impl Serialize for Rotation where - DefaultAllocator: Allocator, + // DefaultAllocator: Allocator, Owned: Serialize, { fn serialize(&self, serializer: S) -> Result @@ -126,24 +124,24 @@ where } #[cfg(feature = "serde-serialize")] -impl<'a, N: Scalar, D: DimName> Deserialize<'a> for Rotation +impl<'a, N: Scalar, const D: usize> Deserialize<'a> for Rotation where - DefaultAllocator: Allocator, + // DefaultAllocator: Allocator, Owned: Deserialize<'a>, { fn deserialize(deserializer: Des) -> Result where Des: Deserializer<'a>, { - let matrix = MatrixN::::deserialize(deserializer)?; + let matrix = CMatrixN::::deserialize(deserializer)?; Ok(Self::from_matrix_unchecked(matrix)) } } -impl Rotation -where - DefaultAllocator: Allocator, +impl Rotation +// where +// DefaultAllocator: Allocator, { /// Creates a new rotation from the given square matrix. /// @@ -168,7 +166,7 @@ where /// assert_eq!(*rot.matrix(), mat); /// ``` #[inline] - pub fn from_matrix_unchecked(matrix: MatrixN) -> Self { + pub fn from_matrix_unchecked(matrix: CMatrixN) -> Self { assert!( matrix.is_square(), "Unable to create a rotation from a non-square matrix." @@ -179,9 +177,9 @@ where } /// # Conversion to a matrix -impl Rotation -where - DefaultAllocator: Allocator, +impl Rotation +// where +// DefaultAllocator: Allocator, { /// A reference to the underlying matrix representation of this rotation. /// @@ -202,14 +200,14 @@ where /// assert_eq!(*rot.matrix(), expected); /// ``` #[inline] - pub fn matrix(&self) -> &MatrixN { + pub fn matrix(&self) -> &CMatrixN { &self.matrix } /// A mutable reference to the underlying matrix representation of this rotation. #[inline] #[deprecated(note = "Use `.matrix_mut_unchecked()` instead.")] - pub unsafe fn matrix_mut(&mut self) -> &mut MatrixN { + pub unsafe fn matrix_mut(&mut self) -> &mut CMatrixN { &mut self.matrix } @@ -219,7 +217,7 @@ where /// non-square, non-inversible, or non-orthonormal. If one of those properties is broken, /// subsequent method calls may be UB. #[inline] - pub fn matrix_mut_unchecked(&mut self) -> &mut MatrixN { + pub fn matrix_mut_unchecked(&mut self) -> &mut CMatrixN { &mut self.matrix } @@ -244,7 +242,7 @@ where /// assert_eq!(mat, expected); /// ``` #[inline] - pub fn into_inner(self) -> MatrixN { + pub fn into_inner(self) -> CMatrixN { self.matrix } @@ -252,7 +250,7 @@ where /// Deprecated: Use [Rotation::into_inner] instead. #[deprecated(note = "use `.into_inner()` instead")] #[inline] - pub fn unwrap(self) -> MatrixN { + pub fn unwrap(self) -> CMatrixN { self.matrix } @@ -279,13 +277,13 @@ where /// assert_eq!(rot.to_homogeneous(), expected); /// ``` #[inline] - pub fn to_homogeneous(&self) -> MatrixN> + pub fn to_homogeneous(&self) -> MatrixN, U1>> where N: Zero + One, - D: DimNameAdd, - DefaultAllocator: Allocator, DimNameSum>, + Const: DimNameAdd, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, { - // We could use `MatrixN::to_homogeneous()` here, but that would imply + // We could use `CMatrixN::to_homogeneous()` here, but that would imply // adding the additional traits `DimAdd` and `IsNotStaticOne`. Maybe // these things will get nicer once specialization lands in Rust. let mut res = MatrixN::>::identity(); @@ -296,9 +294,9 @@ where } /// # Transposition and inversion -impl Rotation -where - DefaultAllocator: Allocator, +impl Rotation +// where +// DefaultAllocator: Allocator, { /// Transposes `self`. /// @@ -404,10 +402,10 @@ where } /// # Transformation of a vector or a point -impl Rotation +impl Rotation where N::Element: SimdRealField, - DefaultAllocator: Allocator + Allocator, + // DefaultAllocator: Allocator + Allocator, { /// Rotate the given point. /// @@ -443,7 +441,7 @@ where /// assert_relative_eq!(transformed_vector, Vector3::new(3.0, 2.0, -1.0), epsilon = 1.0e-6); /// ``` #[inline] - pub fn transform_vector(&self, v: &VectorN) -> VectorN { + pub fn transform_vector(&self, v: &CVectorN) -> CVectorN { self * v } @@ -481,7 +479,7 @@ where /// assert_relative_eq!(transformed_vector, Vector3::new(-3.0, 2.0, 1.0), epsilon = 1.0e-6); /// ``` #[inline] - pub fn inverse_transform_vector(&self, v: &VectorN) -> VectorN { + pub fn inverse_transform_vector(&self, v: &CVectorN) -> CVectorN { self.matrix().tr_mul(v) } @@ -500,16 +498,19 @@ where /// assert_relative_eq!(transformed_vector, -Vector3::y_axis(), epsilon = 1.0e-6); /// ``` #[inline] - pub fn inverse_transform_unit_vector(&self, v: &Unit>) -> Unit> { + pub fn inverse_transform_unit_vector(&self, v: &Unit>) -> Unit> { Unit::new_unchecked(self.inverse_transform_vector(&**v)) } } -impl Eq for Rotation where DefaultAllocator: Allocator {} +impl Eq for Rotation +// where DefaultAllocator: Allocator +{ +} -impl PartialEq for Rotation -where - DefaultAllocator: Allocator, +impl PartialEq for Rotation +// where +// DefaultAllocator: Allocator, { #[inline] fn eq(&self, right: &Self) -> bool { @@ -517,10 +518,10 @@ where } } -impl AbsDiffEq for Rotation +impl AbsDiffEq for Rotation where N: Scalar + AbsDiffEq, - DefaultAllocator: Allocator, + // DefaultAllocator: Allocator, N::Epsilon: Copy, { type Epsilon = N::Epsilon; @@ -536,10 +537,10 @@ where } } -impl RelativeEq for Rotation +impl RelativeEq for Rotation where N: Scalar + RelativeEq, - DefaultAllocator: Allocator, + // DefaultAllocator: Allocator, N::Epsilon: Copy, { #[inline] @@ -559,10 +560,10 @@ where } } -impl UlpsEq for Rotation +impl UlpsEq for Rotation where N: Scalar + UlpsEq, - DefaultAllocator: Allocator, + // DefaultAllocator: Allocator, N::Epsilon: Copy, { #[inline] @@ -581,10 +582,10 @@ where * Display * */ -impl fmt::Display for Rotation +impl fmt::Display for Rotation where N: RealField + fmt::Display, - DefaultAllocator: Allocator + Allocator, + // DefaultAllocator: Allocator + Allocator, { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let precision = f.precision().unwrap_or(3); diff --git a/src/geometry/rotation_alias.rs b/src/geometry/rotation_alias.rs index f9e0230b..09d86152 100644 --- a/src/geometry/rotation_alias.rs +++ b/src/geometry/rotation_alias.rs @@ -1,13 +1,11 @@ -use crate::base::dimension::{U2, U3}; - use crate::geometry::Rotation; /// A 2-dimensional rotation matrix. /// /// **Because this is an alias, not all its methods are listed here. See the [`Rotation`](crate::Rotation) type too.** -pub type Rotation2 = Rotation; +pub type Rotation2 = Rotation; /// A 3-dimensional rotation matrix. /// /// **Because this is an alias, not all its methods are listed here. See the [`Rotation`](crate::Rotation) type too.** -pub type Rotation3 = Rotation; +pub type Rotation3 = Rotation; diff --git a/src/geometry/rotation_construction.rs b/src/geometry/rotation_construction.rs index f198fc92..a144a537 100644 --- a/src/geometry/rotation_construction.rs +++ b/src/geometry/rotation_construction.rs @@ -2,17 +2,15 @@ use num::{One, Zero}; use simba::scalar::{ClosedAdd, ClosedMul, SupersetOf}; -use crate::base::allocator::Allocator; -use crate::base::dimension::DimName; -use crate::base::{DefaultAllocator, MatrixN, Scalar}; +use crate::base::{MatrixN, Scalar}; use crate::geometry::Rotation; /// # Identity -impl Rotation +impl Rotation where N: Scalar + Zero + One, - DefaultAllocator: Allocator, + // DefaultAllocator: Allocator, { /// Creates a new square identity rotation of the given `dimension`. /// @@ -31,9 +29,9 @@ where } } -impl Rotation -where - DefaultAllocator: Allocator, +impl Rotation +// where +// DefaultAllocator: Allocator, { /// Cast the components of `self` to another type. /// @@ -47,16 +45,16 @@ where pub fn cast(self) -> Rotation where Rotation: SupersetOf, - DefaultAllocator: Allocator, + // DefaultAllocator: Allocator, { crate::convert(self) } } -impl One for Rotation +impl One for Rotation where N: Scalar + Zero + One + ClosedAdd + ClosedMul, - DefaultAllocator: Allocator, + // DefaultAllocator: Allocator, { #[inline] fn one() -> Self { diff --git a/src/geometry/rotation_conversion.rs b/src/geometry/rotation_conversion.rs index 21f5a936..14cb296b 100644 --- a/src/geometry/rotation_conversion.rs +++ b/src/geometry/rotation_conversion.rs @@ -4,8 +4,8 @@ use simba::scalar::{RealField, SubsetOf, SupersetOf}; use simba::simd::{PrimitiveSimdValue, SimdValue}; use crate::base::allocator::Allocator; -use crate::base::dimension::{DimMin, DimName, DimNameAdd, DimNameSum, U1}; -use crate::base::{DefaultAllocator, Matrix2, Matrix3, Matrix4, MatrixN, Scalar}; +use crate::base::dimension::{DimMin, DimNameAdd, DimNameSum, U1}; +use crate::base::{Const, DefaultAllocator, Matrix2, Matrix3, Matrix4, MatrixN, Scalar}; use crate::geometry::{ AbstractRotation, Isometry, Rotation, Rotation2, Rotation3, Similarity, SuperTCategoryOf, @@ -27,11 +27,11 @@ use crate::geometry::{ */ -impl SubsetOf> for Rotation +impl SubsetOf> for Rotation where N1: RealField, N2: RealField + SupersetOf, - DefaultAllocator: Allocator + Allocator, + // DefaultAllocator: Allocator + Allocator, { #[inline] fn to_superset(&self) -> Rotation { @@ -120,113 +120,112 @@ where } } -impl SubsetOf> for Rotation +impl SubsetOf> for Rotation where N1: RealField, N2: RealField + SupersetOf, R: AbstractRotation + SupersetOf, - DefaultAllocator: Allocator + Allocator, + // DefaultAllocator: Allocator + Allocator, { #[inline] - fn to_superset(&self) -> Isometry { + fn to_superset(&self) -> Isometry { Isometry::from_parts(Translation::identity(), crate::convert_ref(self)) } #[inline] - fn is_in_subset(iso: &Isometry) -> bool { + fn is_in_subset(iso: &Isometry) -> bool { iso.translation.vector.is_zero() } #[inline] - fn from_superset_unchecked(iso: &Isometry) -> Self { + fn from_superset_unchecked(iso: &Isometry) -> Self { crate::convert_ref_unchecked(&iso.rotation) } } -impl SubsetOf> for Rotation +impl SubsetOf> for Rotation where N1: RealField, N2: RealField + SupersetOf, R: AbstractRotation + SupersetOf, - DefaultAllocator: Allocator + Allocator, + // DefaultAllocator: Allocator + Allocator, { #[inline] - fn to_superset(&self) -> Similarity { + fn to_superset(&self) -> Similarity { Similarity::from_parts(Translation::identity(), crate::convert_ref(self), N2::one()) } #[inline] - fn is_in_subset(sim: &Similarity) -> bool { + fn is_in_subset(sim: &Similarity) -> bool { sim.isometry.translation.vector.is_zero() && sim.scaling() == N2::one() } #[inline] - fn from_superset_unchecked(sim: &Similarity) -> Self { + fn from_superset_unchecked(sim: &Similarity) -> Self { crate::convert_ref_unchecked(&sim.isometry.rotation) } } -impl SubsetOf> for Rotation +impl SubsetOf> for Rotation where N1: RealField, N2: RealField + SupersetOf, C: SuperTCategoryOf, - D: DimNameAdd + DimMin, // needed by .is_special_orthogonal() - DefaultAllocator: Allocator - + Allocator - + Allocator, DimNameSum> - + Allocator, DimNameSum> - + Allocator<(usize, usize), D>, + Const: DimNameAdd + DimMin, Output = Const>, // needed by .is_special_orthogonal() + DefaultAllocator: Allocator, U1>, DimNameSum, U1>> + + Allocator, U1>, DimNameSum, U1>>, + // + Allocator<(usize, usize), D>, + // Allocator + // + Allocator { // needed by .is_special_orthogonal() #[inline] - fn to_superset(&self) -> Transform { + fn to_superset(&self) -> Transform { Transform::from_matrix_unchecked(self.to_homogeneous().to_superset()) } #[inline] - fn is_in_subset(t: &Transform) -> bool { + fn is_in_subset(t: &Transform) -> bool { >::is_in_subset(t.matrix()) } #[inline] - fn from_superset_unchecked(t: &Transform) -> Self { + fn from_superset_unchecked(t: &Transform) -> Self { Self::from_superset_unchecked(t.matrix()) } } -impl SubsetOf>> for Rotation +impl SubsetOf, U1>>> for Rotation where N1: RealField, N2: RealField + SupersetOf, - D: DimNameAdd + DimMin, // needed by .is_special_orthogonal() - DefaultAllocator: Allocator - + Allocator - + Allocator, DimNameSum> - + Allocator, DimNameSum> - + Allocator<(usize, usize), D>, + Const: DimNameAdd + DimMin, Output = Const>, // needed by .is_special_orthogonal() + DefaultAllocator: Allocator, U1>, DimNameSum, U1>> + + Allocator, U1>, DimNameSum, U1>>, // + Allocator<(usize, usize), D>, + // + Allocator + // + Allocator { // needed by .is_special_orthogonal() #[inline] - fn to_superset(&self) -> MatrixN> { + fn to_superset(&self) -> MatrixN, U1>> { self.to_homogeneous().to_superset() } #[inline] - fn is_in_subset(m: &MatrixN>) -> bool { + fn is_in_subset(m: &MatrixN, U1>>) -> bool { let rot = m.fixed_slice::(0, 0); - let bottom = m.fixed_slice::(D::dim(), 0); + let bottom = m.fixed_slice::(D, 0); // Scalar types agree. m.iter().all(|e| SupersetOf::::is_in_subset(e)) && // The block part is a rotation. rot.is_special_orthogonal(N2::default_epsilon() * crate::convert(100.0)) && // The bottom row is (0, 0, ..., 1) - bottom.iter().all(|e| e.is_zero()) && m[(D::dim(), D::dim())] == N2::one() + bottom.iter().all(|e| e.is_zero()) && m[(D, D)] == N2::one() } #[inline] - fn from_superset_unchecked(m: &MatrixN>) -> Self { + fn from_superset_unchecked(m: &MatrixN, U1>>) -> Self { let r = m.fixed_slice::(0, 0); Self::from_matrix_unchecked(crate::convert_unchecked(r.into_owned())) } @@ -260,12 +259,12 @@ impl From> for Matrix3 { } } -impl From<[Rotation; 2]> +impl From<[Rotation; 2]> for Rotation where N: From<[::Element; 2]>, N::Element: Scalar + Copy, - DefaultAllocator: Allocator + Allocator, + // DefaultAllocator: Allocator + Allocator, { #[inline] fn from(arr: [Rotation; 2]) -> Self { @@ -276,12 +275,12 @@ where } } -impl From<[Rotation; 4]> +impl From<[Rotation; 4]> for Rotation where N: From<[::Element; 4]>, N::Element: Scalar + Copy, - DefaultAllocator: Allocator + Allocator, + // DefaultAllocator: Allocator + Allocator, { #[inline] fn from(arr: [Rotation; 4]) -> Self { @@ -294,12 +293,12 @@ where } } -impl From<[Rotation; 8]> +impl From<[Rotation; 8]> for Rotation where N: From<[::Element; 8]>, N::Element: Scalar + Copy, - DefaultAllocator: Allocator + Allocator, + // DefaultAllocator: Allocator + Allocator, { #[inline] fn from(arr: [Rotation; 8]) -> Self { @@ -316,12 +315,12 @@ where } } -impl From<[Rotation; 16]> +impl From<[Rotation; 16]> for Rotation where N: From<[::Element; 16]>, N::Element: Scalar + Copy, - DefaultAllocator: Allocator + Allocator, + // DefaultAllocator: Allocator + Allocator, { #[inline] fn from(arr: [Rotation; 16]) -> Self { diff --git a/src/geometry/rotation_simba.rs b/src/geometry/rotation_simba.rs index cb064a81..319fcc3c 100755 --- a/src/geometry/rotation_simba.rs +++ b/src/geometry/rotation_simba.rs @@ -1,17 +1,14 @@ use simba::simd::SimdValue; -use crate::base::allocator::Allocator; -use crate::base::dimension::DimName; -use crate::base::{DefaultAllocator, MatrixN, Scalar}; +use crate::base::{MatrixN, Scalar}; use crate::geometry::Rotation; -impl SimdValue for Rotation +impl SimdValue for Rotation where N: Scalar + SimdValue, - D: DimName, N::Element: Scalar, - DefaultAllocator: Allocator + Allocator, + // DefaultAllocator: Allocator + Allocator, { type Element = Rotation; type SimdBool = N::SimdBool; diff --git a/src/geometry/similarity.rs b/src/geometry/similarity.rs index fab54759..81203fb9 100755 --- a/src/geometry/similarity.rs +++ b/src/geometry/similarity.rs @@ -16,9 +16,9 @@ use simba::scalar::{RealField, SubsetOf}; use simba::simd::SimdRealField; use crate::base::allocator::Allocator; -use crate::base::dimension::{DimName, DimNameAdd, DimNameSum, U1}; +use crate::base::dimension::{DimNameAdd, DimNameSum, U1}; use crate::base::storage::Owned; -use crate::base::{DefaultAllocator, MatrixN, Scalar, VectorN}; +use crate::base::{CVectorN, Const, DefaultAllocator, MatrixN, Scalar}; use crate::geometry::{AbstractRotation, Isometry, Point, Translation}; /// A similarity, i.e., an uniform scaling, followed by a rotation, followed by a translation. @@ -39,20 +39,20 @@ use crate::geometry::{AbstractRotation, Isometry, Point, Translation}; DefaultAllocator: Allocator, Owned: Deserialize<'de>")) )] -pub struct Similarity -where - DefaultAllocator: Allocator, +pub struct Similarity +// where +// DefaultAllocator: Allocator, { /// The part of this similarity that does not include the scaling factor. - pub isometry: Isometry, + pub isometry: Isometry, scaling: N, } #[cfg(feature = "abomonation-serialize")] -impl Abomonation for Similarity +impl Abomonation for Similarity where - Isometry: Abomonation, - DefaultAllocator: Allocator, + Isometry: Abomonation, + // DefaultAllocator: Allocator, { unsafe fn entomb(&self, writer: &mut W) -> IOResult<()> { self.isometry.entomb(writer) @@ -67,11 +67,10 @@ where } } -impl hash::Hash - for Similarity +impl hash::Hash for Similarity where - DefaultAllocator: Allocator, - Owned: hash::Hash, + // DefaultAllocator: Allocator, + Owned>: hash::Hash, { fn hash(&self, state: &mut H) { self.isometry.hash(state); @@ -79,17 +78,18 @@ where } } -impl + Copy> Copy - for Similarity +impl + Copy, const D: usize> Copy + for Similarity where - DefaultAllocator: Allocator, - Owned: Copy, + // DefaultAllocator: Allocator, + Owned>: Copy, { } -impl + Clone> Clone for Similarity -where - DefaultAllocator: Allocator, +impl + Clone, const D: usize> Clone + for Similarity +// where +// DefaultAllocator: Allocator, { #[inline] fn clone(&self) -> Self { @@ -97,10 +97,10 @@ where } } -impl Similarity +impl Similarity where R: AbstractRotation, - DefaultAllocator: Allocator, + // DefaultAllocator: Allocator, { /// Creates a new similarity from its rotational and translational parts. #[inline] @@ -110,7 +110,7 @@ where /// Creates a new similarity from its rotational and translational parts. #[inline] - pub fn from_isometry(isometry: Isometry, scaling: N) -> Self { + pub fn from_isometry(isometry: Isometry, scaling: N) -> Self { assert!(!scaling.is_zero(), "The scaling factor must not be zero."); Self { isometry, scaling } @@ -128,9 +128,9 @@ where } } -impl Similarity -where - DefaultAllocator: Allocator, +impl Similarity +// where +// DefaultAllocator: Allocator, { /// The scaling factor of this similarity transformation. #[inline] @@ -139,11 +139,11 @@ where } } -impl Similarity +impl Similarity where N::Element: SimdRealField, R: AbstractRotation, - DefaultAllocator: Allocator, + // DefaultAllocator: Allocator, { /// Creates a new similarity that applies only a scaling factor. #[inline] @@ -282,7 +282,7 @@ where /// assert_relative_eq!(transformed_vector, Vector3::new(18.0, 15.0, -12.0), epsilon = 1.0e-5); /// ``` #[inline] - pub fn transform_vector(&self, v: &VectorN) -> VectorN { + pub fn transform_vector(&self, v: &CVectorN) -> CVectorN { self * v } @@ -322,7 +322,7 @@ where /// assert_relative_eq!(transformed_vector, Vector3::new(-3.0, 2.5, 2.0), epsilon = 1.0e-5); /// ``` #[inline] - pub fn inverse_transform_vector(&self, v: &VectorN) -> VectorN { + pub fn inverse_transform_vector(&self, v: &CVectorN) -> CVectorN { self.isometry.inverse_transform_vector(v) / self.scaling() } } @@ -331,17 +331,17 @@ where // and makes it harder to use it, e.g., for Transform × Isometry implementation. // This is OK since all constructors of the isometry enforce the Rotation bound already (and // explicit struct construction is prevented by the private scaling factor). -impl Similarity -where - DefaultAllocator: Allocator, +impl Similarity +// where +// DefaultAllocator: Allocator, { /// Converts this similarity into its equivalent homogeneous transformation matrix. #[inline] - pub fn to_homogeneous(&self) -> MatrixN> + pub fn to_homogeneous(&self) -> MatrixN, U1>> where - D: DimNameAdd, - R: SubsetOf>>, - DefaultAllocator: Allocator, DimNameSum>, + Const: DimNameAdd, + R: SubsetOf, U1>>>, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, { let mut res = self.isometry.to_homogeneous(); @@ -353,17 +353,15 @@ where } } -impl Eq for Similarity -where - R: AbstractRotation + Eq, - DefaultAllocator: Allocator, +impl Eq for Similarity where + R: AbstractRotation + Eq // DefaultAllocator: Allocator, { } -impl PartialEq for Similarity +impl PartialEq for Similarity where R: AbstractRotation + PartialEq, - DefaultAllocator: Allocator, + // DefaultAllocator: Allocator, { #[inline] fn eq(&self, right: &Self) -> bool { @@ -371,10 +369,10 @@ where } } -impl AbsDiffEq for Similarity +impl AbsDiffEq for Similarity where R: AbstractRotation + AbsDiffEq, - DefaultAllocator: Allocator, + // DefaultAllocator: Allocator, N::Epsilon: Copy, { type Epsilon = N::Epsilon; @@ -391,10 +389,10 @@ where } } -impl RelativeEq for Similarity +impl RelativeEq for Similarity where R: AbstractRotation + RelativeEq, - DefaultAllocator: Allocator, + // DefaultAllocator: Allocator, N::Epsilon: Copy, { #[inline] @@ -417,10 +415,9 @@ where } } -impl UlpsEq for Similarity +impl UlpsEq for Similarity where R: AbstractRotation + UlpsEq, - DefaultAllocator: Allocator, N::Epsilon: Copy, { #[inline] @@ -440,11 +437,11 @@ where * Display * */ -impl fmt::Display for Similarity +impl fmt::Display for Similarity where N: RealField + fmt::Display, R: AbstractRotation + fmt::Display, - DefaultAllocator: Allocator + Allocator, + // DefaultAllocator: Allocator + Allocator, { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let precision = f.precision().unwrap_or(3); diff --git a/src/geometry/similarity_alias.rs b/src/geometry/similarity_alias.rs index c2c887ac..9b397bbd 100644 --- a/src/geometry/similarity_alias.rs +++ b/src/geometry/similarity_alias.rs @@ -1,15 +1,13 @@ -use crate::base::dimension::{U2, U3}; - use crate::geometry::{Rotation2, Rotation3, Similarity, UnitComplex, UnitQuaternion}; /// A 2-dimensional similarity. -pub type Similarity2 = Similarity>; +pub type Similarity2 = Similarity, 2>; /// A 3-dimensional similarity. -pub type Similarity3 = Similarity>; +pub type Similarity3 = Similarity, 3>; /// A 2-dimensional similarity using a rotation matrix for its rotation part. -pub type SimilarityMatrix2 = Similarity>; +pub type SimilarityMatrix2 = Similarity, 2>; /// A 3-dimensional similarity using a rotation matrix for its rotation part. -pub type SimilarityMatrix3 = Similarity>; +pub type SimilarityMatrix3 = Similarity, 3>; diff --git a/src/geometry/similarity_construction.rs b/src/geometry/similarity_construction.rs index 0c814534..91e4c228 100644 --- a/src/geometry/similarity_construction.rs +++ b/src/geometry/similarity_construction.rs @@ -13,20 +13,18 @@ use rand::{ use simba::scalar::SupersetOf; use simba::simd::SimdRealField; -use crate::base::allocator::Allocator; -use crate::base::dimension::{DimName, U2, U3}; -use crate::base::{DefaultAllocator, Vector2, Vector3}; +use crate::base::{Vector2, Vector3}; use crate::{ AbstractRotation, Isometry, Point, Point3, Rotation2, Rotation3, Scalar, Similarity, Translation, UnitComplex, UnitQuaternion, }; -impl Similarity +impl Similarity where N::Element: SimdRealField, R: AbstractRotation, - DefaultAllocator: Allocator, + // DefaultAllocator: Allocator, { /// Creates a new identity similarity. /// @@ -49,11 +47,11 @@ where } } -impl One for Similarity +impl One for Similarity where N::Element: SimdRealField, R: AbstractRotation, - DefaultAllocator: Allocator, + // DefaultAllocator: Allocator, { /// Creates a new identity similarity. #[inline] @@ -63,15 +61,15 @@ where } #[cfg(feature = "rand-no-std")] -impl Distribution> for Standard +impl Distribution> for Standard where R: AbstractRotation, - DefaultAllocator: Allocator, + // DefaultAllocator: Allocator, Standard: Distribution + Distribution, { /// Generate an arbitrary random variate for testing purposes. #[inline] - fn sample<'a, G: Rng + ?Sized>(&self, rng: &mut G) -> Similarity { + fn sample<'a, G: Rng + ?Sized>(&self, rng: &mut G) -> Similarity { let mut s = rng.gen(); while relative_eq!(s, N::zero()) { s = rng.gen() @@ -81,11 +79,11 @@ where } } -impl Similarity +impl Similarity where N::Element: SimdRealField, R: AbstractRotation, - DefaultAllocator: Allocator, + // DefaultAllocator: Allocator, { /// The similarity that applies the scaling factor `scaling`, followed by the rotation `r` with /// its axis passing through the point `p`. @@ -110,12 +108,12 @@ where } #[cfg(feature = "arbitrary")] -impl Arbitrary for Similarity +impl Arbitrary for Similarity where N: crate::RealField + Arbitrary + Send, N::Element: crate::RealField, R: AbstractRotation + Arbitrary + Send, - DefaultAllocator: Allocator, + // DefaultAllocator: Allocator, Owned: Send, { #[inline] @@ -136,7 +134,7 @@ where */ // 2D similarity. -impl Similarity> +impl Similarity, 2> where N::Element: SimdRealField, { @@ -170,15 +168,15 @@ where /// let sim2 = sim.cast::(); /// assert_eq!(sim2, SimilarityMatrix2::::identity()); /// ``` - pub fn cast(self) -> Similarity> + pub fn cast(self) -> Similarity, 2> where - Similarity>: SupersetOf, + Similarity, 2>: SupersetOf, { crate::convert(self) } } -impl Similarity> +impl Similarity, 2> where N::Element: SimdRealField, { @@ -212,9 +210,9 @@ where /// let sim2 = sim.cast::(); /// assert_eq!(sim2, Similarity2::::identity()); /// ``` - pub fn cast(self) -> Similarity> + pub fn cast(self) -> Similarity, 2> where - Similarity>: SupersetOf, + Similarity, 2>: SupersetOf, { crate::convert(self) } @@ -223,7 +221,7 @@ where // 3D rotation. macro_rules! similarity_construction_impl( ($Rot: ident) => { - impl Similarity> + impl Similarity, 3> where N::Element: SimdRealField { /// Creates a new similarity from a translation, rotation axis-angle, and scaling /// factor. @@ -253,7 +251,7 @@ macro_rules! similarity_construction_impl( #[inline] pub fn new(translation: Vector3, axisangle: Vector3, scaling: N) -> Self { - Self::from_isometry(Isometry::<_, U3, $Rot>::new(translation, axisangle), scaling) + Self::from_isometry(Isometry::<_, $Rot, 3>::new(translation, axisangle), scaling) } /// Cast the components of `self` to another type. @@ -265,9 +263,9 @@ macro_rules! similarity_construction_impl( /// let sim2 = sim.cast::(); /// assert_eq!(sim2, Similarity3::::identity()); /// ``` - pub fn cast(self) -> Similarity> + pub fn cast(self) -> Similarity, 3> where - Similarity>: SupersetOf, + Similarity, 3>: SupersetOf, { crate::convert(self) } @@ -306,20 +304,20 @@ macro_rules! similarity_construction_impl( /// ``` #[inline] pub fn face_towards(eye: &Point3, - target: &Point3, - up: &Vector3, - scaling: N) - -> Self { - Self::from_isometry(Isometry::<_, U3, $Rot>::face_towards(eye, target, up), scaling) + target: &Point3, + up: &Vector3, + scaling: N) + -> Self { + Self::from_isometry(Isometry::<_, $Rot, 3>::face_towards(eye, target, up), scaling) } /// Deprecated: Use [SimilarityMatrix3::face_towards] instead. #[deprecated(note="renamed to `face_towards`")] pub fn new_observer_frames(eye: &Point3, - target: &Point3, - up: &Vector3, - scaling: N) - -> Self { + target: &Point3, + up: &Vector3, + scaling: N) + -> Self { Self::face_towards(eye, target, up, scaling) } @@ -358,7 +356,7 @@ macro_rules! similarity_construction_impl( up: &Vector3, scaling: N) -> Self { - Self::from_isometry(Isometry::<_, U3, $Rot>::look_at_rh(eye, target, up), scaling) + Self::from_isometry(Isometry::<_, $Rot, 3>::look_at_rh(eye, target, up), scaling) } /// Builds a left-handed look-at view matrix including a scaling factor. @@ -396,7 +394,7 @@ macro_rules! similarity_construction_impl( up: &Vector3, scaling: N) -> Self { - Self::from_isometry(Isometry::<_, _, $Rot>::look_at_lh(eye, target, up), scaling) + Self::from_isometry(Isometry::<_, $Rot, _>::look_at_lh(eye, target, up), scaling) } } } diff --git a/src/geometry/similarity_conversion.rs b/src/geometry/similarity_conversion.rs index abcd7187..723d27dd 100644 --- a/src/geometry/similarity_conversion.rs +++ b/src/geometry/similarity_conversion.rs @@ -4,8 +4,8 @@ use simba::scalar::{RealField, SubsetOf, SupersetOf}; use simba::simd::{PrimitiveSimdValue, SimdRealField, SimdValue}; use crate::base::allocator::Allocator; -use crate::base::dimension::{DimMin, DimName, DimNameAdd, DimNameSum, U1}; -use crate::base::{DefaultAllocator, MatrixN, Scalar}; +use crate::base::dimension::{DimMin, DimNameAdd, DimNameSum, U1}; +use crate::base::{Const, DefaultAllocator, MatrixN, Scalar}; use crate::geometry::{ AbstractRotation, Isometry, Similarity, SuperTCategoryOf, TAffine, Transform, Translation, @@ -20,27 +20,27 @@ use crate::geometry::{ * Similarity -> Matrix (homogeneous) */ -impl SubsetOf> for Similarity +impl SubsetOf> for Similarity where N1: RealField + SubsetOf, N2: RealField + SupersetOf, R1: AbstractRotation + SubsetOf, R2: AbstractRotation, - DefaultAllocator: Allocator + Allocator, + // DefaultAllocator: Allocator + Allocator, { #[inline] - fn to_superset(&self) -> Similarity { + fn to_superset(&self) -> Similarity { Similarity::from_isometry(self.isometry.to_superset(), self.scaling().to_superset()) } #[inline] - fn is_in_subset(sim: &Similarity) -> bool { - crate::is_convertible::<_, Isometry>(&sim.isometry) + fn is_in_subset(sim: &Similarity) -> bool { + crate::is_convertible::<_, Isometry>(&sim.isometry) && crate::is_convertible::<_, N1>(&sim.scaling()) } #[inline] - fn from_superset_unchecked(sim: &Similarity) -> Self { + fn from_superset_unchecked(sim: &Similarity) -> Self { Similarity::from_isometry( sim.isometry.to_subset_unchecked(), sim.scaling().to_subset_unchecked(), @@ -48,64 +48,64 @@ where } } -impl SubsetOf> for Similarity +impl SubsetOf> for Similarity where N1: RealField, N2: RealField + SupersetOf, C: SuperTCategoryOf, R: AbstractRotation - + SubsetOf>> - + SubsetOf>>, - D: DimNameAdd + DimMin, // needed by .determinant() - DefaultAllocator: Allocator - + Allocator - + Allocator, DimNameSum> - + Allocator, DimNameSum> - + Allocator<(usize, usize), D> - + Allocator, DimNameSum> - + Allocator - + Allocator, + + SubsetOf, U1>>> + + SubsetOf, U1>>>, + Const: DimNameAdd + DimMin, Output = Const>, // needed by .determinant() + DefaultAllocator: Allocator, U1>, DimNameSum, U1>> + + Allocator, U1>, DimNameSum, U1>> + + Allocator, U1>, DimNameSum, U1>>, + // + Allocator<(usize, usize), D> + // + Allocator + // + Allocator + // + Allocator + // + Allocator, { #[inline] - fn to_superset(&self) -> Transform { + fn to_superset(&self) -> Transform { Transform::from_matrix_unchecked(self.to_homogeneous().to_superset()) } #[inline] - fn is_in_subset(t: &Transform) -> bool { + fn is_in_subset(t: &Transform) -> bool { >::is_in_subset(t.matrix()) } #[inline] - fn from_superset_unchecked(t: &Transform) -> Self { + fn from_superset_unchecked(t: &Transform) -> Self { Self::from_superset_unchecked(t.matrix()) } } -impl SubsetOf>> for Similarity +impl SubsetOf, U1>>> + for Similarity where N1: RealField, N2: RealField + SupersetOf, R: AbstractRotation - + SubsetOf>> - + SubsetOf>>, - D: DimNameAdd + DimMin, // needed by .determinant() - DefaultAllocator: Allocator - + Allocator - + Allocator, DimNameSum> - + Allocator, DimNameSum> - + Allocator<(usize, usize), D> - + Allocator, DimNameSum> - + Allocator - + Allocator, + + SubsetOf, U1>>> + + SubsetOf, U1>>>, + Const: DimNameAdd + DimMin, Output = Const>, // needed by .determinant() + DefaultAllocator: Allocator, U1>, DimNameSum, U1>> + + Allocator, U1>, DimNameSum, U1>> + + Allocator, U1>, DimNameSum, U1>>, // + Allocator<(usize, usize), D> + // + Allocator + // + Allocator + // + Allocator + // + Allocator { #[inline] - fn to_superset(&self) -> MatrixN> { + fn to_superset(&self) -> MatrixN, U1>> { self.to_homogeneous().to_superset() } #[inline] - fn is_in_subset(m: &MatrixN>) -> bool { + fn is_in_subset(m: &MatrixN, U1>>) -> bool { let mut rot = m.fixed_slice::(0, 0).clone_owned(); if rot .fixed_columns_mut::(0) @@ -128,20 +128,20 @@ where rot.fixed_columns_mut::(2).neg_mut(); } - let bottom = m.fixed_slice::(D::dim(), 0); + let bottom = m.fixed_slice::(D, 0); // Scalar types agree. m.iter().all(|e| SupersetOf::::is_in_subset(e)) && // The normalized block part is a rotation. // rot.is_special_orthogonal(N2::default_epsilon().sqrt()) && // The bottom row is (0, 0, ..., 1) - bottom.iter().all(|e| e.is_zero()) && m[(D::dim(), D::dim())] == N2::one() + bottom.iter().all(|e| e.is_zero()) && m[(D, D)] == N2::one() } else { false } } #[inline] - fn from_superset_unchecked(m: &MatrixN>) -> Self { + fn from_superset_unchecked(m: &MatrixN, U1>>) -> Self { let mut mm = m.clone_owned(); let na = mm.fixed_slice_mut::(0, 0).normalize_mut(); let nb = mm.fixed_slice_mut::(0, 1).normalize_mut(); @@ -158,7 +158,7 @@ where scale = -scale; } - let t = m.fixed_slice::(0, D::dim()).into_owned(); + let t = m.fixed_slice::(0, D).into_owned(); let t = Translation { vector: crate::convert_unchecked(t), }; @@ -171,30 +171,31 @@ where } } -impl From> for MatrixN> +impl From> + for MatrixN, U1>> where - D: DimNameAdd, - R: SubsetOf>>, - DefaultAllocator: Allocator + Allocator, DimNameSum>, + Const: DimNameAdd, + R: SubsetOf, U1>>>, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, // + Allocator { #[inline] - fn from(sim: Similarity) -> Self { + fn from(sim: Similarity) -> Self { sim.to_homogeneous() } } -impl - From<[Similarity; 2]> for Similarity +impl + From<[Similarity; 2]> for Similarity where N: From<[::Element; 2]>, R: SimdValue + AbstractRotation + From<[::Element; 2]>, R::Element: AbstractRotation, N::Element: Scalar + Zero + Copy, R::Element: Scalar + Zero + Copy, - DefaultAllocator: Allocator + Allocator, + // DefaultAllocator: Allocator + Allocator, { #[inline] - fn from(arr: [Similarity; 2]) -> Self { + fn from(arr: [Similarity; 2]) -> Self { let iso = Isometry::from([arr[0].isometry.clone(), arr[1].isometry.clone()]); let scale = N::from([arr[0].scaling(), arr[1].scaling()]); @@ -202,18 +203,18 @@ where } } -impl - From<[Similarity; 4]> for Similarity +impl + From<[Similarity; 4]> for Similarity where N: From<[::Element; 4]>, R: SimdValue + AbstractRotation + From<[::Element; 4]>, R::Element: AbstractRotation, N::Element: Scalar + Zero + Copy, R::Element: Scalar + Zero + Copy, - DefaultAllocator: Allocator + Allocator, + // DefaultAllocator: Allocator + Allocator, { #[inline] - fn from(arr: [Similarity; 4]) -> Self { + fn from(arr: [Similarity; 4]) -> Self { let iso = Isometry::from([ arr[0].isometry.clone(), arr[1].isometry.clone(), @@ -231,18 +232,18 @@ where } } -impl - From<[Similarity; 8]> for Similarity +impl + From<[Similarity; 8]> for Similarity where N: From<[::Element; 8]>, R: SimdValue + AbstractRotation + From<[::Element; 8]>, R::Element: AbstractRotation, N::Element: Scalar + Zero + Copy, R::Element: Scalar + Zero + Copy, - DefaultAllocator: Allocator + Allocator, + // DefaultAllocator: Allocator + Allocator, { #[inline] - fn from(arr: [Similarity; 8]) -> Self { + fn from(arr: [Similarity; 8]) -> Self { let iso = Isometry::from([ arr[0].isometry.clone(), arr[1].isometry.clone(), @@ -268,18 +269,18 @@ where } } -impl - From<[Similarity; 16]> for Similarity +impl + From<[Similarity; 16]> for Similarity where N: From<[::Element; 16]>, R: SimdValue + AbstractRotation + From<[::Element; 16]>, R::Element: AbstractRotation, N::Element: Scalar + Zero + Copy, R::Element: Scalar + Zero + Copy, - DefaultAllocator: Allocator + Allocator, + // DefaultAllocator: Allocator + Allocator, { #[inline] - fn from(arr: [Similarity; 16]) -> Self { + fn from(arr: [Similarity; 16]) -> Self { let iso = Isometry::from([ arr[0].isometry.clone(), arr[1].isometry.clone(), diff --git a/src/geometry/similarity_ops.rs b/src/geometry/similarity_ops.rs index 319d8647..4c821e21 100644 --- a/src/geometry/similarity_ops.rs +++ b/src/geometry/similarity_ops.rs @@ -144,7 +144,7 @@ macro_rules! similarity_binop_assign_impl_all( // Similarity ÷ Similarity similarity_binop_impl_all!( Mul, mul; - self: Similarity, rhs: Similarity, Output = Similarity; + self: Similarity, rhs: Similarity, Output = Similarity; [val val] => &self * &rhs; [ref val] => self * &rhs; [val ref] => &self * rhs; @@ -157,7 +157,7 @@ similarity_binop_impl_all!( similarity_binop_impl_all!( Div, div; - self: Similarity, rhs: Similarity, Output = Similarity; + self: Similarity, rhs: Similarity, Output = Similarity; [val val] => #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.inverse() }; [ref val] => #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.inverse() }; [val ref] => #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.inverse() }; @@ -167,7 +167,7 @@ similarity_binop_impl_all!( // Similarity ×= Translation similarity_binop_assign_impl_all!( MulAssign, mul_assign; - self: Similarity, rhs: Translation; + self: Similarity, rhs: Translation; [val] => *self *= &rhs; [ref] => { let shift = self.isometry.rotation.transform_vector(&rhs.vector) * self.scaling(); @@ -179,7 +179,7 @@ similarity_binop_assign_impl_all!( // Similarity ÷= Similarity similarity_binop_assign_impl_all!( MulAssign, mul_assign; - self: Similarity, rhs: Similarity; + self: Similarity, rhs: Similarity; [val] => *self *= &rhs; [ref] => { *self *= &rhs.isometry; @@ -189,7 +189,7 @@ similarity_binop_assign_impl_all!( similarity_binop_assign_impl_all!( DivAssign, div_assign; - self: Similarity, rhs: Similarity; + self: Similarity, rhs: Similarity; [val] => *self /= &rhs; // TODO: don't invert explicitly. [ref] => #[allow(clippy::suspicious_op_assign_impl)] { *self *= rhs.inverse() }; @@ -199,7 +199,7 @@ similarity_binop_assign_impl_all!( // Similarity ÷= Isometry similarity_binop_assign_impl_all!( MulAssign, mul_assign; - self: Similarity, rhs: Isometry; + self: Similarity, rhs: Isometry; [val] => *self *= &rhs; [ref] => { let shift = self.isometry.rotation.transform_vector(&rhs.translation.vector) * self.scaling(); @@ -210,7 +210,7 @@ similarity_binop_assign_impl_all!( similarity_binop_assign_impl_all!( DivAssign, div_assign; - self: Similarity, rhs: Isometry; + self: Similarity, rhs: Isometry; [val] => *self /= &rhs; // TODO: don't invert explicitly. [ref] => #[allow(clippy::suspicious_op_assign_impl)] { *self *= rhs.inverse() }; @@ -238,7 +238,7 @@ md_assign_impl_all!( md_assign_impl_all!( MulAssign, mul_assign where N: SimdRealField for N::Element: SimdRealField; (U3, U3), (U3, U3) for; - self: Similarity>, rhs: UnitQuaternion; + self: Similarity, 3>, rhs: UnitQuaternion; [val] => self.isometry.rotation *= rhs; [ref] => self.isometry.rotation *= *rhs; ); @@ -246,7 +246,7 @@ md_assign_impl_all!( md_assign_impl_all!( DivAssign, div_assign where N: SimdRealField for N::Element: SimdRealField; (U3, U3), (U3, U3) for; - self: Similarity>, rhs: UnitQuaternion; + self: Similarity, 3>, rhs: UnitQuaternion; // TODO: don't invert explicitly? [val] => #[allow(clippy::suspicious_op_assign_impl)] { *self *= rhs.inverse() }; [ref] => #[allow(clippy::suspicious_op_assign_impl)] { *self *= rhs.inverse() }; @@ -273,7 +273,7 @@ md_assign_impl_all!( // Similarity ÷ Isometry similarity_binop_impl_all!( Mul, mul; - self: Similarity, rhs: Isometry, Output = Similarity; + self: Similarity, rhs: Isometry, Output = Similarity; [val val] => &self * &rhs; [ref val] => self * &rhs; [val ref] => &self * rhs; @@ -289,7 +289,7 @@ similarity_binop_impl_all!( similarity_binop_impl_all!( Div, div; - self: Similarity, rhs: Isometry, Output = Similarity; + self: Similarity, rhs: Isometry, Output = Similarity; [val val] => #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.inverse() }; [ref val] => #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.inverse() }; [val ref] => #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.inverse() }; @@ -300,7 +300,7 @@ similarity_binop_impl_all!( // Isometry ÷ Similarity similarity_binop_impl_all!( Mul, mul; - self: Isometry, rhs: Similarity, Output = Similarity; + self: Isometry, rhs: Similarity, Output = Similarity; [val val] => { let scaling = rhs.scaling(); Similarity::from_isometry(self * rhs.isometry, scaling) @@ -321,7 +321,7 @@ similarity_binop_impl_all!( similarity_binop_impl_all!( Div, div; - self: Isometry, rhs: Similarity, Output = Similarity; + self: Isometry, rhs: Similarity, Output = Similarity; [val val] => #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.inverse() }; [ref val] => #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.inverse() }; [val ref] => #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.inverse() }; @@ -331,7 +331,7 @@ similarity_binop_impl_all!( // Similarity × Point similarity_binop_impl_all!( Mul, mul; - self: Similarity, right: Point, Output = Point; + self: Similarity, right: Point, Output = Point; [val val] => { let scaling = self.scaling(); self.isometry.translation * (self.isometry.rotation.transform_point(&right) * scaling) @@ -347,7 +347,7 @@ similarity_binop_impl_all!( // Similarity × Vector similarity_binop_impl_all!( Mul, mul; - self: Similarity, right: VectorN, Output = VectorN; + self: Similarity, right: VectorN, Output = VectorN; [val val] => self.isometry.rotation.transform_vector(&right) * self.scaling(); [ref val] => self.isometry.rotation.transform_vector(&right) * self.scaling(); [val ref] => self.isometry.rotation.transform_vector(right) * self.scaling(); @@ -357,7 +357,7 @@ similarity_binop_impl_all!( // Similarity × Translation similarity_binop_impl_all!( Mul, mul; - self: Similarity, right: Translation, Output = Similarity; + self: Similarity, right: Translation, Output = Similarity; [val val] => &self * &right; [ref val] => self * &right; [val ref] => &self * right; @@ -374,7 +374,7 @@ similarity_binop_impl_all!( // Translation × Similarity similarity_binop_impl_all!( Mul, mul; - self: Translation, right: Similarity, Output = Similarity; + self: Translation, right: Similarity, Output = Similarity; [val val] => { let scaling = right.scaling(); Similarity::from_isometry(self * right.isometry, scaling) @@ -506,8 +506,8 @@ similarity_from_composition_impl_all!( similarity_from_composition_impl_all!( Mul, mul; (U4, U1), (U3, U1); - self: Similarity>, rhs: UnitQuaternion, - Output = Similarity>; + self: Similarity, 3>, rhs: UnitQuaternion, + Output = Similarity, 3>; [val val] => { let scaling = self.scaling(); Similarity::from_isometry(self.isometry * rhs, scaling) @@ -524,8 +524,8 @@ similarity_from_composition_impl_all!( similarity_from_composition_impl_all!( Mul, mul; (U4, U1), (U3, U1); - self: UnitQuaternion, right: Similarity>, - Output = Similarity>; + self: UnitQuaternion, right: Similarity, 3>, + Output = Similarity, 3>; [val val] => &self * &right; [ref val] => self * &right; [val ref] => &self * right; @@ -536,8 +536,8 @@ similarity_from_composition_impl_all!( similarity_from_composition_impl_all!( Div, div; (U4, U1), (U3, U1); - self: Similarity>, rhs: UnitQuaternion, - Output = Similarity>; + self: Similarity, 3>, rhs: UnitQuaternion, + Output = Similarity, 3>; [val val] => { let scaling = self.scaling(); Similarity::from_isometry(self.isometry / rhs, scaling) @@ -554,8 +554,8 @@ similarity_from_composition_impl_all!( similarity_from_composition_impl_all!( Div, div; (U4, U1), (U3, U1); - self: UnitQuaternion, right: Similarity>, - Output = Similarity>; + self: UnitQuaternion, right: Similarity, 3>, + Output = Similarity, 3>; // TODO: don't call inverse explicitly? [val val] => #[allow(clippy::suspicious_arithmetic_impl)] { self * right.inverse() }; [ref val] => #[allow(clippy::suspicious_arithmetic_impl)] { self * right.inverse() }; diff --git a/src/geometry/similarity_simba.rs b/src/geometry/similarity_simba.rs index bf3858f7..0436130a 100755 --- a/src/geometry/similarity_simba.rs +++ b/src/geometry/similarity_simba.rs @@ -1,19 +1,15 @@ use simba::simd::{SimdRealField, SimdValue}; -use crate::base::allocator::Allocator; -use crate::base::dimension::DimName; -use crate::base::DefaultAllocator; - use crate::geometry::{AbstractRotation, Isometry, Similarity}; -impl SimdValue for Similarity +impl SimdValue for Similarity where N::Element: SimdRealField, R: SimdValue + AbstractRotation, R::Element: AbstractRotation, - DefaultAllocator: Allocator + Allocator, + // DefaultAllocator: Allocator + Allocator, { - type Element = Similarity; + type Element = Similarity; type SimdBool = N::SimdBool; #[inline] diff --git a/src/geometry/swizzle.rs b/src/geometry/swizzle.rs index 7797e02b..e0c42eaa 100644 --- a/src/geometry/swizzle.rs +++ b/src/geometry/swizzle.rs @@ -1,5 +1,4 @@ -use crate::base::allocator::Allocator; -use crate::base::{DefaultAllocator, DimName, Scalar, ToTypenum}; +use crate::base::{Const, Scalar, ToTypenum}; use crate::geometry::{Point, Point2, Point3}; use typenum::{self, Cmp, Greater}; @@ -10,7 +9,7 @@ macro_rules! impl_swizzle { /// Builds a new point from components of `self`. #[inline] pub fn $name(&self) -> $Result - where D::Typenum: Cmp { + where as ToTypenum>::Typenum: Cmp { $Result::new($(self[$i].inlined_clone()),*) } )* @@ -19,10 +18,10 @@ macro_rules! impl_swizzle { } /// # Swizzling -impl Point +impl Point where - D: DimName + ToTypenum, - DefaultAllocator: Allocator, + Const: ToTypenum, + // DefaultAllocator: Allocator, { impl_swizzle!( where U0: xx() -> Point2[0, 0], diff --git a/src/geometry/transform.rs b/src/geometry/transform.rs index b15eb28f..15b2c939 100755 --- a/src/geometry/transform.rs +++ b/src/geometry/transform.rs @@ -9,9 +9,9 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer}; use simba::scalar::RealField; use crate::base::allocator::Allocator; -use crate::base::dimension::{DimName, DimNameAdd, DimNameSum, U1}; +use crate::base::dimension::{DimNameAdd, DimNameSum, U1}; use crate::base::storage::Owned; -use crate::base::{DefaultAllocator, MatrixN, VectorN}; +use crate::base::{CMatrixN, CVectorN, Const, DefaultAllocator, MatrixN}; use crate::geometry::Point; @@ -28,10 +28,10 @@ pub trait TCategory: Any + Debug + Copy + PartialEq + Send { /// Checks that the given matrix is a valid homogeneous representation of an element of the /// category `Self`. - fn check_homogeneous_invariants(mat: &MatrixN) -> bool + fn check_homogeneous_invariants(mat: &CMatrixN) -> bool where - N::Epsilon: Copy, - DefaultAllocator: Allocator; + N::Epsilon: Copy; + // DefaultAllocator: Allocator; } /// Traits that gives the `Transform` category that is compatible with the result of the @@ -71,10 +71,10 @@ pub enum TAffine {} impl TCategory for TGeneral { #[inline] - fn check_homogeneous_invariants(_: &MatrixN) -> bool + fn check_homogeneous_invariants(_: &CMatrixN) -> bool where N::Epsilon: Copy, - DefaultAllocator: Allocator, + // DefaultAllocator: Allocator, { true } @@ -82,10 +82,10 @@ impl TCategory for TGeneral { impl TCategory for TProjective { #[inline] - fn check_homogeneous_invariants(mat: &MatrixN) -> bool + fn check_homogeneous_invariants(mat: &CMatrixN) -> bool where N::Epsilon: Copy, - DefaultAllocator: Allocator, + // DefaultAllocator: Allocator, { mat.is_invertible() } @@ -98,12 +98,12 @@ impl TCategory for TAffine { } #[inline] - fn check_homogeneous_invariants(mat: &MatrixN) -> bool + fn check_homogeneous_invariants(mat: &CMatrixN) -> bool where N::Epsilon: Copy, - DefaultAllocator: Allocator, + // DefaultAllocator: Allocator, { - let last = D::dim() - 1; + let last = D - 1; mat.is_invertible() && mat[(last, last)] == N::one() && (0..last).all(|i| mat[(last, i)].is_zero()) @@ -157,33 +157,36 @@ super_tcategory_impl!( /// 3D transformation. #[repr(C)] #[derive(Debug)] -pub struct Transform, C: TCategory> +pub struct Transform where - DefaultAllocator: Allocator, DimNameSum>, + Const: DimNameAdd, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, { - matrix: MatrixN>, + matrix: MatrixN, U1>>, _phantom: PhantomData, } // TODO -// impl + hash::Hash, C: TCategory> hash::Hash for Transform -// where DefaultAllocator: Allocator, DimNameSum>, -// Owned, DimNameSum>: hash::Hash { +// impl + hash::Hash, C: TCategory> hash::Hash for Transform +// where DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, +// Owned, U1>, DimNameSum, U1>>: hash::Hash { // fn hash(&self, state: &mut H) { // self.matrix.hash(state); // } // } -impl + Copy, C: TCategory> Copy for Transform +impl Copy for Transform where - DefaultAllocator: Allocator, DimNameSum>, - Owned, DimNameSum>: Copy, + Const: DimNameAdd, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, + Owned, U1>, DimNameSum, U1>>: Copy, { } -impl, C: TCategory> Clone for Transform +impl Clone for Transform where - DefaultAllocator: Allocator, DimNameSum>, + Const: DimNameAdd, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, { #[inline] fn clone(&self) -> Self { @@ -192,10 +195,11 @@ where } #[cfg(feature = "serde-serialize")] -impl, C: TCategory> Serialize for Transform +impl Serialize for Transform where - DefaultAllocator: Allocator, DimNameSum>, - Owned, DimNameSum>: Serialize, + Const: DimNameAdd, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, + Owned, U1>, DimNameSum, U1>>: Serialize, { fn serialize(&self, serializer: S) -> Result where @@ -206,29 +210,33 @@ where } #[cfg(feature = "serde-serialize")] -impl<'a, N: RealField, D: DimNameAdd, C: TCategory> Deserialize<'a> for Transform +impl<'a, N: RealField, C: TCategory, const D: usize> Deserialize<'a> for Transform where - DefaultAllocator: Allocator, DimNameSum>, - Owned, DimNameSum>: Deserialize<'a>, + Const: DimNameAdd, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, + Owned, U1>, DimNameSum, U1>>: Deserialize<'a>, { fn deserialize(deserializer: Des) -> Result where Des: Deserializer<'a>, { - let matrix = MatrixN::>::deserialize(deserializer)?; + let matrix = MatrixN::, U1>>::deserialize(deserializer)?; Ok(Transform::from_matrix_unchecked(matrix)) } } -impl, C: TCategory> Eq for Transform where - DefaultAllocator: Allocator, DimNameSum> +impl Eq for Transform +where + Const: DimNameAdd, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, { } -impl, C: TCategory> PartialEq for Transform +impl PartialEq for Transform where - DefaultAllocator: Allocator, DimNameSum>, + Const: DimNameAdd, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, { #[inline] fn eq(&self, right: &Self) -> bool { @@ -236,14 +244,15 @@ where } } -impl, C: TCategory> Transform +impl Transform where - DefaultAllocator: Allocator, DimNameSum>, + Const: DimNameAdd, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, { /// Creates a new transformation from the given homogeneous matrix. The transformation category /// of `Self` is not checked to be verified by the given matrix. #[inline] - pub fn from_matrix_unchecked(matrix: MatrixN>) -> Self { + pub fn from_matrix_unchecked(matrix: MatrixN, U1>>) -> Self { Transform { matrix, _phantom: PhantomData, @@ -263,7 +272,7 @@ where /// assert_eq!(t.into_inner(), m); /// ``` #[inline] - pub fn into_inner(self) -> MatrixN> { + pub fn into_inner(self) -> MatrixN, U1>> { self.matrix } @@ -271,7 +280,7 @@ where /// Deprecated: Use [Transform::into_inner] instead. #[deprecated(note = "use `.into_inner()` instead")] #[inline] - pub fn unwrap(self) -> MatrixN> { + pub fn unwrap(self) -> MatrixN, U1>> { self.matrix } @@ -288,7 +297,7 @@ where /// assert_eq!(*t.matrix(), m); /// ``` #[inline] - pub fn matrix(&self) -> &MatrixN> { + pub fn matrix(&self) -> &MatrixN, U1>> { &self.matrix } @@ -315,7 +324,7 @@ where /// assert_eq!(*t.matrix(), expected); /// ``` #[inline] - pub fn matrix_mut_unchecked(&mut self) -> &mut MatrixN> { + pub fn matrix_mut_unchecked(&mut self) -> &mut MatrixN, U1>> { &mut self.matrix } @@ -326,7 +335,7 @@ where /// `TAffine` because not all projective transformations are affine (the other way-round is /// valid though). #[inline] - pub fn set_category>(self) -> Transform { + pub fn set_category>(self) -> Transform { Transform::from_matrix_unchecked(self.matrix) } @@ -335,7 +344,7 @@ where #[deprecated( note = "This method is redundant with automatic `Copy` and the `.clone()` method and will be removed in a future release." )] - pub fn clone_owned(&self) -> Transform { + pub fn clone_owned(&self) -> Transform { Transform::from_matrix_unchecked(self.matrix.clone_owned()) } @@ -352,7 +361,7 @@ where /// assert_eq!(t.into_inner(), m); /// ``` #[inline] - pub fn to_homogeneous(&self) -> MatrixN> { + pub fn to_homogeneous(&self) -> MatrixN, U1>> { self.matrix().clone_owned() } @@ -381,7 +390,7 @@ where /// ``` #[inline] #[must_use = "Did you mean to use try_inverse_mut()?"] - pub fn try_inverse(self) -> Option> { + pub fn try_inverse(self) -> Option> { if let Some(m) = self.matrix.try_inverse() { Some(Transform::from_matrix_unchecked(m)) } else { @@ -407,7 +416,7 @@ where /// ``` #[inline] #[must_use = "Did you mean to use inverse_mut()?"] - pub fn inverse(self) -> Transform + pub fn inverse(self) -> Transform where C: SubTCategoryOf, { @@ -470,14 +479,14 @@ where } } -impl, C> Transform +impl Transform where N: RealField, C: TCategory, - DefaultAllocator: Allocator, DimNameSum> - + Allocator> - + Allocator - + Allocator, + Const: DimNameAdd, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>> + + Allocator, U1>>, // + Allocator + // + Allocator { /// Transform the given point by this transformation. /// @@ -492,18 +501,18 @@ where /// /// This is the same as the multiplication `self * v`. #[inline] - pub fn transform_vector(&self, v: &VectorN) -> VectorN { + pub fn transform_vector(&self, v: &CVectorN) -> CVectorN { self * v } } -impl, C: TCategory> Transform +impl Transform where + Const: DimNameAdd, C: SubTCategoryOf, - DefaultAllocator: Allocator, DimNameSum> - + Allocator> - + Allocator - + Allocator, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>> + + Allocator, U1>>, // + Allocator + // + Allocator { /// Transform the given point by the inverse of this transformation. /// This may be cheaper than inverting the transformation and transforming @@ -517,27 +526,29 @@ where /// This may be cheaper than inverting the transformation and transforming /// the vector. #[inline] - pub fn inverse_transform_vector(&self, v: &VectorN) -> VectorN { + pub fn inverse_transform_vector(&self, v: &CVectorN) -> CVectorN { self.clone().inverse() * v } } -impl> Transform +impl Transform where - DefaultAllocator: Allocator, DimNameSum>, + Const: DimNameAdd, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, { /// A mutable reference to underlying matrix. Use `.matrix_mut_unchecked` instead if this /// transformation category is not `TGeneral`. #[inline] - pub fn matrix_mut(&mut self) -> &mut MatrixN> { + pub fn matrix_mut(&mut self) -> &mut MatrixN, U1>> { self.matrix_mut_unchecked() } } -impl, C: TCategory> AbsDiffEq for Transform +impl AbsDiffEq for Transform where + Const: DimNameAdd, N::Epsilon: Copy, - DefaultAllocator: Allocator, DimNameSum>, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, { type Epsilon = N::Epsilon; @@ -552,10 +563,11 @@ where } } -impl, C: TCategory> RelativeEq for Transform +impl RelativeEq for Transform where + Const: DimNameAdd, N::Epsilon: Copy, - DefaultAllocator: Allocator, DimNameSum>, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, { #[inline] fn default_max_relative() -> Self::Epsilon { @@ -574,10 +586,11 @@ where } } -impl, C: TCategory> UlpsEq for Transform +impl UlpsEq for Transform where + Const: DimNameAdd, N::Epsilon: Copy, - DefaultAllocator: Allocator, DimNameSum>, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, { #[inline] fn default_max_ulps() -> u32 { diff --git a/src/geometry/transform_alias.rs b/src/geometry/transform_alias.rs index 58a5ee1e..f869f0e2 100644 --- a/src/geometry/transform_alias.rs +++ b/src/geometry/transform_alias.rs @@ -1,17 +1,15 @@ -use crate::base::dimension::{U2, U3}; - use crate::geometry::{TAffine, TGeneral, TProjective, Transform}; /// A 2D general transformation that may not be invertible. Stored as a homogeneous 3x3 matrix. -pub type Transform2 = Transform; +pub type Transform2 = Transform; /// An invertible 2D general transformation. Stored as a homogeneous 3x3 matrix. -pub type Projective2 = Transform; +pub type Projective2 = Transform; /// A 2D affine transformation. Stored as a homogeneous 3x3 matrix. -pub type Affine2 = Transform; +pub type Affine2 = Transform; /// A 3D general transformation that may not be inversible. Stored as a homogeneous 4x4 matrix. -pub type Transform3 = Transform; +pub type Transform3 = Transform; /// An invertible 3D general transformation. Stored as a homogeneous 4x4 matrix. -pub type Projective3 = Transform; +pub type Projective3 = Transform; /// A 3D affine transformation. Stored as a homogeneous 4x4 matrix. -pub type Affine3 = Transform; +pub type Affine3 = Transform; diff --git a/src/geometry/transform_construction.rs b/src/geometry/transform_construction.rs index e0826eeb..0d5f8b1e 100644 --- a/src/geometry/transform_construction.rs +++ b/src/geometry/transform_construction.rs @@ -4,13 +4,14 @@ use simba::scalar::RealField; use crate::base::allocator::Allocator; use crate::base::dimension::{DimNameAdd, DimNameSum, U1}; -use crate::base::{DefaultAllocator, MatrixN}; +use crate::base::{Const, DefaultAllocator, MatrixN}; use crate::geometry::{TCategory, Transform}; -impl, C: TCategory> Transform +impl Transform where - DefaultAllocator: Allocator, DimNameSum>, + Const: DimNameAdd, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, { /// Creates a new identity transform. /// @@ -42,13 +43,14 @@ where /// ``` #[inline] pub fn identity() -> Self { - Self::from_matrix_unchecked(MatrixN::<_, DimNameSum>::identity()) + Self::from_matrix_unchecked(MatrixN::<_, DimNameSum, U1>>::identity()) } } -impl, C: TCategory> One for Transform +impl One for Transform where - DefaultAllocator: Allocator, DimNameSum>, + Const: DimNameAdd, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, { /// Creates a new identity transform. #[inline] diff --git a/src/geometry/transform_conversion.rs b/src/geometry/transform_conversion.rs index 6c531f84..0522f7a2 100644 --- a/src/geometry/transform_conversion.rs +++ b/src/geometry/transform_conversion.rs @@ -1,74 +1,76 @@ use simba::scalar::{RealField, SubsetOf}; use crate::base::allocator::Allocator; -use crate::base::dimension::{DimName, DimNameAdd, DimNameSum, U1}; -use crate::base::{DefaultAllocator, MatrixN}; +use crate::base::dimension::{DimNameAdd, DimNameSum, U1}; +use crate::base::{Const, DefaultAllocator, MatrixN}; use crate::geometry::{SuperTCategoryOf, TCategory, Transform}; -impl SubsetOf> for Transform +impl SubsetOf> for Transform where N1: RealField + SubsetOf, N2: RealField, C1: TCategory, C2: SuperTCategoryOf, - D: DimNameAdd, - DefaultAllocator: Allocator, DimNameSum> - + Allocator, DimNameSum>, + Const: DimNameAdd, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>> + + Allocator, U1>, DimNameSum, U1>>, N1::Epsilon: Copy, N2::Epsilon: Copy, { #[inline] - fn to_superset(&self) -> Transform { + fn to_superset(&self) -> Transform { Transform::from_matrix_unchecked(self.to_homogeneous().to_superset()) } #[inline] - fn is_in_subset(t: &Transform) -> bool { + fn is_in_subset(t: &Transform) -> bool { >::is_in_subset(t.matrix()) } #[inline] - fn from_superset_unchecked(t: &Transform) -> Self { + fn from_superset_unchecked(t: &Transform) -> Self { Self::from_superset_unchecked(t.matrix()) } } -impl SubsetOf>> for Transform +impl SubsetOf, U1>>> + for Transform where N1: RealField + SubsetOf, N2: RealField, C: TCategory, - D: DimNameAdd, - DefaultAllocator: Allocator, DimNameSum> - + Allocator, DimNameSum>, + Const: DimNameAdd, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>> + + Allocator, U1>, DimNameSum, U1>>, N1::Epsilon: Copy, N2::Epsilon: Copy, { #[inline] - fn to_superset(&self) -> MatrixN> { + fn to_superset(&self) -> MatrixN, U1>> { self.matrix().to_superset() } #[inline] - fn is_in_subset(m: &MatrixN>) -> bool { + fn is_in_subset(m: &MatrixN, U1>>) -> bool { C::check_homogeneous_invariants(m) } #[inline] - fn from_superset_unchecked(m: &MatrixN>) -> Self { + fn from_superset_unchecked(m: &MatrixN, U1>>) -> Self { Self::from_matrix_unchecked(crate::convert_ref_unchecked(m)) } } -impl From> for MatrixN> +impl From> + for MatrixN, U1>> where - D: DimNameAdd, + Const: DimNameAdd, C: TCategory, - DefaultAllocator: Allocator, DimNameSum>, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, { #[inline] - fn from(t: Transform) -> Self { + fn from(t: Transform) -> Self { t.to_homogeneous() } } diff --git a/src/geometry/transform_ops.rs b/src/geometry/transform_ops.rs index 01cf4d3d..9a51bbb4 100644 --- a/src/geometry/transform_ops.rs +++ b/src/geometry/transform_ops.rs @@ -79,10 +79,10 @@ use crate::geometry::{ * Indexing. * */ -impl Index<(usize, usize)> for Transform +impl Index<(usize, usize)> for Transform where - D: DimName + DimNameAdd, - DefaultAllocator: Allocator, DimNameSum>, + Const: DimNameAdd, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, { type Output = N; @@ -93,10 +93,10 @@ where } // Only general transformations are mutably indexable. -impl IndexMut<(usize, usize)> for Transform +impl IndexMut<(usize, usize)> for Transform where - D: DimName + DimNameAdd, - DefaultAllocator: Allocator, DimNameSum>, + Const: DimNameAdd, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, { #[inline] fn index_mut(&mut self, ij: (usize, usize)) -> &mut N { @@ -108,7 +108,7 @@ where md_impl_all!( Mul, mul where N: RealField; (DimNameSum, DimNameSum), (D, U1) for D: DimNameAdd, C: TCategory; - self: Transform, rhs: VectorN, Output = VectorN; + self: Transform, rhs: VectorN, Output = VectorN; [val val] => &self * &rhs; [ref val] => self * &rhs; [val ref] => &self * rhs; @@ -133,7 +133,7 @@ md_impl_all!( Mul, mul where N: RealField; (DimNameSum, DimNameSum), (D, U1) for D: DimNameAdd, C: TCategory where DefaultAllocator: Allocator; - self: Transform, rhs: Point, Output = Point; + self: Transform, rhs: Point, Output = Point; [val val] => &self * &rhs; [ref val] => self * &rhs; [val ref] => &self * rhs; @@ -170,7 +170,7 @@ md_impl_all!( md_impl_all!( Mul, mul where N: RealField; (DimNameSum, DimNameSum), (D, D) for D: DimNameAdd, C: TCategoryMul; - self: Transform, rhs: Rotation, Output = Transform; + self: Transform, rhs: Rotation, 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()); @@ -181,7 +181,7 @@ md_impl_all!( md_impl_all!( Mul, mul where N: RealField; (D, D), (DimNameSum, DimNameSum) for D: DimNameAdd, C: TCategoryMul; - self: Rotation, rhs: Transform, Output = Transform; + self: Rotation, 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()); @@ -192,7 +192,7 @@ md_impl_all!( md_impl_all!( Mul, mul where N: RealField; (U4, U4), (U4, U1) for C: TCategoryMul; - self: Transform, rhs: UnitQuaternion, Output = Transform; + self: Transform, rhs: UnitQuaternion, 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()); @@ -203,7 +203,7 @@ md_impl_all!( md_impl_all!( Mul, mul where N: RealField; (U4, U1), (U4, U4) for C: TCategoryMul; - self: UnitQuaternion, rhs: Transform, Output = Transform; + self: UnitQuaternion, 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()); @@ -215,7 +215,7 @@ md_impl_all!( Mul, mul where N: RealField; (DimNameSum, DimNameSum), (D, U1) for D: DimNameAdd, C: TCategoryMul, R: SubsetOf> >; - self: Transform, rhs: Isometry, Output = Transform; + self: Transform, rhs: Isometry, 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()); @@ -227,7 +227,7 @@ md_impl_all!( Mul, mul where N: RealField; (D, U1), (DimNameSum, DimNameSum) for D: DimNameAdd, C: TCategoryMul, R: SubsetOf> >; - self: Isometry, rhs: Transform, Output = Transform; + self: Isometry, 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()); @@ -239,7 +239,7 @@ md_impl_all!( Mul, mul where N: RealField; (DimNameSum, DimNameSum), (D, U1) for D: DimNameAdd, C: TCategoryMul, R: SubsetOf> >; - self: Transform, rhs: Similarity, Output = Transform; + self: Transform, rhs: Similarity, 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()); @@ -251,7 +251,7 @@ md_impl_all!( Mul, mul where N: RealField; (D, U1), (DimNameSum, DimNameSum) for D: DimNameAdd, C: TCategoryMul, R: SubsetOf> >; - self: Similarity, rhs: Transform, Output = Transform; + self: Similarity, 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()); @@ -270,7 +270,7 @@ md_impl_all!( md_impl_all!( Mul, mul where N: RealField; (DimNameSum, DimNameSum), (D, U1) for D: DimNameAdd, C: TCategoryMul; - self: Transform, rhs: Translation, Output = Transform; + self: Transform, rhs: Translation, 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()); @@ -282,7 +282,7 @@ md_impl_all!( Mul, mul where N: RealField; (D, U1), (DimNameSum, DimNameSum) for D: DimNameAdd, C: TCategoryMul; - self: Translation, rhs: Transform, Output = Transform; + self: Translation, 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()); @@ -304,7 +304,7 @@ md_impl_all!( md_impl_all!( Div, div where N: RealField; (DimNameSum, DimNameSum), (D, D) for D: DimNameAdd, C: TCategoryMul; - self: Transform, rhs: Rotation, Output = Transform; + self: Transform, rhs: Rotation, Output = Transform; [val val] => #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.inverse() }; [ref val] => #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.inverse() }; [val ref] => #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.inverse() }; @@ -315,7 +315,7 @@ md_impl_all!( md_impl_all!( Div, div where N: RealField; (D, D), (DimNameSum, DimNameSum) for D: DimNameAdd, C: TCategoryMul; - self: Rotation, rhs: Transform, Output = Transform; + self: Rotation, rhs: Transform, Output = Transform; [val val] => #[allow(clippy::suspicious_arithmetic_impl)] { self.inverse() * rhs }; [ref val] => #[allow(clippy::suspicious_arithmetic_impl)] { self.inverse() * rhs }; [val ref] => #[allow(clippy::suspicious_arithmetic_impl)] { self.inverse() * rhs }; @@ -326,7 +326,7 @@ md_impl_all!( md_impl_all!( Div, div where N: RealField; (U4, U4), (U4, U1) for C: TCategoryMul; - self: Transform, rhs: UnitQuaternion, Output = Transform; + self: Transform, rhs: UnitQuaternion, Output = Transform; [val val] => #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.inverse() }; [ref val] => #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.inverse() }; [val ref] => #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.inverse() }; @@ -337,7 +337,7 @@ md_impl_all!( md_impl_all!( Div, div where N: RealField; (U4, U1), (U4, U4) for C: TCategoryMul; - self: UnitQuaternion, rhs: Transform, Output = Transform; + self: UnitQuaternion, rhs: Transform, Output = Transform; [val val] => #[allow(clippy::suspicious_arithmetic_impl)] { self.inverse() * rhs }; [ref val] => #[allow(clippy::suspicious_arithmetic_impl)] { self.inverse() * rhs }; [val ref] => #[allow(clippy::suspicious_arithmetic_impl)] { self.inverse() * rhs }; @@ -350,7 +350,7 @@ md_impl_all!( // (DimNameSum, DimNameSum), (D, U1) // for D: DimNameAdd, C: TCategoryMul, R: SubsetOf> > // where SB::Alloc: Allocator, DimNameSum >; -// self: Transform, rhs: Isometry, Output = Transform; +// self: Transform, rhs: Isometry, Output = Transform; // [val val] => Self::Output::from_matrix_unchecked(self.into_inner() * rhs.inverse().to_homogeneous()); // [ref val] => Self::Output::from_matrix_unchecked(self.matrix() * rhs.inverse().to_homogeneous()); // [val ref] => Self::Output::from_matrix_unchecked(self.into_inner() * rhs.inverse().to_homogeneous()); @@ -363,7 +363,7 @@ md_impl_all!( // (D, U1), (DimNameSum, DimNameSum) // for D: DimNameAdd, C: TCategoryMul, R: SubsetOf> > // where SA::Alloc: Allocator, DimNameSum >; -// self: Isometry, rhs: Transform, Output = Transform; +// self: Isometry, 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()); @@ -377,7 +377,7 @@ md_impl_all!( // for D: DimNameAdd, C: TCategoryMul, R: SubsetOf> > // where SB::Alloc: Allocator // where SB::Alloc: Allocator, DimNameSum >; -// self: Transform, rhs: Similarity, Output = Transform; +// self: Transform, rhs: Similarity, 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()); @@ -391,7 +391,7 @@ md_impl_all!( // for D: DimNameAdd, C: TCategoryMul, R: SubsetOf> > // where SA::Alloc: Allocator // where SA::Alloc: Allocator, DimNameSum >; -// self: Similarity, rhs: Transform, Output = Transform; +// self: Similarity, 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()); @@ -402,7 +402,7 @@ md_impl_all!( md_impl_all!( Div, div where N: RealField; (DimNameSum, DimNameSum), (D, U1) for D: DimNameAdd, C: TCategoryMul; - self: Transform, rhs: Translation, Output = Transform; + self: Transform, rhs: Translation, Output = Transform; [val val] => #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.inverse() }; [ref val] => #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.inverse() }; [val ref] => #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.inverse() }; @@ -414,7 +414,7 @@ md_impl_all!( Div, div where N: RealField; (D, U1), (DimNameSum, DimNameSum) for D: DimNameAdd, C: TCategoryMul; - self: Translation, rhs: Transform, Output = Transform; + self: Translation, rhs: Transform, Output = Transform; [val val] => #[allow(clippy::suspicious_arithmetic_impl)] { self.inverse() * rhs }; [ref val] => #[allow(clippy::suspicious_arithmetic_impl)] { self.inverse() * rhs }; [val ref] => #[allow(clippy::suspicious_arithmetic_impl)] { self.inverse() * rhs }; @@ -435,7 +435,7 @@ md_assign_impl_all!( MulAssign, mul_assign where N: RealField; (DimNameSum, DimNameSum), (D, U1) for D: DimNameAdd, C: TCategory, R: SubsetOf> >; - self: Transform, rhs: Similarity; + self: Transform, rhs: Similarity; [val] => *self.matrix_mut_unchecked() *= rhs.to_homogeneous(); [ref] => *self.matrix_mut_unchecked() *= rhs.to_homogeneous(); ); @@ -445,7 +445,7 @@ md_assign_impl_all!( MulAssign, mul_assign where N: RealField; (DimNameSum, DimNameSum), (D, U1) for D: DimNameAdd, C: TCategory, R: SubsetOf> >; - self: Transform, rhs: Isometry; + self: Transform, rhs: Isometry; [val] => *self.matrix_mut_unchecked() *= rhs.to_homogeneous(); [ref] => *self.matrix_mut_unchecked() *= rhs.to_homogeneous(); ); @@ -462,7 +462,7 @@ md_assign_impl_all!( md_assign_impl_all!( MulAssign, mul_assign where N: RealField; (DimNameSum, DimNameSum), (D, U1) for D: DimNameAdd, C: TCategory; - self: Transform, rhs: Translation; + self: Transform, rhs: Translation; [val] => *self.matrix_mut_unchecked() *= rhs.to_homogeneous(); [ref] => *self.matrix_mut_unchecked() *= rhs.to_homogeneous(); ); @@ -471,7 +471,7 @@ md_assign_impl_all!( md_assign_impl_all!( MulAssign, mul_assign where N: RealField; (DimNameSum, DimNameSum), (D, D) for D: DimNameAdd, C: TCategory; - self: Transform, rhs: Rotation; + self: Transform, rhs: Rotation; [val] => *self.matrix_mut_unchecked() *= rhs.to_homogeneous(); [ref] => *self.matrix_mut_unchecked() *= rhs.to_homogeneous(); ); @@ -480,7 +480,7 @@ md_assign_impl_all!( md_assign_impl_all!( MulAssign, mul_assign where N: RealField; (U4, U4), (U4, U1) for C: TCategory; - self: Transform, rhs: UnitQuaternion; + self: Transform, rhs: UnitQuaternion; [val] => *self.matrix_mut_unchecked() *= rhs.to_homogeneous(); [ref] => *self.matrix_mut_unchecked() *= rhs.to_homogeneous(); ); @@ -500,7 +500,7 @@ md_assign_impl_all!( // DivAssign, div_assign; // (DimNameSum, DimNameSum), (D, U1) // for D: DimNameAdd, C: TCategory, R: SubsetOf> >; -// self: Transform, rhs: Similarity; +// self: Transform, rhs: Similarity; // [val] => *self *= rhs.inverse(); // [ref] => *self *= rhs.inverse(); // ); @@ -511,7 +511,7 @@ md_assign_impl_all!( // DivAssign, div_assign; // (DimNameSum, DimNameSum), (D, U1) // for D: DimNameAdd, C: TCategory, R: SubsetOf> >; -// self: Transform, rhs: Isometry; +// self: Transform, rhs: Isometry; // [val] => *self *= rhs.inverse(); // [ref] => *self *= rhs.inverse(); // ); @@ -520,7 +520,7 @@ md_assign_impl_all!( md_assign_impl_all!( DivAssign, div_assign where N: RealField; (DimNameSum, DimNameSum), (D, U1) for D: DimNameAdd, C: TCategory; - self: Transform, rhs: Translation; + self: Transform, rhs: Translation; [val] => #[allow(clippy::suspicious_op_assign_impl)] { *self *= rhs.inverse() }; [ref] => #[allow(clippy::suspicious_op_assign_impl)] { *self *= rhs.inverse() }; ); @@ -529,7 +529,7 @@ md_assign_impl_all!( md_assign_impl_all!( DivAssign, div_assign where N: RealField; (DimNameSum, DimNameSum), (D, D) for D: DimNameAdd, C: TCategory; - self: Transform, rhs: Rotation; + self: Transform, rhs: Rotation; [val] => #[allow(clippy::suspicious_op_assign_impl)] { *self *= rhs.inverse() }; [ref] => #[allow(clippy::suspicious_op_assign_impl)] { *self *= rhs.inverse() }; ); @@ -538,7 +538,7 @@ md_assign_impl_all!( md_assign_impl_all!( DivAssign, div_assign where N: RealField; (U4, U4), (U4, U1) for C: TCategory; - self: Transform, rhs: UnitQuaternion; + self: Transform, rhs: UnitQuaternion; [val] => #[allow(clippy::suspicious_op_assign_impl)] { *self *= rhs.inverse() }; [ref] => #[allow(clippy::suspicious_op_assign_impl)] { *self *= rhs.inverse() }; ); diff --git a/src/geometry/transform_simba.rs b/src/geometry/transform_simba.rs index d50843f4..0d116137 100755 --- a/src/geometry/transform_simba.rs +++ b/src/geometry/transform_simba.rs @@ -2,19 +2,20 @@ use simba::simd::SimdValue; use crate::base::allocator::Allocator; use crate::base::dimension::{DimNameAdd, DimNameSum, U1}; -use crate::base::{DefaultAllocator, MatrixN, Scalar}; +use crate::base::{Const, DefaultAllocator, MatrixN, Scalar}; use crate::RealField; use crate::geometry::{TCategory, Transform}; -impl, C> SimdValue for Transform +impl SimdValue for Transform where N::Element: Scalar, C: TCategory, - DefaultAllocator: Allocator, DimNameSum> - + Allocator, DimNameSum>, + Const: DimNameAdd, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>> + + Allocator, U1>, DimNameSum, U1>>, { - type Element = Transform; + type Element = Transform; type SimdBool = N::SimdBool; #[inline] diff --git a/src/geometry/translation.rs b/src/geometry/translation.rs index 26bbfd12..1ae452bb 100755 --- a/src/geometry/translation.rs +++ b/src/geometry/translation.rs @@ -14,45 +14,44 @@ use abomonation::Abomonation; use simba::scalar::{ClosedAdd, ClosedNeg, ClosedSub}; use crate::base::allocator::Allocator; -use crate::base::dimension::{DimName, DimNameAdd, DimNameSum, U1}; +use crate::base::dimension::{DimNameAdd, DimNameSum, U1}; use crate::base::storage::Owned; -use crate::base::{DefaultAllocator, MatrixN, Scalar, VectorN}; +use crate::base::{CVectorN, Const, DefaultAllocator, MatrixN, Scalar}; use crate::geometry::Point; /// A translation. #[repr(C)] #[derive(Debug)] -pub struct Translation -where - DefaultAllocator: Allocator, +pub struct Translation +// where +// DefaultAllocator: Allocator, { /// The translation coordinates, i.e., how much is added to a point's coordinates when it is /// translated. - pub vector: VectorN, + pub vector: CVectorN, } -impl hash::Hash for Translation +impl hash::Hash for Translation where - DefaultAllocator: Allocator, - Owned: hash::Hash, + // DefaultAllocator: Allocator, + Owned>: hash::Hash, { fn hash(&self, state: &mut H) { self.vector.hash(state) } } -impl Copy for Translation -where - DefaultAllocator: Allocator, - Owned: Copy, +impl Copy for Translation where + // DefaultAllocator: Allocator, + Owned>: Copy { } -impl Clone for Translation +impl Clone for Translation where - DefaultAllocator: Allocator, - Owned: Clone, + // DefaultAllocator: Allocator, + Owned>: Clone, { #[inline] fn clone(&self) -> Self { @@ -65,8 +64,8 @@ impl Abomonation for Translation where N: Scalar, D: DimName, - VectorN: Abomonation, - DefaultAllocator: Allocator, + CVectorN: Abomonation, + // DefaultAllocator: Allocator, { unsafe fn entomb(&self, writer: &mut W) -> IOResult<()> { self.vector.entomb(writer) @@ -82,9 +81,9 @@ where } #[cfg(feature = "serde-serialize")] -impl Serialize for Translation +impl Serialize for Translation where - DefaultAllocator: Allocator, + // DefaultAllocator: Allocator, Owned: Serialize, { fn serialize(&self, serializer: S) -> Result @@ -96,29 +95,29 @@ where } #[cfg(feature = "serde-serialize")] -impl<'a, N: Scalar, D: DimName> Deserialize<'a> for Translation +impl<'a, N: Scalar, const D: usize> Deserialize<'a> for Translation where - DefaultAllocator: Allocator, + // DefaultAllocator: Allocator, Owned: Deserialize<'a>, { fn deserialize(deserializer: Des) -> Result where Des: Deserializer<'a>, { - let matrix = VectorN::::deserialize(deserializer)?; + let matrix = CVectorN::::deserialize(deserializer)?; Ok(Translation::from(matrix)) } } -impl Translation -where - DefaultAllocator: Allocator, +impl Translation +// where +// DefaultAllocator: Allocator, { /// Creates a new translation from the given vector. #[inline] #[deprecated(note = "Use `::from` instead.")] - pub fn from_vector(vector: VectorN) -> Translation { + pub fn from_vector(vector: CVectorN) -> Translation { Translation { vector } } @@ -164,15 +163,14 @@ where /// assert_eq!(t.to_homogeneous(), expected); /// ``` #[inline] - pub fn to_homogeneous(&self) -> MatrixN> + pub fn to_homogeneous(&self) -> MatrixN, U1>> where N: Zero + One, - D: DimNameAdd, - DefaultAllocator: Allocator, DimNameSum>, + Const: DimNameAdd, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, { let mut res = MatrixN::>::identity(); - res.fixed_slice_mut::(0, D::dim()) - .copy_from(&self.vector); + res.fixed_slice_mut::(0, D).copy_from(&self.vector); res } @@ -204,9 +202,9 @@ where } } -impl Translation -where - DefaultAllocator: Allocator, +impl Translation +// where +// DefaultAllocator: Allocator, { /// Translate the given point. /// @@ -224,9 +222,9 @@ where } } -impl Translation -where - DefaultAllocator: Allocator, +impl Translation +// where +// DefaultAllocator: Allocator, { /// Translate the given point by the inverse of this translation. /// @@ -242,11 +240,14 @@ where } } -impl Eq for Translation where DefaultAllocator: Allocator {} +impl Eq for Translation +// where DefaultAllocator: Allocator +{ +} -impl PartialEq for Translation -where - DefaultAllocator: Allocator, +impl PartialEq for Translation +// where +// DefaultAllocator: Allocator, { #[inline] fn eq(&self, right: &Translation) -> bool { @@ -254,9 +255,9 @@ where } } -impl AbsDiffEq for Translation +impl AbsDiffEq for Translation where - DefaultAllocator: Allocator, + // DefaultAllocator: Allocator, N::Epsilon: Copy, { type Epsilon = N::Epsilon; @@ -272,9 +273,9 @@ where } } -impl RelativeEq for Translation +impl RelativeEq for Translation where - DefaultAllocator: Allocator, + // DefaultAllocator: Allocator, N::Epsilon: Copy, { #[inline] @@ -294,9 +295,9 @@ where } } -impl UlpsEq for Translation +impl UlpsEq for Translation where - DefaultAllocator: Allocator, + // DefaultAllocator: Allocator, N::Epsilon: Copy, { #[inline] @@ -315,9 +316,9 @@ where * Display * */ -impl fmt::Display for Translation -where - DefaultAllocator: Allocator + Allocator, +impl fmt::Display for Translation +// where +// DefaultAllocator: Allocator + Allocator, { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let precision = f.precision().unwrap_or(3); diff --git a/src/geometry/translation_alias.rs b/src/geometry/translation_alias.rs index 13db0495..554fecc5 100644 --- a/src/geometry/translation_alias.rs +++ b/src/geometry/translation_alias.rs @@ -1,21 +1,19 @@ -use crate::base::dimension::{U1, U2, U3, U4, U5, U6}; - use crate::geometry::Translation; /// A 1-dimensional translation. -pub type Translation1 = Translation; +pub type Translation1 = Translation; /// A 2-dimensional translation. -pub type Translation2 = Translation; +pub type Translation2 = Translation; /// A 3-dimensional translation. -pub type Translation3 = Translation; +pub type Translation3 = Translation; /// A 4-dimensional translation. -pub type Translation4 = Translation; +pub type Translation4 = Translation; /// A 5-dimensional translation. -pub type Translation5 = Translation; +pub type Translation5 = Translation; /// A 6-dimensional translation. -pub type Translation6 = Translation; +pub type Translation6 = Translation; diff --git a/src/geometry/translation_construction.rs b/src/geometry/translation_construction.rs index c1c02862..cfd441d5 100644 --- a/src/geometry/translation_construction.rs +++ b/src/geometry/translation_construction.rs @@ -12,15 +12,13 @@ use rand::{ use simba::scalar::{ClosedAdd, SupersetOf}; -use crate::base::allocator::Allocator; -use crate::base::dimension::{DimName, U1, U2, U3, U4, U5, U6}; -use crate::base::{DefaultAllocator, Scalar, VectorN}; +use crate::base::{CVectorN, Scalar}; use crate::geometry::Translation; -impl Translation -where - DefaultAllocator: Allocator, +impl Translation +// where +// DefaultAllocator: Allocator, { /// Creates a new identity translation. /// @@ -41,7 +39,7 @@ where where N: Zero, { - Self::from(VectorN::::from_element(N::zero())) + Self::from(CVectorN::::from_element(N::zero())) } /// Cast the components of `self` to another type. @@ -56,15 +54,15 @@ where pub fn cast(self) -> Translation where Translation: SupersetOf, - DefaultAllocator: Allocator, + // DefaultAllocator: Allocator, { crate::convert(self) } } -impl One for Translation -where - DefaultAllocator: Allocator, +impl One for Translation +// where +// DefaultAllocator: Allocator, { #[inline] fn one() -> Self { @@ -73,27 +71,27 @@ where } #[cfg(feature = "rand-no-std")] -impl Distribution> for Standard +impl Distribution> for Standard where - DefaultAllocator: Allocator, + // DefaultAllocator: Allocator, Standard: Distribution, { /// Generate an arbitrary random variate for testing purposes. #[inline] fn sample<'a, G: Rng + ?Sized>(&self, rng: &'a mut G) -> Translation { - Translation::from(rng.gen::>()) + Translation::from(rng.gen::>()) } } #[cfg(feature = "arbitrary")] -impl Arbitrary for Translation +impl Arbitrary for Translation where - DefaultAllocator: Allocator, + // DefaultAllocator: Allocator, Owned: Send, { #[inline] fn arbitrary(rng: &mut Gen) -> Self { - let v: VectorN = Arbitrary::arbitrary(rng); + let v: CVectorN = Arbitrary::arbitrary(rng); Self::from(v) } } @@ -104,16 +102,17 @@ where * */ macro_rules! componentwise_constructors_impl( - ($($doc: expr; $D: ty, $($args: ident:$irow: expr),*);* $(;)*) => {$( + ($($doc: expr; $D: expr, $($args: ident:$irow: expr),*);* $(;)*) => {$( impl Translation - where DefaultAllocator: Allocator { + // where DefaultAllocator: Allocator + { #[doc = "Initializes this translation from its components."] #[doc = "# Example\n```"] #[doc = $doc] #[doc = "```"] #[inline] pub fn new($($args: N),*) -> Self { - Self::from(VectorN::::new($($args),*)) + Self::from(CVectorN::::new($($args),*)) } } )*} @@ -121,15 +120,15 @@ macro_rules! componentwise_constructors_impl( componentwise_constructors_impl!( "# use nalgebra::Translation1;\nlet t = Translation1::new(1.0);\nassert!(t.vector.x == 1.0);"; - U1, x:0; + 1, x:0; "# use nalgebra::Translation2;\nlet t = Translation2::new(1.0, 2.0);\nassert!(t.vector.x == 1.0 && t.vector.y == 2.0);"; - U2, x:0, y:1; + 2, x:0, y:1; "# use nalgebra::Translation3;\nlet t = Translation3::new(1.0, 2.0, 3.0);\nassert!(t.vector.x == 1.0 && t.vector.y == 2.0 && t.vector.z == 3.0);"; - U3, x:0, y:1, z:2; + 3, x:0, y:1, z:2; "# use nalgebra::Translation4;\nlet t = Translation4::new(1.0, 2.0, 3.0, 4.0);\nassert!(t.vector.x == 1.0 && t.vector.y == 2.0 && t.vector.z == 3.0 && t.vector.w == 4.0);"; - U4, x:0, y:1, z:2, w:3; + 4, x:0, y:1, z:2, w:3; "# use nalgebra::Translation5;\nlet t = Translation5::new(1.0, 2.0, 3.0, 4.0, 5.0);\nassert!(t.vector.x == 1.0 && t.vector.y == 2.0 && t.vector.z == 3.0 && t.vector.w == 4.0 && t.vector.a == 5.0);"; - U5, x:0, y:1, z:2, w:3, a:4; + 5, x:0, y:1, z:2, w:3, a:4; "# use nalgebra::Translation6;\nlet t = Translation6::new(1.0, 2.0, 3.0, 4.0, 5.0, 6.0);\nassert!(t.vector.x == 1.0 && t.vector.y == 2.0 && t.vector.z == 3.0 && t.vector.w == 4.0 && t.vector.a == 5.0 && t.vector.b == 6.0);"; - U6, x:0, y:1, z:2, w:3, a:4, b:5; + 6, x:0, y:1, z:2, w:3, a:4, b:5; ); diff --git a/src/geometry/translation_conversion.rs b/src/geometry/translation_conversion.rs index 9e915073..c49e2735 100644 --- a/src/geometry/translation_conversion.rs +++ b/src/geometry/translation_conversion.rs @@ -4,8 +4,8 @@ use simba::scalar::{RealField, SubsetOf, SupersetOf}; use simba::simd::PrimitiveSimdValue; use crate::base::allocator::Allocator; -use crate::base::dimension::{DimName, DimNameAdd, DimNameSum, U1}; -use crate::base::{DefaultAllocator, MatrixN, Scalar, VectorN}; +use crate::base::dimension::{DimNameAdd, DimNameSum, U1}; +use crate::base::{Const, DefaultAllocator, MatrixN, Scalar, VectorN}; use crate::geometry::{ AbstractRotation, Isometry, Similarity, SuperTCategoryOf, TAffine, Transform, Translation, @@ -24,11 +24,11 @@ use crate::geometry::{ * Translation -> Matrix (homogeneous) */ -impl SubsetOf> for Translation +impl SubsetOf> for Translation where N1: Scalar, N2: Scalar + SupersetOf, - DefaultAllocator: Allocator + Allocator, + // DefaultAllocator: Allocator + Allocator, { #[inline] fn to_superset(&self) -> Translation { @@ -48,25 +48,25 @@ where } } -impl SubsetOf> for Translation +impl SubsetOf> for Translation where N1: RealField, N2: RealField + SupersetOf, R: AbstractRotation, - DefaultAllocator: Allocator + Allocator, + // DefaultAllocator: Allocator + Allocator, { #[inline] - fn to_superset(&self) -> Isometry { + fn to_superset(&self) -> Isometry { Isometry::from_parts(self.to_superset(), R::identity()) } #[inline] - fn is_in_subset(iso: &Isometry) -> bool { + fn is_in_subset(iso: &Isometry) -> bool { iso.rotation == R::identity() } #[inline] - fn from_superset_unchecked(iso: &Isometry) -> Self { + fn from_superset_unchecked(iso: &Isometry) -> Self { Self::from_superset_unchecked(&iso.translation) } } @@ -95,96 +95,96 @@ where } } -impl SubsetOf> for Translation +impl SubsetOf> for Translation where N1: RealField, N2: RealField + SupersetOf, R: AbstractRotation, - DefaultAllocator: Allocator + Allocator, + // DefaultAllocator: Allocator + Allocator, { #[inline] - fn to_superset(&self) -> Similarity { + fn to_superset(&self) -> Similarity { Similarity::from_parts(self.to_superset(), R::identity(), N2::one()) } #[inline] - fn is_in_subset(sim: &Similarity) -> bool { + fn is_in_subset(sim: &Similarity) -> bool { sim.isometry.rotation == R::identity() && sim.scaling() == N2::one() } #[inline] - fn from_superset_unchecked(sim: &Similarity) -> Self { + fn from_superset_unchecked(sim: &Similarity) -> Self { Self::from_superset_unchecked(&sim.isometry.translation) } } -impl SubsetOf> for Translation +impl SubsetOf> for Translation where N1: RealField, N2: RealField + SupersetOf, C: SuperTCategoryOf, - D: DimNameAdd, - DefaultAllocator: Allocator - + Allocator - + Allocator, DimNameSum> - + Allocator, DimNameSum>, + Const: DimNameAdd, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>> + + Allocator, U1>, DimNameSum, U1>>, { #[inline] - fn to_superset(&self) -> Transform { + fn to_superset(&self) -> Transform { Transform::from_matrix_unchecked(self.to_homogeneous().to_superset()) } #[inline] - fn is_in_subset(t: &Transform) -> bool { + fn is_in_subset(t: &Transform) -> bool { >::is_in_subset(t.matrix()) } #[inline] - fn from_superset_unchecked(t: &Transform) -> Self { + fn from_superset_unchecked(t: &Transform) -> Self { Self::from_superset_unchecked(t.matrix()) } } -impl SubsetOf>> for Translation +impl SubsetOf, U1>>> for Translation where N1: RealField, N2: RealField + SupersetOf, - D: DimNameAdd, - DefaultAllocator: Allocator - + Allocator - + Allocator, DimNameSum> - + Allocator, DimNameSum>, + Const: DimNameAdd, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>> + + Allocator, U1>, DimNameSum, U1>>, + // + Allocator + // + Allocator { #[inline] - fn to_superset(&self) -> MatrixN> { + fn to_superset(&self) -> MatrixN, U1>> { self.to_homogeneous().to_superset() } #[inline] - fn is_in_subset(m: &MatrixN>) -> bool { - let id = m.fixed_slice::, D>(0, 0); + fn is_in_subset(m: &MatrixN, U1>>) -> bool { + let id = m.fixed_slice::, U1>, D>(0, 0); // Scalar types agree. m.iter().all(|e| SupersetOf::::is_in_subset(e)) && // The block part does nothing. id.is_identity(N2::zero()) && // The normalization factor is one. - m[(D::dim(), D::dim())] == N2::one() + m[(D, D)] == N2::one() } #[inline] - fn from_superset_unchecked(m: &MatrixN>) -> Self { - let t = m.fixed_slice::(0, D::dim()); + fn from_superset_unchecked(m: &MatrixN, U1>>) -> Self { + let t = m.fixed_slice::(0, D); Self { vector: crate::convert_unchecked(t.into_owned()), } } } -impl From> for MatrixN> +impl From> + for MatrixN, U1>> where - D: DimNameAdd, - DefaultAllocator: Allocator + Allocator, DimNameSum>, + Const: DimNameAdd, + DefaultAllocator: + Allocator, U1>, DimNameSum, U1>> + Allocator>, { #[inline] fn from(t: Translation) -> Self { @@ -192,22 +192,22 @@ where } } -impl From> for Translation -where - DefaultAllocator: Allocator, +impl From>> for Translation +// where +// DefaultAllocator: Allocator, { #[inline] - fn from(vector: VectorN) -> Self { + fn from(vector: VectorN>) -> Self { Translation { vector } } } -impl From<[Translation; 2]> +impl From<[Translation; 2]> for Translation where N: From<[::Element; 2]>, N::Element: Scalar, - DefaultAllocator: Allocator + Allocator, + // DefaultAllocator: Allocator + Allocator, { #[inline] fn from(arr: [Translation; 2]) -> Self { @@ -218,12 +218,12 @@ where } } -impl From<[Translation; 4]> +impl From<[Translation; 4]> for Translation where N: From<[::Element; 4]>, N::Element: Scalar, - DefaultAllocator: Allocator + Allocator, + // DefaultAllocator: Allocator + Allocator, { #[inline] fn from(arr: [Translation; 4]) -> Self { @@ -236,12 +236,12 @@ where } } -impl From<[Translation; 8]> +impl From<[Translation; 8]> for Translation where N: From<[::Element; 8]>, N::Element: Scalar, - DefaultAllocator: Allocator + Allocator, + // DefaultAllocator: Allocator + Allocator, { #[inline] fn from(arr: [Translation; 8]) -> Self { @@ -258,12 +258,12 @@ where } } -impl From<[Translation; 16]> +impl From<[Translation; 16]> for Translation where N: From<[::Element; 16]>, N::Element: Scalar, - DefaultAllocator: Allocator + Allocator, + // DefaultAllocator: Allocator + Allocator, { #[inline] fn from(arr: [Translation; 16]) -> Self { diff --git a/src/geometry/translation_coordinates.rs b/src/geometry/translation_coordinates.rs index c422415c..28d9bde2 100644 --- a/src/geometry/translation_coordinates.rs +++ b/src/geometry/translation_coordinates.rs @@ -1,10 +1,8 @@ use std::mem; use std::ops::{Deref, DerefMut}; -use crate::base::allocator::Allocator; use crate::base::coordinates::{X, XY, XYZ, XYZW, XYZWA, XYZWAB}; -use crate::base::dimension::{U1, U2, U3, U4, U5, U6}; -use crate::base::{DefaultAllocator, Scalar}; +use crate::base::Scalar; use crate::geometry::Translation; @@ -15,9 +13,10 @@ use crate::geometry::Translation; */ macro_rules! deref_impl( - ($D: ty, $Target: ident $(, $comps: ident)*) => { + ($D: expr, $Target: ident $(, $comps: ident)*) => { impl Deref for Translation - where DefaultAllocator: Allocator { + // where DefaultAllocator: Allocator + { type Target = $Target; #[inline] @@ -27,7 +26,8 @@ macro_rules! deref_impl( } impl DerefMut for Translation - where DefaultAllocator: Allocator { + // where DefaultAllocator: Allocator + { #[inline] fn deref_mut(&mut self) -> &mut Self::Target { unsafe { mem::transmute(self) } @@ -36,9 +36,9 @@ macro_rules! deref_impl( } ); -deref_impl!(U1, X, x); -deref_impl!(U2, XY, x, y); -deref_impl!(U3, XYZ, x, y, z); -deref_impl!(U4, XYZW, x, y, z, w); -deref_impl!(U5, XYZWA, x, y, z, w, a); -deref_impl!(U6, XYZWAB, x, y, z, w, a, b); +deref_impl!(1, X, x); +deref_impl!(2, XY, x, y); +deref_impl!(3, XYZ, x, y, z); +deref_impl!(4, XYZW, x, y, z, w); +deref_impl!(5, XYZWA, x, y, z, w, a); +deref_impl!(6, XYZWAB, x, y, z, w, a, b); diff --git a/src/geometry/translation_simba.rs b/src/geometry/translation_simba.rs index c439a5d2..6d96618f 100755 --- a/src/geometry/translation_simba.rs +++ b/src/geometry/translation_simba.rs @@ -1,16 +1,14 @@ use simba::simd::SimdValue; -use crate::base::allocator::Allocator; -use crate::base::dimension::DimName; -use crate::base::{DefaultAllocator, VectorN}; +use crate::base::VectorN; use crate::Scalar; use crate::geometry::Translation; -impl SimdValue for Translation +impl SimdValue for Translation where N::Element: Scalar, - DefaultAllocator: Allocator + Allocator, + // DefaultAllocator: Allocator + Allocator, { type Element = Translation; type SimdBool = N::SimdBool; diff --git a/src/geometry/unit_complex_conversion.rs b/src/geometry/unit_complex_conversion.rs index 91736764..f2c02b85 100644 --- a/src/geometry/unit_complex_conversion.rs +++ b/src/geometry/unit_complex_conversion.rs @@ -4,7 +4,6 @@ use num_complex::Complex; use simba::scalar::{RealField, SubsetOf, SupersetOf}; use simba::simd::{PrimitiveSimdValue, SimdRealField}; -use crate::base::dimension::U2; use crate::base::{Matrix2, Matrix3, Scalar}; use crate::geometry::{ AbstractRotation, Isometry, Rotation2, Similarity, SuperTCategoryOf, TAffine, Transform, @@ -17,9 +16,9 @@ use crate::geometry::{ * * UnitComplex -> UnitComplex * UnitComplex -> Rotation - * UnitComplex -> Isometry - * UnitComplex -> Similarity - * UnitComplex -> Transform + * UnitComplex -> Isometry<2> + * UnitComplex -> Similarity<2> + * UnitComplex -> Transform<2> * UnitComplex -> Matrix (homogeneous) * * NOTE: @@ -70,68 +69,68 @@ where } } -impl SubsetOf> for UnitComplex +impl SubsetOf> for UnitComplex where N1: RealField, N2: RealField + SupersetOf, - R: AbstractRotation + SupersetOf, + R: AbstractRotation + SupersetOf, { #[inline] - fn to_superset(&self) -> Isometry { + fn to_superset(&self) -> Isometry { Isometry::from_parts(Translation::identity(), crate::convert_ref(self)) } #[inline] - fn is_in_subset(iso: &Isometry) -> bool { + fn is_in_subset(iso: &Isometry) -> bool { iso.translation.vector.is_zero() } #[inline] - fn from_superset_unchecked(iso: &Isometry) -> Self { + fn from_superset_unchecked(iso: &Isometry) -> Self { crate::convert_ref_unchecked(&iso.rotation) } } -impl SubsetOf> for UnitComplex +impl SubsetOf> for UnitComplex where N1: RealField, N2: RealField + SupersetOf, - R: AbstractRotation + SupersetOf, + R: AbstractRotation + SupersetOf, { #[inline] - fn to_superset(&self) -> Similarity { + fn to_superset(&self) -> Similarity { Similarity::from_isometry(crate::convert_ref(self), N2::one()) } #[inline] - fn is_in_subset(sim: &Similarity) -> bool { + fn is_in_subset(sim: &Similarity) -> bool { sim.isometry.translation.vector.is_zero() && sim.scaling() == N2::one() } #[inline] - fn from_superset_unchecked(sim: &Similarity) -> Self { + fn from_superset_unchecked(sim: &Similarity) -> Self { crate::convert_ref_unchecked(&sim.isometry) } } -impl SubsetOf> for UnitComplex +impl SubsetOf> for UnitComplex where N1: RealField, N2: RealField + SupersetOf, C: SuperTCategoryOf, { #[inline] - fn to_superset(&self) -> Transform { + fn to_superset(&self) -> Transform { Transform::from_matrix_unchecked(self.to_homogeneous().to_superset()) } #[inline] - fn is_in_subset(t: &Transform) -> bool { + fn is_in_subset(t: &Transform) -> bool { >::is_in_subset(t.matrix()) } #[inline] - fn from_superset_unchecked(t: &Transform) -> Self { + fn from_superset_unchecked(t: &Transform) -> Self { Self::from_superset_unchecked(t.matrix()) } } diff --git a/src/lib.rs b/src/lib.rs index 8f70b340..a64182be 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -384,9 +384,12 @@ pub fn partial_sort2<'a, T: PartialOrd>(a: &'a T, b: &'a T) -> Option<(&'a T, &' /// * [distance](fn.distance.html) /// * [distance_squared](fn.distance_squared.html) #[inline] -pub fn center(p1: &Point, p2: &Point) -> Point -where - DefaultAllocator: Allocator, +pub fn center( + p1: &Point, + p2: &Point, +) -> Point +// where +// DefaultAllocator: Allocator, { ((&p1.coords + &p2.coords) * convert::<_, N>(0.5)).into() } @@ -398,12 +401,12 @@ where /// * [center](fn.center.html) /// * [distance_squared](fn.distance_squared.html) #[inline] -pub fn distance( +pub fn distance( p1: &Point, p2: &Point, ) -> N::SimdRealField -where - DefaultAllocator: Allocator, +// where +// DefaultAllocator: Allocator, { (&p2.coords - &p1.coords).norm() } @@ -415,12 +418,12 @@ where /// * [center](fn.center.html) /// * [distance](fn.distance.html) #[inline] -pub fn distance_squared( +pub fn distance_squared( p1: &Point, p2: &Point, ) -> N::SimdRealField -where - DefaultAllocator: Allocator, +// where +// DefaultAllocator: Allocator, { (&p2.coords - &p1.coords).norm_squared() }