2017-02-13 01:17:09 +08:00
|
|
|
use num::Zero;
|
|
|
|
use num_complex::Complex;
|
|
|
|
|
2020-03-21 19:16:46 +08:00
|
|
|
use simba::scalar::{RealField, SubsetOf, SupersetOf};
|
2020-04-05 23:15:43 +08:00
|
|
|
use simba::simd::{PrimitiveSimdValue, SimdRealField};
|
2017-02-13 01:17:09 +08:00
|
|
|
|
2020-03-23 16:16:01 +08:00
|
|
|
use crate::base::{Matrix2, Matrix3, Scalar};
|
2019-03-23 21:29:07 +08:00
|
|
|
use crate::geometry::{
|
2020-03-21 19:16:46 +08:00
|
|
|
AbstractRotation, Isometry, Rotation2, Similarity, SuperTCategoryOf, TAffine, Transform,
|
|
|
|
Translation, UnitComplex,
|
2018-05-19 23:15:15 +08:00
|
|
|
};
|
2017-02-13 01:17:09 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This file provides the following conversions:
|
|
|
|
* =============================================
|
|
|
|
*
|
|
|
|
* UnitComplex -> UnitComplex
|
2017-08-03 01:37:44 +08:00
|
|
|
* UnitComplex -> Rotation<U1>
|
2021-04-07 20:29:20 +08:00
|
|
|
* UnitComplex -> Isometry<2>
|
|
|
|
* UnitComplex -> Similarity<2>
|
|
|
|
* UnitComplex -> Transform<2>
|
2017-02-13 01:17:09 +08:00
|
|
|
* UnitComplex -> Matrix<U3> (homogeneous)
|
|
|
|
*
|
|
|
|
* NOTE:
|
|
|
|
* UnitComplex -> Complex is already provided by: Unit<T> -> T
|
|
|
|
*/
|
|
|
|
|
|
|
|
impl<N1, N2> SubsetOf<UnitComplex<N2>> for UnitComplex<N1>
|
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
|
|
|
{
|
2017-02-13 01:17:09 +08:00
|
|
|
#[inline]
|
|
|
|
fn to_superset(&self) -> UnitComplex<N2> {
|
|
|
|
UnitComplex::new_unchecked(self.as_ref().to_superset())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn is_in_subset(uq: &UnitComplex<N2>) -> bool {
|
2019-03-23 21:29:07 +08:00
|
|
|
crate::is_convertible::<_, Complex<N1>>(uq.as_ref())
|
2017-02-13 01:17:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
2020-03-21 19:16:46 +08:00
|
|
|
fn from_superset_unchecked(uq: &UnitComplex<N2>) -> Self {
|
2019-03-23 21:29:07 +08:00
|
|
|
Self::new_unchecked(crate::convert_ref_unchecked(uq.as_ref()))
|
2017-02-13 01:17:09 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-03 01:37:44 +08:00
|
|
|
impl<N1, N2> SubsetOf<Rotation2<N2>> for UnitComplex<N1>
|
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
|
|
|
{
|
2017-02-13 01:17:09 +08:00
|
|
|
#[inline]
|
2017-08-03 01:37:44 +08:00
|
|
|
fn to_superset(&self) -> Rotation2<N2> {
|
2017-02-13 01:17:09 +08:00
|
|
|
let q: UnitComplex<N2> = self.to_superset();
|
|
|
|
q.to_rotation_matrix().to_superset()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
2017-08-03 01:37:44 +08:00
|
|
|
fn is_in_subset(rot: &Rotation2<N2>) -> bool {
|
2019-03-23 21:29:07 +08:00
|
|
|
crate::is_convertible::<_, Rotation2<N1>>(rot)
|
2017-02-13 01:17:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
2020-03-21 19:16:46 +08:00
|
|
|
fn from_superset_unchecked(rot: &Rotation2<N2>) -> Self {
|
2017-02-13 01:17:09 +08:00
|
|
|
let q = UnitComplex::<N2>::from_rotation_matrix(rot);
|
2019-03-23 21:29:07 +08:00
|
|
|
crate::convert_unchecked(q)
|
2017-02-13 01:17:09 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-07 20:29:20 +08:00
|
|
|
impl<N1, N2, R> SubsetOf<Isometry<N2, R, 2>> for UnitComplex<N1>
|
2018-02-02 19:26:35 +08:00
|
|
|
where
|
2019-03-25 18:21:41 +08:00
|
|
|
N1: RealField,
|
|
|
|
N2: RealField + SupersetOf<N1>,
|
2021-04-07 20:29:20 +08:00
|
|
|
R: AbstractRotation<N2, 2> + SupersetOf<Self>,
|
2018-02-02 19:26:35 +08:00
|
|
|
{
|
2017-02-13 01:17:09 +08:00
|
|
|
#[inline]
|
2021-04-07 20:29:20 +08:00
|
|
|
fn to_superset(&self) -> Isometry<N2, R, 2> {
|
2019-03-23 21:29:07 +08:00
|
|
|
Isometry::from_parts(Translation::identity(), crate::convert_ref(self))
|
2017-02-13 01:17:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
2021-04-07 20:29:20 +08:00
|
|
|
fn is_in_subset(iso: &Isometry<N2, R, 2>) -> bool {
|
2017-02-13 01:17:09 +08:00
|
|
|
iso.translation.vector.is_zero()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
2021-04-07 20:29:20 +08:00
|
|
|
fn from_superset_unchecked(iso: &Isometry<N2, R, 2>) -> Self {
|
2019-03-23 21:29:07 +08:00
|
|
|
crate::convert_ref_unchecked(&iso.rotation)
|
2017-02-13 01:17:09 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-07 20:29:20 +08:00
|
|
|
impl<N1, N2, R> SubsetOf<Similarity<N2, R, 2>> for UnitComplex<N1>
|
2018-02-02 19:26:35 +08:00
|
|
|
where
|
2019-03-25 18:21:41 +08:00
|
|
|
N1: RealField,
|
|
|
|
N2: RealField + SupersetOf<N1>,
|
2021-04-07 20:29:20 +08:00
|
|
|
R: AbstractRotation<N2, 2> + SupersetOf<Self>,
|
2018-02-02 19:26:35 +08:00
|
|
|
{
|
2017-02-13 01:17:09 +08:00
|
|
|
#[inline]
|
2021-04-07 20:29:20 +08:00
|
|
|
fn to_superset(&self) -> Similarity<N2, R, 2> {
|
2019-03-23 21:29:07 +08:00
|
|
|
Similarity::from_isometry(crate::convert_ref(self), N2::one())
|
2017-02-13 01:17:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
2021-04-07 20:29:20 +08:00
|
|
|
fn is_in_subset(sim: &Similarity<N2, R, 2>) -> bool {
|
2018-02-02 19:26:35 +08:00
|
|
|
sim.isometry.translation.vector.is_zero() && sim.scaling() == N2::one()
|
2017-02-13 01:17:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
2021-04-07 20:29:20 +08:00
|
|
|
fn from_superset_unchecked(sim: &Similarity<N2, R, 2>) -> Self {
|
2019-03-23 21:29:07 +08:00
|
|
|
crate::convert_ref_unchecked(&sim.isometry)
|
2017-02-13 01:17:09 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-07 20:29:20 +08:00
|
|
|
impl<N1, N2, C> SubsetOf<Transform<N2, C, 2>> for UnitComplex<N1>
|
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>,
|
|
|
|
{
|
2017-02-13 01:17:09 +08:00
|
|
|
#[inline]
|
2021-04-07 20:29:20 +08:00
|
|
|
fn to_superset(&self) -> Transform<N2, C, 2> {
|
2017-08-03 01:37:44 +08:00
|
|
|
Transform::from_matrix_unchecked(self.to_homogeneous().to_superset())
|
2017-02-13 01:17:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
2021-04-07 20:29:20 +08:00
|
|
|
fn is_in_subset(t: &Transform<N2, C, 2>) -> bool {
|
2017-02-13 01:17:09 +08:00
|
|
|
<Self as SubsetOf<_>>::is_in_subset(t.matrix())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
2021-04-07 20:29:20 +08:00
|
|
|
fn from_superset_unchecked(t: &Transform<N2, C, 2>) -> Self {
|
2017-02-13 01:17:09 +08:00
|
|
|
Self::from_superset_unchecked(t.matrix())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-25 18:21:41 +08:00
|
|
|
impl<N1: RealField, N2: RealField + SupersetOf<N1>> SubsetOf<Matrix3<N2>> for UnitComplex<N1> {
|
2017-08-03 01:37:44 +08:00
|
|
|
#[inline]
|
|
|
|
fn to_superset(&self) -> Matrix3<N2> {
|
2017-02-13 01:17:09 +08:00
|
|
|
self.to_homogeneous().to_superset()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
2017-08-03 01:37:44 +08:00
|
|
|
fn is_in_subset(m: &Matrix3<N2>) -> bool {
|
2019-03-23 21:29:07 +08:00
|
|
|
crate::is_convertible::<_, Rotation2<N1>>(m)
|
2017-02-13 01:17:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
2020-03-21 19:16:46 +08:00
|
|
|
fn from_superset_unchecked(m: &Matrix3<N2>) -> Self {
|
2019-03-23 21:29:07 +08:00
|
|
|
let rot: Rotation2<N1> = crate::convert_ref_unchecked(m);
|
2017-02-13 01:17:09 +08:00
|
|
|
Self::from_rotation_matrix(&rot)
|
|
|
|
}
|
|
|
|
}
|
2019-02-19 05:41:46 +08:00
|
|
|
|
2020-03-22 06:22:55 +08:00
|
|
|
impl<N: SimdRealField> From<UnitComplex<N>> for Rotation2<N>
|
2020-04-05 23:15:43 +08:00
|
|
|
where
|
|
|
|
N::Element: SimdRealField,
|
2020-03-22 06:22:55 +08:00
|
|
|
{
|
2019-02-19 05:41:46 +08:00
|
|
|
#[inline]
|
|
|
|
fn from(q: UnitComplex<N>) -> Self {
|
|
|
|
q.to_rotation_matrix()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-22 06:22:55 +08:00
|
|
|
impl<N: SimdRealField> From<Rotation2<N>> for UnitComplex<N>
|
2020-04-05 23:15:43 +08:00
|
|
|
where
|
|
|
|
N::Element: SimdRealField,
|
2020-03-22 06:22:55 +08:00
|
|
|
{
|
2019-02-19 05:41:46 +08:00
|
|
|
#[inline]
|
|
|
|
fn from(q: Rotation2<N>) -> Self {
|
|
|
|
Self::from_rotation_matrix(&q)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-22 06:22:55 +08:00
|
|
|
impl<N: SimdRealField> From<UnitComplex<N>> for Matrix3<N>
|
2020-04-05 23:15:43 +08:00
|
|
|
where
|
|
|
|
N::Element: SimdRealField,
|
2020-03-22 06:22:55 +08:00
|
|
|
{
|
2019-02-19 05:41:46 +08:00
|
|
|
#[inline]
|
|
|
|
fn from(q: UnitComplex<N>) -> Matrix3<N> {
|
|
|
|
q.to_homogeneous()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-22 06:22:55 +08:00
|
|
|
impl<N: SimdRealField> From<UnitComplex<N>> for Matrix2<N>
|
2020-04-05 23:15:43 +08:00
|
|
|
where
|
|
|
|
N::Element: SimdRealField,
|
2020-03-22 06:22:55 +08:00
|
|
|
{
|
2019-02-19 05:41:46 +08:00
|
|
|
#[inline]
|
|
|
|
fn from(q: UnitComplex<N>) -> Self {
|
|
|
|
q.to_rotation_matrix().into_inner()
|
|
|
|
}
|
|
|
|
}
|
2020-03-23 16:16:01 +08:00
|
|
|
|
|
|
|
impl<N: Scalar + Copy + PrimitiveSimdValue> From<[UnitComplex<N::Element>; 2]> for UnitComplex<N>
|
|
|
|
where
|
|
|
|
N: From<[<N as simba::simd::SimdValue>::Element; 2]>,
|
|
|
|
N::Element: Scalar + Copy,
|
|
|
|
{
|
|
|
|
#[inline]
|
|
|
|
fn from(arr: [UnitComplex<N::Element>; 2]) -> Self {
|
|
|
|
Self::new_unchecked(Complex {
|
|
|
|
re: N::from([arr[0].re, arr[1].re]),
|
|
|
|
im: N::from([arr[0].im, arr[1].im]),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<N: Scalar + Copy + PrimitiveSimdValue> From<[UnitComplex<N::Element>; 4]> for UnitComplex<N>
|
|
|
|
where
|
|
|
|
N: From<[<N as simba::simd::SimdValue>::Element; 4]>,
|
|
|
|
N::Element: Scalar + Copy,
|
|
|
|
{
|
|
|
|
#[inline]
|
|
|
|
fn from(arr: [UnitComplex<N::Element>; 4]) -> Self {
|
|
|
|
Self::new_unchecked(Complex {
|
|
|
|
re: N::from([arr[0].re, arr[1].re, arr[2].re, arr[3].re]),
|
|
|
|
im: N::from([arr[0].im, arr[1].im, arr[2].im, arr[3].im]),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<N: Scalar + Copy + PrimitiveSimdValue> From<[UnitComplex<N::Element>; 8]> for UnitComplex<N>
|
|
|
|
where
|
|
|
|
N: From<[<N as simba::simd::SimdValue>::Element; 8]>,
|
|
|
|
N::Element: Scalar + Copy,
|
|
|
|
{
|
|
|
|
#[inline]
|
|
|
|
fn from(arr: [UnitComplex<N::Element>; 8]) -> Self {
|
|
|
|
Self::new_unchecked(Complex {
|
|
|
|
re: N::from([
|
|
|
|
arr[0].re, arr[1].re, arr[2].re, arr[3].re, arr[4].re, arr[5].re, arr[6].re,
|
|
|
|
arr[7].re,
|
|
|
|
]),
|
|
|
|
im: N::from([
|
|
|
|
arr[0].im, arr[1].im, arr[2].im, arr[3].im, arr[4].im, arr[5].im, arr[6].im,
|
|
|
|
arr[7].im,
|
|
|
|
]),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<N: Scalar + Copy + PrimitiveSimdValue> From<[UnitComplex<N::Element>; 16]> for UnitComplex<N>
|
|
|
|
where
|
|
|
|
N: From<[<N as simba::simd::SimdValue>::Element; 16]>,
|
|
|
|
N::Element: Scalar + Copy,
|
|
|
|
{
|
|
|
|
#[inline]
|
|
|
|
fn from(arr: [UnitComplex<N::Element>; 16]) -> Self {
|
|
|
|
Self::new_unchecked(Complex {
|
|
|
|
re: N::from([
|
|
|
|
arr[0].re, arr[1].re, arr[2].re, arr[3].re, arr[4].re, arr[5].re, arr[6].re,
|
|
|
|
arr[7].re, arr[8].re, arr[9].re, arr[10].re, arr[11].re, arr[12].re, arr[13].re,
|
|
|
|
arr[14].re, arr[15].re,
|
|
|
|
]),
|
|
|
|
im: N::from([
|
|
|
|
arr[0].im, arr[1].im, arr[2].im, arr[3].im, arr[4].im, arr[5].im, arr[6].im,
|
|
|
|
arr[7].im, arr[8].im, arr[9].im, arr[10].im, arr[11].im, arr[12].im, arr[13].im,
|
|
|
|
arr[14].im, arr[15].im,
|
|
|
|
]),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|