use alga::general::{Real, SubsetOf, SupersetOf}; use alga::linear::Rotation; use core::{SquareMatrix, OwnedSquareMatrix}; use core::dimension::{DimName, DimNameAdd, DimNameSum, U1}; use core::storage::OwnedStorage; use core::allocator::{Allocator, OwnedAllocator}; use geometry::{PointBase, TranslationBase, IsometryBase, SimilarityBase, TransformBase, SuperTCategoryOf, TAffine}; /* * This file provides the following conversions: * ============================================= * * IsometryBase -> IsometryBase * IsometryBase -> SimilarityBase * IsometryBase -> TransformBase * IsometryBase -> Matrix (homogeneous) */ impl SubsetOf> for IsometryBase where N1: Real, N2: Real + SupersetOf, R1: Rotation> + SubsetOf, R2: Rotation>, SA: OwnedStorage, SB: OwnedStorage, SA::Alloc: OwnedAllocator, SB::Alloc: OwnedAllocator { #[inline] fn to_superset(&self) -> IsometryBase { IsometryBase::from_parts( self.translation.to_superset(), self.rotation.to_superset() ) } #[inline] fn is_in_subset(iso: &IsometryBase) -> bool { ::is_convertible::<_, TranslationBase>(&iso.translation) && ::is_convertible::<_, R1>(&iso.rotation) } #[inline] unsafe fn from_superset_unchecked(iso: &IsometryBase) -> Self { IsometryBase::from_parts( iso.translation.to_subset_unchecked(), iso.rotation.to_subset_unchecked() ) } } impl SubsetOf> for IsometryBase where N1: Real, N2: Real + SupersetOf, R1: Rotation> + SubsetOf, R2: Rotation>, SA: OwnedStorage, SB: OwnedStorage, SA::Alloc: OwnedAllocator, SB::Alloc: OwnedAllocator { #[inline] fn to_superset(&self) -> SimilarityBase { SimilarityBase::from_isometry( self.to_superset(), N2::one() ) } #[inline] fn is_in_subset(sim: &SimilarityBase) -> bool { ::is_convertible::<_, IsometryBase>(&sim.isometry) && sim.scaling() == N2::one() } #[inline] unsafe fn from_superset_unchecked(sim: &SimilarityBase) -> Self { ::convert_ref_unchecked(&sim.isometry) } } impl SubsetOf> for IsometryBase where N1: Real, N2: Real + SupersetOf, SA: OwnedStorage, SB: OwnedStorage, DimNameSum>, C: SuperTCategoryOf, R: Rotation> + SubsetOf, SA::Alloc>> + // needed by: .to_homogeneous() SubsetOf, SB>>, // needed by: ::convert_unchecked(mm) D: DimNameAdd, SA::Alloc: OwnedAllocator + Allocator + // needed by R Allocator, DimNameSum> + // needed by: .to_homogeneous() Allocator, DimNameSum>, // needed by R SB::Alloc: OwnedAllocator, DimNameSum, SB> + Allocator + // needed by: mm.fixed_slice_mut Allocator + // needed by: m.fixed_slice Allocator { // needed by: m.fixed_slice #[inline] fn to_superset(&self) -> TransformBase { TransformBase::from_matrix_unchecked(self.to_homogeneous().to_superset()) } #[inline] fn is_in_subset(t: &TransformBase) -> bool { >::is_in_subset(t.matrix()) } #[inline] unsafe fn from_superset_unchecked(t: &TransformBase) -> Self { Self::from_superset_unchecked(t.matrix()) } } impl SubsetOf, SB>> for IsometryBase where N1: Real, N2: Real + SupersetOf, SA: OwnedStorage, SB: OwnedStorage, DimNameSum>, R: Rotation> + SubsetOf, SA::Alloc>> + // needed by: .to_homogeneous() SubsetOf, SB>>, // needed by: ::convert_unchecked(mm) D: DimNameAdd, SA::Alloc: OwnedAllocator + Allocator + // needed by R Allocator, DimNameSum> + // needed by: .to_homogeneous() Allocator, DimNameSum>, // needed by R SB::Alloc: OwnedAllocator, DimNameSum, SB> + Allocator + // needed by: mm.fixed_slice_mut Allocator + // needed by: m.fixed_slice Allocator { // needed by: m.fixed_slice #[inline] fn to_superset(&self) -> SquareMatrix, SB> { self.to_homogeneous().to_superset() } #[inline] fn is_in_subset(m: &SquareMatrix, SB>) -> bool { let rot = m.fixed_slice::(0, 0); let bottom = m.fixed_slice::(D::dim(), 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() * ::convert(100.0)) && // The bottom row is (0, 0, ..., 1) bottom.iter().all(|e| e.is_zero()) && m[(D::dim(), D::dim())] == N2::one() } #[inline] unsafe fn from_superset_unchecked(m: &SquareMatrix, SB>) -> Self { let t = m.fixed_slice::(0, D::dim()).into_owned(); let t = TranslationBase::from_vector(::convert_unchecked(t)); Self::from_parts(t, ::convert_unchecked(m.clone_owned())) } }