2020-03-21 19:16:46 +08:00
|
|
|
use simba::scalar::{RealField, SubsetOf, SupersetOf};
|
2016-12-05 05:44:42 +08:00
|
|
|
|
2019-03-23 21:29:07 +08:00
|
|
|
use crate::base::allocator::Allocator;
|
|
|
|
use crate::base::dimension::{DimMin, DimName, DimNameAdd, DimNameSum, U1};
|
|
|
|
use crate::base::{DefaultAllocator, MatrixN};
|
2016-12-05 05:44:42 +08:00
|
|
|
|
2020-03-21 19:16:46 +08:00
|
|
|
use crate::geometry::{
|
|
|
|
AbstractRotation, Isometry, Similarity, SuperTCategoryOf, TAffine, Transform, Translation,
|
|
|
|
};
|
2016-12-05 05:44:42 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This file provides the following conversions:
|
|
|
|
* =============================================
|
|
|
|
*
|
2017-08-03 01:37:44 +08:00
|
|
|
* Isometry -> Isometry
|
|
|
|
* Isometry -> Similarity
|
|
|
|
* Isometry -> Transform
|
|
|
|
* Isometry -> Matrix (homogeneous)
|
2016-12-05 05:44:42 +08:00
|
|
|
*/
|
|
|
|
|
2017-08-03 01:37:44 +08:00
|
|
|
impl<N1, N2, D: DimName, R1, R2> SubsetOf<Isometry<N2, D, R2>> for Isometry<N1, D, R1>
|
2018-02-02 19:26:35 +08:00
|
|
|
where
|
2019-03-25 18:21:41 +08:00
|
|
|
N1: RealField,
|
|
|
|
N2: RealField + SupersetOf<N1>,
|
2020-03-21 19:16:46 +08:00
|
|
|
R1: AbstractRotation<N1, D> + SubsetOf<R2>,
|
|
|
|
R2: AbstractRotation<N2, D>,
|
2018-02-02 19:26:35 +08:00
|
|
|
DefaultAllocator: Allocator<N1, D> + Allocator<N2, D>,
|
|
|
|
{
|
2016-12-05 05:44:42 +08:00
|
|
|
#[inline]
|
2017-08-03 01:37:44 +08:00
|
|
|
fn to_superset(&self) -> Isometry<N2, D, R2> {
|
2018-02-02 19:26:35 +08:00
|
|
|
Isometry::from_parts(self.translation.to_superset(), self.rotation.to_superset())
|
2016-12-05 05:44:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
2017-08-03 01:37:44 +08:00
|
|
|
fn is_in_subset(iso: &Isometry<N2, D, R2>) -> bool {
|
2019-03-23 21:29:07 +08:00
|
|
|
crate::is_convertible::<_, Translation<N1, D>>(&iso.translation)
|
|
|
|
&& crate::is_convertible::<_, R1>(&iso.rotation)
|
2016-12-05 05:44:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
2020-03-21 19:16:46 +08:00
|
|
|
fn from_superset_unchecked(iso: &Isometry<N2, D, R2>) -> Self {
|
2017-08-03 01:37:44 +08:00
|
|
|
Isometry::from_parts(
|
2016-12-05 05:44:42 +08:00
|
|
|
iso.translation.to_subset_unchecked(),
|
2018-02-02 19:26:35 +08:00
|
|
|
iso.rotation.to_subset_unchecked(),
|
2016-12-05 05:44:42 +08:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-03 01:37:44 +08:00
|
|
|
impl<N1, N2, D: DimName, R1, R2> SubsetOf<Similarity<N2, D, R2>> for Isometry<N1, D, R1>
|
2018-02-02 19:26:35 +08:00
|
|
|
where
|
2019-03-25 18:21:41 +08:00
|
|
|
N1: RealField,
|
|
|
|
N2: RealField + SupersetOf<N1>,
|
2020-03-21 19:16:46 +08:00
|
|
|
R1: AbstractRotation<N1, D> + SubsetOf<R2>,
|
|
|
|
R2: AbstractRotation<N2, D>,
|
2018-02-02 19:26:35 +08:00
|
|
|
DefaultAllocator: Allocator<N1, D> + Allocator<N2, D>,
|
|
|
|
{
|
2016-12-05 05:44:42 +08:00
|
|
|
#[inline]
|
2017-08-03 01:37:44 +08:00
|
|
|
fn to_superset(&self) -> Similarity<N2, D, R2> {
|
2018-02-02 19:26:35 +08:00
|
|
|
Similarity::from_isometry(self.to_superset(), N2::one())
|
2016-12-05 05:44:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
2017-08-03 01:37:44 +08:00
|
|
|
fn is_in_subset(sim: &Similarity<N2, D, R2>) -> bool {
|
2019-03-23 21:29:07 +08:00
|
|
|
crate::is_convertible::<_, Isometry<N1, D, R1>>(&sim.isometry) && sim.scaling() == N2::one()
|
2016-12-05 05:44:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
2020-03-21 19:16:46 +08:00
|
|
|
fn from_superset_unchecked(sim: &Similarity<N2, D, R2>) -> Self {
|
2019-03-23 21:29:07 +08:00
|
|
|
crate::convert_ref_unchecked(&sim.isometry)
|
2016-12-05 05:44:42 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-03 01:37:44 +08:00
|
|
|
impl<N1, N2, D, R, C> SubsetOf<Transform<N2, D, C>> for Isometry<N1, D, R>
|
2018-02-02 19:26:35 +08:00
|
|
|
where
|
2019-03-25 18:21:41 +08:00
|
|
|
N1: RealField,
|
|
|
|
N2: RealField + SupersetOf<N1>,
|
2018-02-02 19:26:35 +08:00
|
|
|
C: SuperTCategoryOf<TAffine>,
|
2020-03-21 19:16:46 +08:00
|
|
|
R: AbstractRotation<N1, D>
|
2018-02-02 19:26:35 +08:00
|
|
|
+ SubsetOf<MatrixN<N1, DimNameSum<D, U1>>>
|
|
|
|
+ SubsetOf<MatrixN<N2, DimNameSum<D, U1>>>,
|
|
|
|
D: DimNameAdd<U1> + DimMin<D, Output = D>, // needed by .is_special_orthogonal()
|
|
|
|
DefaultAllocator: Allocator<N1, D>
|
|
|
|
+ Allocator<N1, D, D>
|
|
|
|
+ Allocator<N1, DimNameSum<D, U1>, DimNameSum<D, U1>>
|
|
|
|
+ Allocator<N2, DimNameSum<D, U1>, DimNameSum<D, U1>>
|
|
|
|
+ Allocator<N2, DimNameSum<D, U1>, DimNameSum<D, U1>>
|
|
|
|
+ Allocator<(usize, usize), D>
|
|
|
|
+ Allocator<N2, D, D>
|
|
|
|
+ Allocator<N2, D>,
|
|
|
|
{
|
2016-12-05 05:44:42 +08:00
|
|
|
#[inline]
|
2017-08-03 01:37:44 +08:00
|
|
|
fn to_superset(&self) -> Transform<N2, D, C> {
|
|
|
|
Transform::from_matrix_unchecked(self.to_homogeneous().to_superset())
|
2016-12-05 05:44:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
2017-08-03 01:37:44 +08:00
|
|
|
fn is_in_subset(t: &Transform<N2, D, C>) -> bool {
|
2016-12-05 05:44:42 +08:00
|
|
|
<Self as SubsetOf<_>>::is_in_subset(t.matrix())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
2020-03-21 19:16:46 +08:00
|
|
|
fn from_superset_unchecked(t: &Transform<N2, D, C>) -> Self {
|
2016-12-05 05:44:42 +08:00
|
|
|
Self::from_superset_unchecked(t.matrix())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-03 01:37:44 +08:00
|
|
|
impl<N1, N2, D, R> SubsetOf<MatrixN<N2, DimNameSum<D, U1>>> for Isometry<N1, D, R>
|
2018-02-02 19:26:35 +08:00
|
|
|
where
|
2019-03-25 18:21:41 +08:00
|
|
|
N1: RealField,
|
|
|
|
N2: RealField + SupersetOf<N1>,
|
2020-03-21 19:16:46 +08:00
|
|
|
R: AbstractRotation<N1, D>
|
2018-02-02 19:26:35 +08:00
|
|
|
+ SubsetOf<MatrixN<N1, DimNameSum<D, U1>>>
|
|
|
|
+ SubsetOf<MatrixN<N2, DimNameSum<D, U1>>>,
|
|
|
|
D: DimNameAdd<U1> + DimMin<D, Output = D>, // needed by .is_special_orthogonal()
|
|
|
|
DefaultAllocator: Allocator<N1, D>
|
|
|
|
+ Allocator<N1, D, D>
|
|
|
|
+ Allocator<N1, DimNameSum<D, U1>, DimNameSum<D, U1>>
|
|
|
|
+ Allocator<N2, DimNameSum<D, U1>, DimNameSum<D, U1>>
|
|
|
|
+ Allocator<N2, DimNameSum<D, U1>, DimNameSum<D, U1>>
|
|
|
|
+ Allocator<(usize, usize), D>
|
|
|
|
+ Allocator<N2, D, D>
|
|
|
|
+ Allocator<N2, D>,
|
|
|
|
{
|
2016-12-05 05:44:42 +08:00
|
|
|
#[inline]
|
2017-08-03 01:37:44 +08:00
|
|
|
fn to_superset(&self) -> MatrixN<N2, DimNameSum<D, U1>> {
|
2016-12-05 05:44:42 +08:00
|
|
|
self.to_homogeneous().to_superset()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
2017-08-03 01:37:44 +08:00
|
|
|
fn is_in_subset(m: &MatrixN<N2, DimNameSum<D, U1>>) -> bool {
|
2018-02-02 19:26:35 +08:00
|
|
|
let rot = m.fixed_slice::<D, D>(0, 0);
|
2016-12-05 05:44:42 +08:00
|
|
|
let bottom = m.fixed_slice::<U1, D>(D::dim(), 0);
|
|
|
|
|
|
|
|
// Scalar types agree.
|
|
|
|
m.iter().all(|e| SupersetOf::<N1>::is_in_subset(e)) &&
|
|
|
|
// The block part is a rotation.
|
2019-03-23 21:29:07 +08:00
|
|
|
rot.is_special_orthogonal(N2::default_epsilon() * crate::convert(100.0)) &&
|
2016-12-05 05:44:42 +08:00
|
|
|
// The bottom row is (0, 0, ..., 1)
|
2018-02-02 19:26:35 +08:00
|
|
|
bottom.iter().all(|e| e.is_zero()) && m[(D::dim(), D::dim())] == N2::one()
|
2016-12-05 05:44:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
2020-03-21 19:16:46 +08:00
|
|
|
fn from_superset_unchecked(m: &MatrixN<N2, DimNameSum<D, U1>>) -> Self {
|
2016-12-05 05:44:42 +08:00
|
|
|
let t = m.fixed_slice::<D, U1>(0, D::dim()).into_owned();
|
2018-10-28 14:33:39 +08:00
|
|
|
let t = Translation {
|
2019-03-23 21:29:07 +08:00
|
|
|
vector: crate::convert_unchecked(t),
|
2018-10-28 14:33:39 +08:00
|
|
|
};
|
2016-12-05 05:44:42 +08:00
|
|
|
|
2019-03-23 21:29:07 +08:00
|
|
|
Self::from_parts(t, crate::convert_unchecked(m.clone_owned()))
|
2016-12-05 05:44:42 +08:00
|
|
|
}
|
|
|
|
}
|
2018-10-13 16:25:34 +08:00
|
|
|
|
2019-03-25 18:21:41 +08:00
|
|
|
impl<N: RealField, D: DimName, R> From<Isometry<N, D, R>> for MatrixN<N, DimNameSum<D, U1>>
|
2018-10-13 16:25:34 +08:00
|
|
|
where
|
|
|
|
D: DimNameAdd<U1>,
|
|
|
|
R: SubsetOf<MatrixN<N, DimNameSum<D, U1>>>,
|
|
|
|
DefaultAllocator: Allocator<N, DimNameSum<D, U1>, DimNameSum<D, U1>> + Allocator<N, D>,
|
|
|
|
{
|
|
|
|
#[inline]
|
|
|
|
fn from(iso: Isometry<N, D, R>) -> Self {
|
|
|
|
iso.to_homogeneous()
|
|
|
|
}
|
|
|
|
}
|