From bdf0de68cf189b68cfd903061e9d7e8c60a12333 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Crozet=20S=C3=A9bastien?= Date: Sat, 6 Mar 2021 12:38:15 +0100 Subject: [PATCH] Add conversion of Rotation and UnitComplex from/to glam types. --- src/geometry/mod.rs | 4 -- src/third_party/glam/glam_rotation.rs | 64 +++++++++++++++++++++++ src/third_party/glam/glam_unit_complex.rs | 36 +++++++++++++ src/third_party/glam/mod.rs | 2 + 4 files changed, 102 insertions(+), 4 deletions(-) create mode 100644 src/third_party/glam/glam_rotation.rs create mode 100644 src/third_party/glam/glam_unit_complex.rs diff --git a/src/geometry/mod.rs b/src/geometry/mod.rs index ef5e3eff..2675817e 100644 --- a/src/geometry/mod.rs +++ b/src/geometry/mod.rs @@ -23,8 +23,6 @@ mod rotation_simba; // TODO: implement Rotation methods. mod rotation_specialization; mod quaternion; -#[cfg(feature = "alga")] -mod quaternion_alga; mod quaternion_construction; mod quaternion_conversion; mod quaternion_coordinates; @@ -32,8 +30,6 @@ mod quaternion_ops; mod quaternion_simba; mod dual_quaternion; -#[cfg(feature = "alga")] -mod dual_quaternion_alga; mod dual_quaternion_construction; mod dual_quaternion_conversion; mod dual_quaternion_ops; diff --git a/src/third_party/glam/glam_rotation.rs b/src/third_party/glam/glam_rotation.rs new file mode 100644 index 00000000..2db9f50e --- /dev/null +++ b/src/third_party/glam/glam_rotation.rs @@ -0,0 +1,64 @@ +use crate::{Rotation2, Rotation3, UnitQuaternion}; +use glam::{DMat2, DQuat, Mat2, Quat}; + +impl From> for Mat2 { + #[inline] + fn from(e: Rotation2) -> Mat2 { + e.into_inner().into() + } +} + +impl From> for DMat2 { + #[inline] + fn from(e: Rotation2) -> DMat2 { + e.into_inner().into() + } +} + +impl From> for Quat { + #[inline] + fn from(e: Rotation3) -> Quat { + UnitQuaternion::from(e).into() + } +} + +impl From> for DQuat { + #[inline] + fn from(e: Rotation3) -> DQuat { + UnitQuaternion::from(e).into() + } +} + +#[cfg(feature = "convert-glam-unchecked")] +mod unchecked { + use crate::{Rotation2, Rotation3, UnitQuaternion}; + use glam::{DMat2, DQuat, Mat2, Quat}; + + impl From for Rotation2 { + #[inline] + fn from(e: Mat2) -> Rotation2 { + Rotation2::from_matrix_unchecked(e.into()) + } + } + + impl From for Rotation2 { + #[inline] + fn from(e: DMat2) -> Rotation2 { + Rotation2::from_matrix_unchecked(e.into()) + } + } + + impl From for Rotation3 { + #[inline] + fn from(e: Quat) -> Rotation3 { + Rotation3::from(UnitQuaternion::from(e)) + } + } + + impl From for Rotation3 { + #[inline] + fn from(e: DQuat) -> Rotation3 { + Rotation3::from(UnitQuaternion::from(e)) + } + } +} diff --git a/src/third_party/glam/glam_unit_complex.rs b/src/third_party/glam/glam_unit_complex.rs new file mode 100644 index 00000000..c5d9cc6a --- /dev/null +++ b/src/third_party/glam/glam_unit_complex.rs @@ -0,0 +1,36 @@ +use crate::UnitComplex; +use glam::{DMat2, Mat2}; + +impl From> for Mat2 { + #[inline] + fn from(e: UnitComplex) -> Mat2 { + e.to_rotation_matrix().into_inner().into() + } +} + +impl From> for DMat2 { + #[inline] + fn from(e: UnitComplex) -> DMat2 { + e.to_rotation_matrix().into_inner().into() + } +} + +#[cfg(feature = "convert-glam-unchecked")] +mod unchecked { + use crate::{Rotation2, UnitComplex}; + use glam::{DMat2, Mat2}; + + impl From for UnitComplex { + #[inline] + fn from(e: Mat2) -> UnitComplex { + Rotation2::from_matrix_unchecked(e.into()).into() + } + } + + impl From for UnitComplex { + #[inline] + fn from(e: DMat2) -> UnitComplex { + Rotation2::from_matrix_unchecked(e.into()).into() + } + } +} diff --git a/src/third_party/glam/mod.rs b/src/third_party/glam/mod.rs index a0bb8cda..55dc82c1 100644 --- a/src/third_party/glam/mod.rs +++ b/src/third_party/glam/mod.rs @@ -2,3 +2,5 @@ mod glam_isometry; mod glam_matrix; mod glam_point; mod glam_quaternion; +mod glam_rotation; +mod glam_unit_complex;