From d6ff5ba3481b80c85854b7cc30b7df16ec0f9054 Mon Sep 17 00:00:00 2001 From: Simon Brown Date: Tue, 2 Jan 2024 14:00:57 +0000 Subject: [PATCH] Add mint quaternion support (#167) * Use quaternion array for mint conversion * Fix copy paste in f64 conversion --- CHANGELOG.md | 1 + src/impl_mint.rs | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ba3d70a..ef4c124 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - Add `mint` type conversions for integer vectors - Implement Serialize and Deserialize for `Similarity` - Implement Serialize and Deserialize for f64 types: `DBivec`, `DRotor`, `DIsometry`, `DSimilarity` +- Add type conversion between `mint` quaternion and `Rotor3` ## 0.9.2 diff --git a/src/impl_mint.rs b/src/impl_mint.rs index b78af63..e36ecc8 100644 --- a/src/impl_mint.rs +++ b/src/impl_mint.rs @@ -190,3 +190,33 @@ from_mat3s!(mint::ColumnMatrix3 => DMat3); from_mat4s!(mint::ColumnMatrix4 => Mat4); #[cfg(feature = "f64")] from_mat4s!(mint::ColumnMatrix4 => DMat4); + +macro_rules! from_quat { + ($($minttype:ty => $uvtype:ty),+) => { + $(impl From<$minttype> for $uvtype { + #[inline] + fn from(q: $minttype) -> Self { + Self::from_quaternion_array([q.v.x, q.v.y, q.v.z, q.s]) + } + } + + impl From<$uvtype> for $minttype { + #[inline] + fn from(r: $uvtype) -> Self { + let arr = r.into_quaternion_array(); + Self { + v: mint::Vector3 { + x: arr[0], + y: arr[1], + z: arr[2], + }, + s: arr[3], + } + } + })+ + } +} + +from_quat!(mint::Quaternion => Rotor3); +#[cfg(feature = "f64")] +from_quat!(mint::Quaternion => DRotor3);