1use simba::scalar::{RealField, SubsetOf};
2
3use crate::base::allocator::Allocator;
4use crate::base::dimension::{DimNameAdd, DimNameSum, U1};
5use crate::base::{Const, DefaultAllocator, OMatrix};
6
7use crate::geometry::{SuperTCategoryOf, TCategory, Transform};
8
9impl<T1, T2, C1, C2, const D: usize> SubsetOf<Transform<T2, C2, D>> for Transform<T1, C1, D>
10where
11 T1: RealField + SubsetOf<T2>,
12 T2: RealField,
13 C1: TCategory,
14 C2: SuperTCategoryOf<C1>,
15 Const<D>: DimNameAdd<U1>,
16 DefaultAllocator: Allocator<T1, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>>
17 + Allocator<T2, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>>,
18 T1::Epsilon: Copy,
19 T2::Epsilon: Copy,
20{
21 #[inline]
22 fn to_superset(&self) -> Transform<T2, C2, D> {
23 Transform::from_matrix_unchecked(self.to_homogeneous().to_superset())
24 }
25
26 #[inline]
27 fn is_in_subset(t: &Transform<T2, C2, D>) -> bool {
28 <Self as SubsetOf<_>>::is_in_subset(t.matrix())
29 }
30
31 #[inline]
32 fn from_superset_unchecked(t: &Transform<T2, C2, D>) -> Self {
33 Self::from_superset_unchecked(t.matrix())
34 }
35}
36
37impl<T1, T2, C, const D: usize>
38 SubsetOf<OMatrix<T2, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>>>
39 for Transform<T1, C, D>
40where
41 T1: RealField + SubsetOf<T2>,
42 T2: RealField,
43 C: TCategory,
44 Const<D>: DimNameAdd<U1>,
45 DefaultAllocator: Allocator<T1, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>>
46 + Allocator<T2, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>>,
47 T1::Epsilon: Copy,
48 T2::Epsilon: Copy,
49{
50 #[inline]
51 fn to_superset(&self) -> OMatrix<T2, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>> {
52 self.matrix().to_superset()
53 }
54
55 #[inline]
56 fn is_in_subset(m: &OMatrix<T2, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>>) -> bool {
57 C::check_homogeneous_invariants(m)
58 }
59
60 #[inline]
61 fn from_superset_unchecked(
62 m: &OMatrix<T2, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>>,
63 ) -> Self {
64 Self::from_matrix_unchecked(crate::convert_ref_unchecked(m))
65 }
66}
67
68impl<T: RealField, C, const D: usize> From<Transform<T, C, D>>
69 for OMatrix<T, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>>
70where
71 Const<D>: DimNameAdd<U1>,
72 C: TCategory,
73 DefaultAllocator: Allocator<T, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>>,
74{
75 #[inline]
76 fn from(t: Transform<T, C, D>) -> Self {
77 t.to_homogeneous()
78 }
79}