use alga::general::{SubsetOf, SupersetOf, Real}; use alga::linear::Rotation; use core::{Scalar, ColumnVector, SquareMatrix}; 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: * ============================================= * * TranslationBase -> TranslationBase * TranslationBase -> IsometryBase * TranslationBase -> SimilarityBase * TranslationBase -> TransformBase * TranslationBase -> Matrix (homogeneous) */ impl SubsetOf> for TranslationBase where N1: Scalar, N2: Scalar + SupersetOf, SA: OwnedStorage, SB: OwnedStorage, SA::Alloc: OwnedAllocator, SB::Alloc: OwnedAllocator { #[inline] fn to_superset(&self) -> TranslationBase { TranslationBase::from_vector(self.vector.to_superset()) } #[inline] fn is_in_subset(rot: &TranslationBase) -> bool { ::is_convertible::<_, ColumnVector>(&rot.vector) } #[inline] unsafe fn from_superset_unchecked(rot: &TranslationBase) -> Self { TranslationBase::from_vector(rot.vector.to_subset_unchecked()) } } impl SubsetOf> for TranslationBase where N1: Real, N2: Real + SupersetOf, SA: OwnedStorage, SB: OwnedStorage, R: Rotation>, SA::Alloc: OwnedAllocator, SB::Alloc: OwnedAllocator { #[inline] fn to_superset(&self) -> IsometryBase { IsometryBase::from_parts(self.to_superset(), R::identity()) } #[inline] fn is_in_subset(iso: &IsometryBase) -> bool { iso.rotation == R::identity() } #[inline] unsafe fn from_superset_unchecked(iso: &IsometryBase) -> Self { Self::from_superset_unchecked(&iso.translation) } } impl SubsetOf> for TranslationBase where N1: Real, N2: Real + SupersetOf, SA: OwnedStorage, SB: OwnedStorage, R: Rotation>, SA::Alloc: OwnedAllocator, SB::Alloc: OwnedAllocator { #[inline] fn to_superset(&self) -> SimilarityBase { SimilarityBase::from_parts(self.to_superset(), R::identity(), N2::one()) } #[inline] fn is_in_subset(sim: &SimilarityBase) -> bool { sim.isometry.rotation == R::identity() && sim.scaling() == N2::one() } #[inline] unsafe fn from_superset_unchecked(sim: &SimilarityBase) -> Self { Self::from_superset_unchecked(&sim.isometry.translation) } } impl SubsetOf> for TranslationBase where N1: Real, N2: Real + SupersetOf, SA: OwnedStorage, SB: OwnedStorage, DimNameSum>, C: SuperTCategoryOf, D: DimNameAdd, SA::Alloc: OwnedAllocator + Allocator, DimNameSum>, SB::Alloc: OwnedAllocator, DimNameSum, SB> + Allocator + Allocator, D> { #[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 TranslationBase where N1: Real, N2: Real + SupersetOf, SA: OwnedStorage, SB: OwnedStorage, DimNameSum>, D: DimNameAdd, SA::Alloc: OwnedAllocator + Allocator, DimNameSum>, SB::Alloc: OwnedAllocator, DimNameSum, SB> + Allocator + Allocator, D> { #[inline] fn to_superset(&self) -> SquareMatrix, SB> { self.to_homogeneous().to_superset() } #[inline] fn is_in_subset(m: &SquareMatrix, SB>) -> bool { let id = m.fixed_slice::, 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() } #[inline] unsafe fn from_superset_unchecked(m: &SquareMatrix, SB>) -> Self { let t = m.fixed_slice::(0, D::dim()); Self::from_vector(::convert_unchecked(t.into_owned())) } }