diff --git a/src/geometry/dual_quaternion_ops.rs b/src/geometry/dual_quaternion_ops.rs index 26a9f09f..46bc22b5 100644 --- a/src/geometry/dual_quaternion_ops.rs +++ b/src/geometry/dual_quaternion_ops.rs @@ -46,9 +46,8 @@ use crate::base::storage::Storage; use crate::{ - Allocator, DefaultAllocator, DualQuaternion, Isometry3, Point, Point3, Quaternion, - SimdRealField, Translation3, Unit, UnitDualQuaternion, UnitQuaternion, Vector, Vector3, U1, U3, - U4, + DualQuaternion, Isometry3, Point, Point3, Quaternion, SimdRealField, Translation3, Unit, + UnitDualQuaternion, UnitQuaternion, Vector, Vector3, U3, }; use std::mem; use std::ops::{ @@ -140,9 +139,7 @@ macro_rules! dual_quaternion_op_impl( $lhs: ident: $Lhs: ty, $rhs: ident: $Rhs: ty, Output = $Result: ty $(=> $VDimA: ty, $VDimB: ty)*; $action: expr; $($lives: tt),*) => { impl<$($lives ,)* T: SimdRealField $(, $Storage: $StoragesBound $(<$($BoundParam),*>)*)*> $Op<$Rhs> for $Lhs - where T::Element: SimdRealField, - DefaultAllocator: Allocator + - Allocator { + where T::Element: SimdRealField, { type Output = $Result; #[inline] @@ -963,9 +960,7 @@ macro_rules! dual_quaternion_op_impl( $lhs: ident: $Lhs: ty, $rhs: ident: $Rhs: ty $(=> $VDimA: ty, $VDimB: ty)*; $action: expr; $($lives: tt),*) => { impl<$($lives ,)* T: SimdRealField> $OpAssign<$Rhs> for $Lhs - where T::Element: SimdRealField, - DefaultAllocator: Allocator + - Allocator { + where T::Element: SimdRealField { #[inline] fn $op_assign(&mut $lhs, $rhs: $Rhs) { diff --git a/src/geometry/isometry_ops.rs b/src/geometry/isometry_ops.rs index 9d6928a2..2e6477b5 100644 --- a/src/geometry/isometry_ops.rs +++ b/src/geometry/isometry_ops.rs @@ -4,9 +4,7 @@ use std::ops::{Div, DivAssign, Mul, MulAssign}; use simba::scalar::{ClosedAdd, ClosedMul}; use simba::simd::SimdRealField; -use crate::base::allocator::Allocator; -use crate::base::dimension::{U1, U2, U3}; -use crate::base::{Const, DefaultAllocator, SVector, Unit}; +use crate::base::{SVector, Unit}; use crate::Scalar; use crate::geometry::{ diff --git a/src/geometry/op_macros.rs b/src/geometry/op_macros.rs index 08c00870..a4775d2a 100644 --- a/src/geometry/op_macros.rs +++ b/src/geometry/op_macros.rs @@ -22,9 +22,6 @@ macro_rules! md_impl( $($lives: tt),*) => { impl<$($lives ,)* T $(, $DimsDecl)* $(, const $D: usize)*> $Op<$Rhs> for $Lhs where T: Scalar + Zero + One + ClosedAdd + ClosedMul $($(+ $ScalarBounds)*)*, - DefaultAllocator: Allocator + - Allocator + - Allocator, $( $ConstraintType: $ConstraintBound$(<$( $ConstraintBoundParams $( = $EqBound )*),*>)* ),* { type Output = $Result; @@ -117,8 +114,6 @@ macro_rules! md_assign_impl( impl<$($lives ,)* T $(, $DimsDecl)* $(, const $D: usize)*> $Op<$Rhs> for $Lhs where T: Scalar + Zero + One + ClosedAdd + ClosedMul $($(+ $ScalarBounds)*)*, $($(T::Element: $ElementBounds,)*)* - DefaultAllocator: Allocator + - Allocator, $( $ConstraintType: $ConstraintBound $(<$( $ConstraintBoundParams $( = $EqBound )*),*>)* ),* { #[inline] @@ -172,7 +167,7 @@ macro_rules! md_assign_impl_all( /// Macro for the implementation of addition and subtraction. macro_rules! add_sub_impl( ($Op: ident, $op: ident, $bound: ident; - ($R1: ty, $C1: ty),($R2: ty, $C2: ty) $(-> ($RRes: ty))* + ($R1: ty, $C1: ty),($R2: ty, $C2: ty) $(-> ($RRes: ty, $CRes: ty))* // Const type declaration const $($D: ident),*; // Other generic type declarations. @@ -183,11 +178,8 @@ macro_rules! add_sub_impl( $action: expr; $($lives: tt),*) => { impl<$($lives ,)* T $(, $DimsDecl)* $(, const $D: usize)*> $Op<$Rhs> for $Lhs where T: Scalar + $bound, - DefaultAllocator: Allocator + - Allocator + - SameShapeAllocator, ShapeConstraint: SameNumberOfRows<$R1, $R2 $(, Representative = $RRes)*> + - SameNumberOfColumns<$C1, $C2>, + SameNumberOfColumns<$C1, $C2 $(, Representative = $CRes)*>, $( $ConstraintType: $ConstraintBound$(<$( $ConstraintBoundParams $( = $EqBound )*),*>)* ),* { type Output = $Result; diff --git a/src/geometry/point.rs b/src/geometry/point.rs index e5dcbc25..33725250 100644 --- a/src/geometry/point.rs +++ b/src/geometry/point.rs @@ -17,7 +17,7 @@ use simba::simd::SimdPartialOrd; use crate::base::allocator::Allocator; use crate::base::dimension::{DimName, DimNameAdd, DimNameSum, U1}; use crate::base::iter::{MatrixIter, MatrixIterMut}; -use crate::base::{Const, DefaultAllocator, OVector, Scalar}; +use crate::base::{Const, DefaultAllocator, OVector, SVector, Scalar}; /// A point in an euclidean space. /// @@ -40,9 +40,9 @@ use crate::base::{Const, DefaultAllocator, OVector, Scalar}; /// of said transformations for details. #[repr(C)] #[derive(Debug, Clone)] -pub struct Point { +pub struct Point { /// The coordinates of this point, i.e., the shift from the origin. - pub coords: OVector>, + pub coords: SVector, } impl hash::Hash for Point { @@ -55,7 +55,7 @@ impl Copy for Point {} #[cfg(feature = "bytemuck")] unsafe impl bytemuck::Zeroable for Point where - OVector>: bytemuck::Zeroable + SVector: bytemuck::Zeroable { } @@ -63,7 +63,7 @@ unsafe impl bytemuck::Zeroable for Point where unsafe impl bytemuck::Pod for Point where T: Copy, - OVector>: bytemuck::Pod, + SVector: bytemuck::Pod, { } @@ -83,7 +83,6 @@ impl<'a, T: Scalar + Deserialize<'a>, const D: usize> Deserialize<'a> for Point< where Des: Deserializer<'a>, { - use crate::SVector; let coords = SVector::::deserialize(deserializer)?; Ok(Self::from(coords)) @@ -94,7 +93,7 @@ impl<'a, T: Scalar + Deserialize<'a>, const D: usize> Deserialize<'a> for Point< impl Abomonation for Point where T: Scalar, - OVector>: Abomonation, + SVector: Abomonation, { unsafe fn entomb(&self, writer: &mut W) -> IOResult<()> { self.coords.entomb(writer) @@ -183,7 +182,7 @@ impl Point { /// Creates a new point with the given coordinates. #[deprecated(note = "Use Point::from(vector) instead.")] #[inline] - pub fn from_coordinates(coords: OVector>) -> Self { + pub fn from_coordinates(coords: SVector) -> Self { Self { coords } } diff --git a/src/geometry/point_construction.rs b/src/geometry/point_construction.rs index 3f52d950..f50a3fc1 100644 --- a/src/geometry/point_construction.rs +++ b/src/geometry/point_construction.rs @@ -181,7 +181,7 @@ where // NOTE: the impl for Point1 is not with the others so that we // can add a section with the impl block comment. /// # Construction from individual components -impl Point1 { +impl Point1 { /// Initializes this point from its components. /// /// # Example @@ -192,20 +192,22 @@ impl Point1 { /// assert_eq!(p.x, 1.0); /// ``` #[inline] - pub fn new(x: T) -> Self { - Vector1::new(x).into() + pub const fn new(x: T) -> Self { + Point { + coords: Vector1::new(x), + } } } macro_rules! componentwise_constructors_impl( ($($doc: expr; $Point: ident, $Vector: ident, $($args: ident:$irow: expr),*);* $(;)*) => {$( - impl $Point { + impl $Point { #[doc = "Initializes this point from its components."] #[doc = "# Example\n```"] #[doc = $doc] #[doc = "```"] #[inline] - pub fn new($($args: T),*) -> Self { - $Vector::new($($args),*).into() + pub const fn new($($args: T),*) -> Self { + Point { coords: $Vector::new($($args),*) } } } )*} diff --git a/src/geometry/point_ops.rs b/src/geometry/point_ops.rs index d1054364..576028cc 100644 --- a/src/geometry/point_ops.rs +++ b/src/geometry/point_ops.rs @@ -5,13 +5,12 @@ use std::ops::{ use simba::scalar::{ClosedAdd, ClosedDiv, ClosedMul, ClosedNeg, ClosedSub}; -use crate::base::allocator::{Allocator, SameShapeAllocator}; use crate::base::constraint::{ AreMultipliable, SameNumberOfColumns, SameNumberOfRows, ShapeConstraint, }; use crate::base::dimension::{Dim, U1}; use crate::base::storage::Storage; -use crate::base::{Const, DefaultAllocator, Matrix, Scalar, Vector, VectorSum}; +use crate::base::{Const, Matrix, SVector, Scalar, Vector}; use crate::geometry::Point; @@ -67,32 +66,32 @@ impl<'a, T: Scalar + ClosedNeg, const D: usize> Neg for &'a Point { // Point - Point add_sub_impl!(Sub, sub, ClosedSub; - (Const, U1), (Const, U1) + (Const, U1), (Const, U1) -> (Const, U1) const D; for; where; - self: &'a Point, right: &'b Point, Output = VectorSum, Const>; + self: &'a Point, right: &'b Point, Output = SVector; &self.coords - &right.coords; 'a, 'b); add_sub_impl!(Sub, sub, ClosedSub; - (Const, U1), (Const, U1) + (Const, U1), (Const, U1) -> (Const, U1) const D; for; where; - self: &'a Point, right: Point, Output = VectorSum, Const>; + self: &'a Point, right: Point, Output = SVector; &self.coords - right.coords; 'a); add_sub_impl!(Sub, sub, ClosedSub; - (Const, U1), (Const, U1) + (Const, U1), (Const, U1) -> (Const, U1) const D; for; where; - self: Point, right: &'b Point, Output = VectorSum, Const>; + self: Point, right: &'b Point, Output = SVector; self.coords - &right.coords; 'b); add_sub_impl!(Sub, sub, ClosedSub; - (Const, U1), (Const, U1) + (Const, U1), (Const, U1) -> (Const, U1) const D; for; where; - self: Point, right: Point, Output = VectorSum, Const>; + self: Point, right: Point, Output = SVector; self.coords - right.coords; ); // Point - Vector add_sub_impl!(Sub, sub, ClosedSub; - (Const, U1), (D2, U1) -> (Const) + (Const, U1), (D2, U1) -> (Const, U1) const D1; for D2, SB; where D2: Dim, SB: Storage; @@ -100,7 +99,7 @@ add_sub_impl!(Sub, sub, ClosedSub; Self::Output::from(&self.coords - right); 'a, 'b); add_sub_impl!(Sub, sub, ClosedSub; - (Const, U1), (D2, U1) -> (Const) + (Const, U1), (D2, U1) -> (Const, U1) const D1; for D2, SB; where D2: Dim, SB: Storage; @@ -108,7 +107,7 @@ add_sub_impl!(Sub, sub, ClosedSub; Self::Output::from(&self.coords - &right); 'a); // TODO: should not be a ref to `right`. add_sub_impl!(Sub, sub, ClosedSub; - (Const, U1), (D2, U1) -> (Const) + (Const, U1), (D2, U1) -> (Const, U1) const D1; for D2, SB; where D2: Dim, SB: Storage; @@ -116,7 +115,7 @@ add_sub_impl!(Sub, sub, ClosedSub; Self::Output::from(self.coords - right); 'b); add_sub_impl!(Sub, sub, ClosedSub; - (Const, U1), (D2, U1) -> (Const) + (Const, U1), (D2, U1) -> (Const, U1) const D1; for D2, SB; where D2: Dim, SB: Storage; @@ -125,7 +124,7 @@ add_sub_impl!(Sub, sub, ClosedSub; // Point + Vector add_sub_impl!(Add, add, ClosedAdd; - (Const, U1), (D2, U1) -> (Const) + (Const, U1), (D2, U1) -> (Const, U1) const D1; for D2, SB; where D2: Dim, SB: Storage; @@ -133,7 +132,7 @@ add_sub_impl!(Add, add, ClosedAdd; Self::Output::from(&self.coords + right); 'a, 'b); add_sub_impl!(Add, add, ClosedAdd; - (Const, U1), (D2, U1) -> (Const) + (Const, U1), (D2, U1) -> (Const, U1) const D1; for D2, SB; where D2: Dim, SB: Storage; @@ -141,7 +140,7 @@ add_sub_impl!(Add, add, ClosedAdd; Self::Output::from(&self.coords + &right); 'a); // TODO: should not be a ref to `right`. add_sub_impl!(Add, add, ClosedAdd; - (Const, U1), (D2, U1) -> (Const) + (Const, U1), (D2, U1) -> (Const, U1) const D1; for D2, SB; where D2: Dim, SB: Storage; @@ -149,7 +148,7 @@ add_sub_impl!(Add, add, ClosedAdd; Self::Output::from(self.coords + right); 'b); add_sub_impl!(Add, add, ClosedAdd; - (Const, U1), (D2, U1) -> (Const) + (Const, U1), (D2, U1) -> (Const, U1) const D1; for D2, SB; where D2: Dim, SB: Storage; diff --git a/src/geometry/quaternion.rs b/src/geometry/quaternion.rs index 3a51d299..6d45057f 100755 --- a/src/geometry/quaternion.rs +++ b/src/geometry/quaternion.rs @@ -1,6 +1,7 @@ use approx::{AbsDiffEq, RelativeEq, UlpsEq}; use num::Zero; use std::fmt; +use std::hash::{Hash, Hasher}; #[cfg(feature = "abomonation-serialize")] use std::io::{Result as IOResult, Write}; @@ -26,12 +27,27 @@ use crate::geometry::{Point3, Rotation}; /// A quaternion. See the type alias `UnitQuaternion = Unit` for a quaternion /// that may be used as a rotation. #[repr(C)] -#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] -pub struct Quaternion { +#[derive(Debug, Copy, Clone)] +pub struct Quaternion { /// This quaternion as a 4D vector of coordinates in the `[ x, y, z, w ]` storage order. pub coords: Vector4, } +impl Hash for Quaternion { + fn hash(&self, state: &mut H) { + self.coords.hash(state) + } +} + +impl Eq for Quaternion {} + +impl PartialEq for Quaternion { + #[inline] + fn eq(&self, right: &Self) -> bool { + self.coords == right.coords + } +} + impl Default for Quaternion { fn default() -> Self { Quaternion { diff --git a/src/geometry/quaternion_construction.rs b/src/geometry/quaternion_construction.rs index a3b113d2..f110e3dd 100644 --- a/src/geometry/quaternion_construction.rs +++ b/src/geometry/quaternion_construction.rs @@ -23,12 +23,12 @@ use crate::{Scalar, SimdRealField}; use crate::geometry::{Quaternion, Rotation3, UnitQuaternion}; -impl Quaternion { +impl Quaternion { /// Creates a quaternion from a 4D vector. The quaternion scalar part corresponds to the `w` /// vector component. #[inline] - #[deprecated(note = "Use `::from` instead.")] - pub fn from_vector(vector: Vector4) -> Self { + // #[deprecated(note = "Use `::from` instead.")] // Don't deprecate because this one can be a const-fn. + pub const fn from_vector(vector: Vector4) -> Self { Self { coords: vector } } @@ -46,8 +46,8 @@ impl Quaternion { /// assert_eq!(*q.as_vector(), Vector4::new(2.0, 3.0, 4.0, 1.0)); /// ``` #[inline] - pub fn new(w: T, i: T, j: T, k: T) -> Self { - Self::from(Vector4::new(i, j, k, w)) + pub const fn new(w: T, i: T, j: T, k: T) -> Self { + Self::from_vector(Vector4::new(i, j, k, w)) } /// Cast the components of `self` to another type. @@ -61,6 +61,7 @@ impl Quaternion { /// ``` pub fn cast(self) -> Quaternion where + T: Scalar, To: SupersetOf, { crate::convert(self) diff --git a/src/geometry/similarity_ops.rs b/src/geometry/similarity_ops.rs index 65b8b4a5..c164acaa 100644 --- a/src/geometry/similarity_ops.rs +++ b/src/geometry/similarity_ops.rs @@ -4,9 +4,7 @@ use std::ops::{Div, DivAssign, Mul, MulAssign}; use simba::scalar::{ClosedAdd, ClosedMul}; use simba::simd::SimdRealField; -use crate::base::allocator::Allocator; -use crate::base::dimension::{U1, U2, U3}; -use crate::base::{Const, DefaultAllocator, SVector, Scalar}; +use crate::base::{SVector, Scalar}; use crate::geometry::{ AbstractRotation, Isometry, Point, Rotation, Similarity, Translation, UnitComplex, diff --git a/src/geometry/transform_ops.rs b/src/geometry/transform_ops.rs index ceefd280..29781c3c 100644 --- a/src/geometry/transform_ops.rs +++ b/src/geometry/transform_ops.rs @@ -4,7 +4,7 @@ use std::ops::{Div, DivAssign, Index, IndexMut, Mul, MulAssign}; use simba::scalar::{ClosedAdd, ClosedMul, RealField, SubsetOf}; use crate::base::allocator::Allocator; -use crate::base::dimension::{DimNameAdd, DimNameSum, U1, U4}; +use crate::base::dimension::{DimNameAdd, DimNameSum, U1}; use crate::base::{Const, DefaultAllocator, OMatrix, SVector, Scalar}; use crate::geometry::{ @@ -110,7 +110,8 @@ md_impl_all!( (DimNameSum, U1>, DimNameSum, U1>), (Const, U1) const D; for C; - where Const: DimNameAdd, C: TCategory; + where Const: DimNameAdd, C: TCategory, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>>; self: Transform, rhs: SVector, Output = SVector; [val val] => &self * &rhs; [ref val] => self * &rhs; @@ -137,7 +138,8 @@ md_impl_all!( (DimNameSum, U1>, DimNameSum, U1>), (Const, U1) const D; for C; - where Const: DimNameAdd, C: TCategory; + where Const: DimNameAdd, C: TCategory, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>>; self: Transform, rhs: Point, Output = Point; [val val] => &self * &rhs; [ref val] => self * &rhs; @@ -166,7 +168,8 @@ md_impl_all!( (DimNameSum, U1>, DimNameSum, U1>), (DimNameSum, U1>, DimNameSum, U1>) const D; for CA, CB; - where Const: DimNameAdd, CA: TCategoryMul, CB: TCategory; + where Const: DimNameAdd, CA: TCategoryMul, CB: TCategory, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>>; self: Transform, rhs: Transform, Output = Transform; [val val] => Self::Output::from_matrix_unchecked(self.into_inner() * rhs.into_inner()); [ref val] => Self::Output::from_matrix_unchecked(self.matrix() * rhs.into_inner()); @@ -176,11 +179,13 @@ md_impl_all!( // Transform × Rotation md_impl_all!( - Mul, mul where T: RealField; + Mul, mul + where T: RealField; (DimNameSum, U1>, DimNameSum, U1>), (Const, Const) const D; for C; - where Const: DimNameAdd, C: TCategoryMul; + where Const: DimNameAdd, C: TCategoryMul, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>>; 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()); @@ -194,7 +199,8 @@ md_impl_all!( (Const, Const), (DimNameSum, U1>, DimNameSum, U1>) const D; for C; - where Const: DimNameAdd, C: TCategoryMul; + where Const: DimNameAdd, C: TCategoryMul, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>>; 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()); @@ -236,7 +242,8 @@ md_impl_all!( (DimNameSum, U1>, DimNameSum, U1>), (Const, U1) const D; for C, R; - where Const: DimNameAdd, C: TCategoryMul, R: SubsetOf, U1>, DimNameSum, U1>> >; + where Const: DimNameAdd, C: TCategoryMul, R: SubsetOf, U1>, DimNameSum, U1>> >, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>>; 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()); @@ -250,7 +257,8 @@ md_impl_all!( (Const, U1), (DimNameSum, U1>, DimNameSum, U1>) const D; for C, R; - where Const: DimNameAdd, C: TCategoryMul, R: SubsetOf, U1>, DimNameSum, U1>> >; + where Const: DimNameAdd, C: TCategoryMul, R: SubsetOf, U1>, DimNameSum, U1>> >, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>>; 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()); @@ -264,7 +272,8 @@ md_impl_all!( (DimNameSum, U1>, DimNameSum, U1>), (Const, U1) const D; for C, R; - where Const: DimNameAdd, C: TCategoryMul, R: SubsetOf, U1>, DimNameSum, U1>> >; + where Const: DimNameAdd, C: TCategoryMul, R: SubsetOf, U1>, DimNameSum, U1>> >, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>>; 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()); @@ -278,7 +287,8 @@ md_impl_all!( (Const, U1), (DimNameSum, U1>, DimNameSum, U1>) const D; for C, R; - where Const: DimNameAdd, C: TCategoryMul, R: SubsetOf, U1>, DimNameSum, U1>> >; + where Const: DimNameAdd, C: TCategoryMul, R: SubsetOf, U1>, DimNameSum, U1>> >, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>>; 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()); @@ -300,7 +310,8 @@ md_impl_all!( (DimNameSum, U1>, DimNameSum, U1>), (Const, U1) const D; for C; - where Const: DimNameAdd, C: TCategoryMul; + where Const: DimNameAdd, C: TCategoryMul, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>>; 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()); @@ -314,7 +325,8 @@ md_impl_all!( (Const, U1), (DimNameSum, U1>, DimNameSum, U1>) const D; for C; - where Const: DimNameAdd, C: TCategoryMul; + where Const: DimNameAdd, C: TCategoryMul, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>>; 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()); @@ -328,7 +340,8 @@ md_impl_all!( (DimNameSum, U1>, DimNameSum, U1>), (DimNameSum, U1>, DimNameSum, U1>) const D; for CA, CB; - where Const: DimNameAdd, CA: TCategoryMul, CB: SubTCategoryOf; + where Const: DimNameAdd, CA: TCategoryMul, CB: SubTCategoryOf, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>>; self: Transform, rhs: Transform, Output = Transform; [val val] => #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.inverse() }; [ref val] => #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.inverse() }; @@ -342,7 +355,8 @@ md_impl_all!( (DimNameSum, U1>, DimNameSum, U1>), (Const, Const) const D; for C; - where Const: DimNameAdd, C: TCategoryMul; + where Const: DimNameAdd, C: TCategoryMul, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>>; 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() }; @@ -356,7 +370,8 @@ md_impl_all!( (Const, Const), (DimNameSum, U1>, DimNameSum, U1>) const D; for C; - where Const: DimNameAdd, C: TCategoryMul; + where Const: DimNameAdd, C: TCategoryMul, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>>; 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 }; @@ -452,7 +467,8 @@ md_impl_all!( (DimNameSum, U1>, DimNameSum, U1>), (Const, U1) const D; for C; - where Const: DimNameAdd, C: TCategoryMul; + where Const: DimNameAdd, C: TCategoryMul, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>>; 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() }; @@ -466,7 +482,8 @@ md_impl_all!( (Const, U1), (DimNameSum, U1>, DimNameSum, U1>) const D; for C; - where Const: DimNameAdd, C: TCategoryMul; + where Const: DimNameAdd, C: TCategoryMul, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>>; 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 }; @@ -480,7 +497,8 @@ md_assign_impl_all!( (DimNameSum, U1>, DimNameSum, U1>), (DimNameSum, U1>, DimNameSum, U1>) const D; for CA, CB; - where Const: DimNameAdd, CA: TCategory, CB: SubTCategoryOf; + where Const: DimNameAdd, CA: TCategory, CB: SubTCategoryOf, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>>; self: Transform, rhs: Transform; [val] => *self.matrix_mut_unchecked() *= rhs.into_inner(); [ref] => *self.matrix_mut_unchecked() *= rhs.matrix(); @@ -492,7 +510,8 @@ md_assign_impl_all!( (DimNameSum, U1>, DimNameSum, U1>), (Const, U1) const D; for C, R; - where Const: DimNameAdd, C: TCategory, R: SubsetOf, U1>, DimNameSum, U1>> >; + where Const: DimNameAdd, C: TCategory, R: SubsetOf, U1>, DimNameSum, U1>> >, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>>; self: Transform, rhs: Similarity; [val] => *self.matrix_mut_unchecked() *= rhs.to_homogeneous(); [ref] => *self.matrix_mut_unchecked() *= rhs.to_homogeneous(); @@ -504,7 +523,8 @@ md_assign_impl_all!( (DimNameSum, U1>, DimNameSum, U1>), (Const, U1) const D; for C, R; - where Const: DimNameAdd, C: TCategory, R: SubsetOf, U1>, DimNameSum, U1>> >; + where Const: DimNameAdd, C: TCategory, R: SubsetOf, U1>, DimNameSum, U1>> >, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>>; self: Transform, rhs: Isometry; [val] => *self.matrix_mut_unchecked() *= rhs.to_homogeneous(); [ref] => *self.matrix_mut_unchecked() *= rhs.to_homogeneous(); @@ -524,7 +544,8 @@ md_assign_impl_all!( (DimNameSum, U1>, DimNameSum, U1>), (Const, U1) const D; for C; - where Const: DimNameAdd, C: TCategory; + where Const: DimNameAdd, C: TCategory, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>>; self: Transform, rhs: Translation; [val] => *self.matrix_mut_unchecked() *= rhs.to_homogeneous(); [ref] => *self.matrix_mut_unchecked() *= rhs.to_homogeneous(); @@ -536,7 +557,8 @@ md_assign_impl_all!( (DimNameSum, U1>, DimNameSum, U1>), (Const, Const) const D; for C; - where Const: DimNameAdd, C: TCategory; + where Const: DimNameAdd, C: TCategory, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>>; self: Transform, rhs: Rotation; [val] => *self.matrix_mut_unchecked() *= rhs.to_homogeneous(); [ref] => *self.matrix_mut_unchecked() *= rhs.to_homogeneous(); @@ -560,7 +582,8 @@ md_assign_impl_all!( (DimNameSum, U1>, DimNameSum, U1>), (DimNameSum, U1>, DimNameSum, U1>) const D; for CA, CB; - where Const: DimNameAdd, CA: SuperTCategoryOf, CB: SubTCategoryOf; + where Const: DimNameAdd, CA: SuperTCategoryOf, CB: SubTCategoryOf, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>>; self: Transform, rhs: Transform; [val] => #[allow(clippy::suspicious_op_assign_impl)] { *self *= rhs.inverse() }; [ref] => #[allow(clippy::suspicious_op_assign_impl)] { *self *= rhs.clone().inverse() }; @@ -593,7 +616,8 @@ md_assign_impl_all!( (DimNameSum, U1>, DimNameSum, U1>), (Const, U1) const D; for C; - where Const: DimNameAdd, C: TCategory; + where Const: DimNameAdd, C: TCategory, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>>; self: Transform, rhs: Translation; [val] => #[allow(clippy::suspicious_op_assign_impl)] { *self *= rhs.inverse() }; [ref] => #[allow(clippy::suspicious_op_assign_impl)] { *self *= rhs.inverse() }; @@ -605,7 +629,8 @@ md_assign_impl_all!( (DimNameSum, U1>, DimNameSum, U1>), (Const, Const) const D; for C; - where Const: DimNameAdd, C: TCategory; + where Const: DimNameAdd, C: TCategory, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>>; self: Transform, rhs: Rotation; [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/translation.rs b/src/geometry/translation.rs index 6f6f0de1..5a4fe357 100755 --- a/src/geometry/translation.rs +++ b/src/geometry/translation.rs @@ -23,7 +23,7 @@ use crate::geometry::Point; /// A translation. #[repr(C)] #[derive(Debug)] -pub struct Translation { +pub struct Translation { /// The translation coordinates, i.e., how much is added to a point's coordinates when it is /// translated. pub vector: SVector, diff --git a/src/geometry/translation_construction.rs b/src/geometry/translation_construction.rs index ca87d389..c6e9d7d3 100644 --- a/src/geometry/translation_construction.rs +++ b/src/geometry/translation_construction.rs @@ -93,15 +93,15 @@ where */ macro_rules! componentwise_constructors_impl( ($($doc: expr; $D: expr, $($args: ident:$irow: expr),*);* $(;)*) => {$( - impl Translation + impl Translation { #[doc = "Initializes this translation from its components."] #[doc = "# Example\n```"] #[doc = $doc] #[doc = "```"] #[inline] - pub fn new($($args: T),*) -> Self { - Self::from(SVector::::new($($args),*)) + pub const fn new($($args: T),*) -> Self { + Self { vector: SVector::::new($($args),*) } } } )*} diff --git a/src/geometry/translation_ops.rs b/src/geometry/translation_ops.rs index 5944fdeb..8851183a 100644 --- a/src/geometry/translation_ops.rs +++ b/src/geometry/translation_ops.rs @@ -2,37 +2,36 @@ use std::ops::{Div, DivAssign, Mul, MulAssign}; use simba::scalar::{ClosedAdd, ClosedSub}; -use crate::base::allocator::{Allocator, SameShapeAllocator}; use crate::base::constraint::{SameNumberOfColumns, SameNumberOfRows, ShapeConstraint}; use crate::base::dimension::U1; -use crate::base::{Const, DefaultAllocator, Scalar}; +use crate::base::{Const, Scalar}; use crate::geometry::{Point, Translation}; // Translation × Translation add_sub_impl!(Mul, mul, ClosedAdd; - (Const, U1), (Const, U1) -> (Const) + (Const, U1), (Const, U1) -> (Const, U1) const D; for; where; self: &'a Translation, right: &'b Translation, Output = Translation; #[allow(clippy::suspicious_arithmetic_impl)] { Translation::from(&self.vector + &right.vector) }; 'a, 'b); add_sub_impl!(Mul, mul, ClosedAdd; - (Const, U1), (Const, U1) -> (Const) + (Const, U1), (Const, U1) -> (Const, U1) const D; for; where; self: &'a Translation, right: Translation, Output = Translation; #[allow(clippy::suspicious_arithmetic_impl)] { Translation::from(&self.vector + right.vector) }; 'a); add_sub_impl!(Mul, mul, ClosedAdd; - (Const, U1), (Const, U1) -> (Const) + (Const, U1), (Const, U1) -> (Const, U1) const D; for; where; self: Translation, right: &'b Translation, Output = Translation; #[allow(clippy::suspicious_arithmetic_impl)] { Translation::from(self.vector + &right.vector) }; 'b); add_sub_impl!(Mul, mul, ClosedAdd; - (Const, U1), (Const, U1) -> (Const) + (Const, U1), (Const, U1) -> (Const, U1) const D; for; where; self: Translation, right: Translation, Output = Translation; #[allow(clippy::suspicious_arithmetic_impl)] { Translation::from(self.vector + right.vector) }; ); @@ -40,28 +39,28 @@ add_sub_impl!(Mul, mul, ClosedAdd; // Translation ÷ Translation // TODO: instead of calling inverse explicitly, could we just add a `mul_tr` or `mul_inv` method? add_sub_impl!(Div, div, ClosedSub; - (Const, U1), (Const, U1) -> (Const) + (Const, U1), (Const, U1) -> (Const, U1) const D; for; where; self: &'a Translation, right: &'b Translation, Output = Translation; #[allow(clippy::suspicious_arithmetic_impl)] { Translation::from(&self.vector - &right.vector) }; 'a, 'b); add_sub_impl!(Div, div, ClosedSub; - (Const, U1), (Const, U1) -> (Const) + (Const, U1), (Const, U1) -> (Const, U1) const D; for; where; self: &'a Translation, right: Translation, Output = Translation; #[allow(clippy::suspicious_arithmetic_impl)] { Translation::from(&self.vector - right.vector) }; 'a); add_sub_impl!(Div, div, ClosedSub; - (Const, U1), (Const, U1) -> (Const) + (Const, U1), (Const, U1) -> (Const, U1) const D; for; where; self: Translation, right: &'b Translation, Output = Translation; #[allow(clippy::suspicious_arithmetic_impl)] { Translation::from(self.vector - &right.vector) }; 'b); add_sub_impl!(Div, div, ClosedSub; - (Const, U1), (Const, U1) -> (Const) + (Const, U1), (Const, U1) -> (Const, U1) const D; for; where; self: Translation, right: Translation, Output = Translation; #[allow(clippy::suspicious_arithmetic_impl)] { Translation::from(self.vector - right.vector) }; ); @@ -70,28 +69,28 @@ add_sub_impl!(Div, div, ClosedSub; // TODO: we don't handle properly non-zero origins here. Do we want this to be the intended // behavior? add_sub_impl!(Mul, mul, ClosedAdd; - (Const, U1), (Const, U1) -> (Const) + (Const, U1), (Const, U1) -> (Const, U1) const D; for; where; self: &'a Translation, right: &'b Point, Output = Point; #[allow(clippy::suspicious_arithmetic_impl)] { right + &self.vector }; 'a, 'b); add_sub_impl!(Mul, mul, ClosedAdd; - (Const, U1), (Const, U1) -> (Const) + (Const, U1), (Const, U1) -> (Const, U1) const D; for; where; self: &'a Translation, right: Point, Output = Point; #[allow(clippy::suspicious_arithmetic_impl)] { right + &self.vector }; 'a); add_sub_impl!(Mul, mul, ClosedAdd; - (Const, U1), (Const, U1) -> (Const) + (Const, U1), (Const, U1) -> (Const, U1) const D; for; where; self: Translation, right: &'b Point, Output = Point; #[allow(clippy::suspicious_arithmetic_impl)] { right + self.vector }; 'b); add_sub_impl!(Mul, mul, ClosedAdd; - (Const, U1), (Const, U1) -> (Const) + (Const, U1), (Const, U1) -> (Const, U1) const D; for; where; self: Translation, right: Point, Output = Point; #[allow(clippy::suspicious_arithmetic_impl)] { right + self.vector }; ); diff --git a/src/third_party/alga/alga_unit_complex.rs b/src/third_party/alga/alga_unit_complex.rs index 7ae9c6df..44dadb42 100755 --- a/src/third_party/alga/alga_unit_complex.rs +++ b/src/third_party/alga/alga_unit_complex.rs @@ -7,9 +7,7 @@ use alga::linear::{ ProjectiveTransformation, Rotation, Similarity, Transformation, }; -use crate::base::allocator::Allocator; -use crate::base::dimension::U2; -use crate::base::{DefaultAllocator, Vector2}; +use crate::base::Vector2; use crate::geometry::{Point2, UnitComplex}; /* @@ -59,10 +57,7 @@ impl_structures!( AbstractGroup ); -impl Transformation> for UnitComplex -where - DefaultAllocator: Allocator, -{ +impl Transformation> for UnitComplex { #[inline] fn transform_point(&self, pt: &Point2) -> Point2 { self.transform_point(pt) @@ -74,9 +69,8 @@ where } } -impl ProjectiveTransformation> for UnitComplex -where - DefaultAllocator: Allocator, +impl ProjectiveTransformation> + for UnitComplex { #[inline] fn inverse_transform_point(&self, pt: &Point2) -> Point2 { @@ -89,10 +83,7 @@ where } } -impl AffineTransformation> for UnitComplex -where - DefaultAllocator: Allocator, -{ +impl AffineTransformation> for UnitComplex { type Rotation = Self; type NonUniformScaling = Id; type Translation = Id; @@ -133,10 +124,7 @@ where } } -impl Similarity> for UnitComplex -where - DefaultAllocator: Allocator, -{ +impl Similarity> for UnitComplex { type Scaling = Id; #[inline] @@ -158,16 +146,13 @@ where macro_rules! marker_impl( ($($Trait: ident),*) => {$( impl $Trait> for UnitComplex - where DefaultAllocator: Allocator { } + { } )*} ); marker_impl!(Isometry, DirectIsometry, OrthogonalTransformation); -impl Rotation> for UnitComplex -where - DefaultAllocator: Allocator, -{ +impl Rotation> for UnitComplex { #[inline] fn powf(&self, n: T) -> Option { Some(self.powf(n))