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