2018-10-13 16:25:34 +08:00
|
|
|
use num::{One, Zero};
|
|
|
|
|
2020-03-21 19:16:46 +08:00
|
|
|
use simba::scalar::{RealField, SubsetOf, SupersetOf};
|
2020-03-23 16:16:01 +08:00
|
|
|
use simba::simd::PrimitiveSimdValue;
|
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::{DimName, DimNameAdd, DimNameSum, U1};
|
|
|
|
use crate::base::{DefaultAllocator, MatrixN, Scalar, VectorN};
|
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,
|
2021-01-29 07:46:14 +08:00
|
|
|
Translation3, UnitDualQuaternion, UnitQuaternion,
|
2020-03-21 19:16:46 +08:00
|
|
|
};
|
2016-12-05 05:44:42 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This file provides the following conversions:
|
|
|
|
* =============================================
|
|
|
|
*
|
2017-08-03 01:37:44 +08:00
|
|
|
* Translation -> Translation
|
|
|
|
* Translation -> Isometry
|
2021-01-29 06:25:32 +08:00
|
|
|
* Translation3 -> UnitDualQuaternion
|
2017-08-03 01:37:44 +08:00
|
|
|
* Translation -> Similarity
|
|
|
|
* Translation -> Transform
|
|
|
|
* Translation -> Matrix (homogeneous)
|
2016-12-05 05:44:42 +08:00
|
|
|
*/
|
|
|
|
|
2017-08-03 01:37:44 +08:00
|
|
|
impl<N1, N2, D: DimName> SubsetOf<Translation<N2, D>> for Translation<N1, D>
|
2018-02-02 19:26:35 +08:00
|
|
|
where
|
2019-12-17 07:09:14 +08:00
|
|
|
N1: Scalar,
|
|
|
|
N2: Scalar + SupersetOf<N1>,
|
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) -> Translation<N2, D> {
|
2018-10-28 14:33:14 +08:00
|
|
|
Translation::from(self.vector.to_superset())
|
2016-12-05 05:44:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
2017-08-03 01:37:44 +08:00
|
|
|
fn is_in_subset(rot: &Translation<N2, D>) -> bool {
|
2019-03-23 21:29:07 +08:00
|
|
|
crate::is_convertible::<_, VectorN<N1, D>>(&rot.vector)
|
2016-12-05 05:44:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
2020-03-21 19:16:46 +08:00
|
|
|
fn from_superset_unchecked(rot: &Translation<N2, D>) -> Self {
|
2018-10-28 14:33:14 +08:00
|
|
|
Translation {
|
|
|
|
vector: rot.vector.to_subset_unchecked(),
|
|
|
|
}
|
2016-12-05 05:44:42 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-03 01:37:44 +08:00
|
|
|
impl<N1, N2, D: DimName, R> SubsetOf<Isometry<N2, D, R>> for Translation<N1, D>
|
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<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, R> {
|
|
|
|
Isometry::from_parts(self.to_superset(), R::identity())
|
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, R>) -> bool {
|
2016-12-05 05:44:42 +08:00
|
|
|
iso.rotation == R::identity()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
2020-03-21 19:16:46 +08:00
|
|
|
fn from_superset_unchecked(iso: &Isometry<N2, D, R>) -> Self {
|
2016-12-05 05:44:42 +08:00
|
|
|
Self::from_superset_unchecked(&iso.translation)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-29 06:25:32 +08:00
|
|
|
impl<N1, N2> SubsetOf<UnitDualQuaternion<N2>> for Translation3<N1>
|
|
|
|
where
|
|
|
|
N1: RealField,
|
|
|
|
N2: RealField + SupersetOf<N1>,
|
|
|
|
{
|
|
|
|
#[inline]
|
|
|
|
fn to_superset(&self) -> UnitDualQuaternion<N2> {
|
|
|
|
let dq = UnitDualQuaternion::<N1>::from_parts(self.clone(), UnitQuaternion::identity());
|
|
|
|
dq.to_superset()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn is_in_subset(dq: &UnitDualQuaternion<N2>) -> bool {
|
2021-01-29 07:46:14 +08:00
|
|
|
crate::is_convertible::<_, Translation<N1, _>>(&dq.translation())
|
|
|
|
&& dq.rotation() == UnitQuaternion::identity()
|
2021-01-29 06:25:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn from_superset_unchecked(dq: &UnitDualQuaternion<N2>) -> Self {
|
|
|
|
let dq: UnitDualQuaternion<N1> = crate::convert_ref_unchecked(dq);
|
|
|
|
dq.translation()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-03 01:37:44 +08:00
|
|
|
impl<N1, N2, D: DimName, R> SubsetOf<Similarity<N2, D, R>> for Translation<N1, D>
|
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<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, R> {
|
|
|
|
Similarity::from_parts(self.to_superset(), R::identity(), 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, R>) -> bool {
|
2018-02-02 19:26:35 +08:00
|
|
|
sim.isometry.rotation == R::identity() && 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, R>) -> Self {
|
2016-12-05 05:44:42 +08:00
|
|
|
Self::from_superset_unchecked(&sim.isometry.translation)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-03 01:37:44 +08:00
|
|
|
impl<N1, N2, D, C> SubsetOf<Transform<N2, D, C>> for Translation<N1, D>
|
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>,
|
|
|
|
D: DimNameAdd<U1>,
|
|
|
|
DefaultAllocator: Allocator<N1, D>
|
|
|
|
+ Allocator<N2, D>
|
|
|
|
+ Allocator<N1, DimNameSum<D, U1>, DimNameSum<D, U1>>
|
|
|
|
+ Allocator<N2, DimNameSum<D, U1>, DimNameSum<D, U1>>,
|
|
|
|
{
|
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> SubsetOf<MatrixN<N2, DimNameSum<D, U1>>> for Translation<N1, D>
|
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
|
|
|
D: DimNameAdd<U1>,
|
|
|
|
DefaultAllocator: Allocator<N1, D>
|
|
|
|
+ Allocator<N2, D>
|
|
|
|
+ Allocator<N1, DimNameSum<D, U1>, DimNameSum<D, U1>>
|
|
|
|
+ Allocator<N2, DimNameSum<D, U1>, DimNameSum<D, U1>>,
|
|
|
|
{
|
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 {
|
2016-12-05 05:44:42 +08:00
|
|
|
let id = m.fixed_slice::<DimNameSum<D, U1>, D>(0, 0);
|
|
|
|
|
|
|
|
// Scalar types agree.
|
|
|
|
m.iter().all(|e| SupersetOf::<N1>::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]
|
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());
|
2018-10-28 14:33:14 +08:00
|
|
|
Self {
|
2019-03-23 21:29:07 +08:00
|
|
|
vector: crate::convert_unchecked(t.into_owned()),
|
2018-10-28 14:33:14 +08:00
|
|
|
}
|
2016-12-05 05:44:42 +08:00
|
|
|
}
|
|
|
|
}
|
2018-10-13 16:25:34 +08:00
|
|
|
|
2019-12-17 07:09:14 +08:00
|
|
|
impl<N: Scalar + Zero + One, D: DimName> From<Translation<N, D>> for MatrixN<N, DimNameSum<D, U1>>
|
2018-10-13 16:25:34 +08:00
|
|
|
where
|
|
|
|
D: DimNameAdd<U1>,
|
|
|
|
DefaultAllocator: Allocator<N, D> + Allocator<N, DimNameSum<D, U1>, DimNameSum<D, U1>>,
|
|
|
|
{
|
|
|
|
#[inline]
|
|
|
|
fn from(t: Translation<N, D>) -> Self {
|
|
|
|
t.to_homogeneous()
|
|
|
|
}
|
|
|
|
}
|
2018-10-28 14:33:14 +08:00
|
|
|
|
2019-12-17 07:09:14 +08:00
|
|
|
impl<N: Scalar, D: DimName> From<VectorN<N, D>> for Translation<N, D>
|
2020-04-06 00:49:48 +08:00
|
|
|
where
|
|
|
|
DefaultAllocator: Allocator<N, D>,
|
2018-10-28 14:33:14 +08:00
|
|
|
{
|
|
|
|
#[inline]
|
|
|
|
fn from(vector: VectorN<N, D>) -> Self {
|
|
|
|
Translation { vector }
|
|
|
|
}
|
|
|
|
}
|
2020-03-23 16:16:01 +08:00
|
|
|
|
2020-03-24 17:16:31 +08:00
|
|
|
impl<N: Scalar + PrimitiveSimdValue, D: DimName> From<[Translation<N::Element, D>; 2]>
|
2020-03-23 16:16:01 +08:00
|
|
|
for Translation<N, D>
|
|
|
|
where
|
|
|
|
N: From<[<N as simba::simd::SimdValue>::Element; 2]>,
|
2020-03-24 17:16:31 +08:00
|
|
|
N::Element: Scalar,
|
2020-03-23 16:16:01 +08:00
|
|
|
DefaultAllocator: Allocator<N, D> + Allocator<N::Element, D>,
|
|
|
|
{
|
|
|
|
#[inline]
|
|
|
|
fn from(arr: [Translation<N::Element, D>; 2]) -> Self {
|
2020-03-24 17:16:31 +08:00
|
|
|
Self::from(VectorN::from([
|
|
|
|
arr[0].vector.clone(),
|
|
|
|
arr[1].vector.clone(),
|
|
|
|
]))
|
2020-03-23 16:16:01 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-24 17:16:31 +08:00
|
|
|
impl<N: Scalar + PrimitiveSimdValue, D: DimName> From<[Translation<N::Element, D>; 4]>
|
2020-03-23 16:16:01 +08:00
|
|
|
for Translation<N, D>
|
|
|
|
where
|
|
|
|
N: From<[<N as simba::simd::SimdValue>::Element; 4]>,
|
2020-03-24 17:16:31 +08:00
|
|
|
N::Element: Scalar,
|
2020-03-23 16:16:01 +08:00
|
|
|
DefaultAllocator: Allocator<N, D> + Allocator<N::Element, D>,
|
|
|
|
{
|
|
|
|
#[inline]
|
|
|
|
fn from(arr: [Translation<N::Element, D>; 4]) -> Self {
|
|
|
|
Self::from(VectorN::from([
|
2020-03-24 17:16:31 +08:00
|
|
|
arr[0].vector.clone(),
|
|
|
|
arr[1].vector.clone(),
|
|
|
|
arr[2].vector.clone(),
|
|
|
|
arr[3].vector.clone(),
|
2020-03-23 16:16:01 +08:00
|
|
|
]))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-24 17:16:31 +08:00
|
|
|
impl<N: Scalar + PrimitiveSimdValue, D: DimName> From<[Translation<N::Element, D>; 8]>
|
2020-03-23 16:16:01 +08:00
|
|
|
for Translation<N, D>
|
|
|
|
where
|
|
|
|
N: From<[<N as simba::simd::SimdValue>::Element; 8]>,
|
2020-03-24 17:16:31 +08:00
|
|
|
N::Element: Scalar,
|
2020-03-23 16:16:01 +08:00
|
|
|
DefaultAllocator: Allocator<N, D> + Allocator<N::Element, D>,
|
|
|
|
{
|
|
|
|
#[inline]
|
|
|
|
fn from(arr: [Translation<N::Element, D>; 8]) -> Self {
|
|
|
|
Self::from(VectorN::from([
|
2020-03-24 17:16:31 +08:00
|
|
|
arr[0].vector.clone(),
|
|
|
|
arr[1].vector.clone(),
|
|
|
|
arr[2].vector.clone(),
|
|
|
|
arr[3].vector.clone(),
|
|
|
|
arr[4].vector.clone(),
|
|
|
|
arr[5].vector.clone(),
|
|
|
|
arr[6].vector.clone(),
|
|
|
|
arr[7].vector.clone(),
|
2020-03-23 16:16:01 +08:00
|
|
|
]))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-24 17:16:31 +08:00
|
|
|
impl<N: Scalar + PrimitiveSimdValue, D: DimName> From<[Translation<N::Element, D>; 16]>
|
2020-03-23 16:16:01 +08:00
|
|
|
for Translation<N, D>
|
|
|
|
where
|
|
|
|
N: From<[<N as simba::simd::SimdValue>::Element; 16]>,
|
2020-03-24 17:16:31 +08:00
|
|
|
N::Element: Scalar,
|
2020-03-23 16:16:01 +08:00
|
|
|
DefaultAllocator: Allocator<N, D> + Allocator<N::Element, D>,
|
|
|
|
{
|
|
|
|
#[inline]
|
|
|
|
fn from(arr: [Translation<N::Element, D>; 16]) -> Self {
|
|
|
|
Self::from(VectorN::from([
|
2020-03-24 17:16:31 +08:00
|
|
|
arr[0].vector.clone(),
|
|
|
|
arr[1].vector.clone(),
|
|
|
|
arr[2].vector.clone(),
|
|
|
|
arr[3].vector.clone(),
|
|
|
|
arr[4].vector.clone(),
|
|
|
|
arr[5].vector.clone(),
|
|
|
|
arr[6].vector.clone(),
|
|
|
|
arr[7].vector.clone(),
|
|
|
|
arr[8].vector.clone(),
|
|
|
|
arr[9].vector.clone(),
|
|
|
|
arr[10].vector.clone(),
|
|
|
|
arr[11].vector.clone(),
|
|
|
|
arr[12].vector.clone(),
|
|
|
|
arr[13].vector.clone(),
|
|
|
|
arr[14].vector.clone(),
|
|
|
|
arr[15].vector.clone(),
|
2020-03-23 16:16:01 +08:00
|
|
|
]))
|
|
|
|
}
|
|
|
|
}
|