use simba::scalar::{RealField, SubsetOf, SupersetOf}; use simba::simd::SimdRealField; use crate::base::{Matrix4, Vector4}; use crate::geometry::{ DualQuaternion, Isometry3, Similarity3, SuperTCategoryOf, TAffine, Transform, Translation3, UnitDualQuaternion, UnitQuaternion, }; /* * This file provides the following conversions: * ============================================= * * DualQuaternion -> DualQuaternion * UnitDualQuaternion -> UnitDualQuaternion * UnitDualQuaternion -> Isometry<3> * UnitDualQuaternion -> Similarity<3> * UnitDualQuaternion -> Transform<3> * UnitDualQuaternion -> Matrix (homogeneous) * * NOTE: * UnitDualQuaternion -> DualQuaternion is already provided by: Unit -> T */ impl SubsetOf> for DualQuaternion where T1: SimdRealField, T2: SimdRealField + SupersetOf, { #[inline] fn to_superset(&self) -> DualQuaternion { DualQuaternion::from_real_and_dual(self.real.to_superset(), self.dual.to_superset()) } #[inline] fn is_in_subset(dq: &DualQuaternion) -> bool { crate::is_convertible::<_, Vector4>(&dq.real.coords) && crate::is_convertible::<_, Vector4>(&dq.dual.coords) } #[inline] fn from_superset_unchecked(dq: &DualQuaternion) -> Self { DualQuaternion::from_real_and_dual( dq.real.to_subset_unchecked(), dq.dual.to_subset_unchecked(), ) } } impl SubsetOf> for UnitDualQuaternion where T1: SimdRealField, T2: SimdRealField + SupersetOf, { #[inline] fn to_superset(&self) -> UnitDualQuaternion { UnitDualQuaternion::new_unchecked(self.as_ref().to_superset()) } #[inline] fn is_in_subset(dq: &UnitDualQuaternion) -> bool { crate::is_convertible::<_, DualQuaternion>(dq.as_ref()) } #[inline] fn from_superset_unchecked(dq: &UnitDualQuaternion) -> Self { Self::new_unchecked(crate::convert_ref_unchecked(dq.as_ref())) } } impl SubsetOf> for UnitDualQuaternion where T1: RealField, T2: RealField + SupersetOf, { #[inline] fn to_superset(&self) -> Isometry3 { let dq: UnitDualQuaternion = self.to_superset(); let iso = dq.to_isometry(); crate::convert_unchecked(iso) } #[inline] fn is_in_subset(iso: &Isometry3) -> bool { crate::is_convertible::<_, UnitQuaternion>(&iso.rotation) && crate::is_convertible::<_, Translation3>(&iso.translation) } #[inline] fn from_superset_unchecked(iso: &Isometry3) -> Self { let dq = UnitDualQuaternion::::from_isometry(iso); crate::convert_unchecked(dq) } } impl SubsetOf> for UnitDualQuaternion where T1: RealField, T2: RealField + SupersetOf, { #[inline] fn to_superset(&self) -> Similarity3 { Similarity3::from_isometry(crate::convert_ref(self), T2::one()) } #[inline] fn is_in_subset(sim: &Similarity3) -> bool { sim.scaling() == T2::one() } #[inline] fn from_superset_unchecked(sim: &Similarity3) -> Self { crate::convert_ref_unchecked(&sim.isometry) } } impl SubsetOf> for UnitDualQuaternion where T1: RealField, T2: RealField + SupersetOf, C: SuperTCategoryOf, { #[inline] fn to_superset(&self) -> Transform { Transform::from_matrix_unchecked(self.clone().to_homogeneous().to_superset()) } #[inline] fn is_in_subset(t: &Transform) -> bool { >::is_in_subset(t.matrix()) } #[inline] fn from_superset_unchecked(t: &Transform) -> Self { Self::from_superset_unchecked(t.matrix()) } } impl> SubsetOf> for UnitDualQuaternion { #[inline] fn to_superset(&self) -> Matrix4 { self.clone().to_homogeneous().to_superset() } #[inline] fn is_in_subset(m: &Matrix4) -> bool { crate::is_convertible::<_, Isometry3>(m) } #[inline] fn from_superset_unchecked(m: &Matrix4) -> Self { let iso: Isometry3 = crate::convert_ref_unchecked(m); Self::from_isometry(&iso) } } impl From> for Matrix4 where T::Element: SimdRealField, { #[inline] fn from(dq: UnitDualQuaternion) -> Self { dq.to_homogeneous() } } impl From> for Isometry3 where T::Element: SimdRealField, { #[inline] fn from(dq: UnitDualQuaternion) -> Self { dq.to_isometry() } } impl From> for UnitDualQuaternion where T::Element: SimdRealField, { #[inline] fn from(iso: Isometry3) -> Self { Self::from_isometry(&iso) } }