Skip to content

Commit

Permalink
Use quaternion array for mint conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
sjb3d committed Dec 23, 2023
1 parent 05a0d94 commit 50085fa
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
30 changes: 30 additions & 0 deletions src/impl_mint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,3 +190,33 @@ from_mat3s!(mint::ColumnMatrix3<f64> => DMat3);
from_mat4s!(mint::ColumnMatrix4<f32> => Mat4);
#[cfg(feature = "f64")]
from_mat4s!(mint::ColumnMatrix4<f64> => 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<f32> => Rotor3);
#[cfg(feature = "f64")]
from_mat4s!(mint::Quaternion<f64> => DRotor3);

0 comments on commit 50085fa

Please sign in to comment.