Mint quaternions
This commit is contained in:
parent
2cd79851c3
commit
b0127ab5dc
|
@ -5,6 +5,8 @@ use alga::linear::Rotation as AlgaRotation;
|
|||
|
||||
use core::{Vector4, Matrix4};
|
||||
use core::dimension::U3;
|
||||
#[cfg(feature = "mint")]
|
||||
use core::storage::Storage;
|
||||
use geometry::{Quaternion, UnitQuaternion, Rotation, Isometry, Similarity,
|
||||
Transform, SuperTCategoryOf, TAffine, Translation,
|
||||
Rotation3, Point3};
|
||||
|
@ -21,6 +23,9 @@ use geometry::{Quaternion, UnitQuaternion, Rotation, Isometry, Similarity,
|
|||
* UnitQuaternion -> Transform<U3>
|
||||
* UnitQuaternion -> Matrix<U4> (homogeneous)
|
||||
*
|
||||
* mint::Quaternion <-> Quaternion
|
||||
* UnitQuaternion -> mint::Quaternion
|
||||
*
|
||||
* NOTE:
|
||||
* UnitQuaternion -> Quaternion is already provided by: Unit<T> -> T
|
||||
*/
|
||||
|
@ -166,3 +171,43 @@ impl<N1: Real, N2: Real + SupersetOf<N1>> SubsetOf<Matrix4<N2>> for UnitQuaterni
|
|||
Self::from_rotation_matrix(&rot)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "mint")]
|
||||
impl<N, S> From<mint::Quaternion<N>> for QuaternionBase<N, S>
|
||||
where
|
||||
N: Real,
|
||||
S: OwnedStorage<N, U4, U1>,
|
||||
S::Alloc: OwnedAllocator<N, U4, U1, S>,
|
||||
{
|
||||
fn from(q: mint::Quaternion<N>) -> Self {
|
||||
QuaternionBase::new(q.s, q.v.x, q.v.y, q.v.z)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "mint")]
|
||||
impl<N: Real, S: Storage<N, U4, U1>> Into<mint::Quaternion<N>> for QuaternionBase<N, S> {
|
||||
fn into(self) -> mint::Quaternion<N> {
|
||||
mint::Quaternion {
|
||||
v: mint::Vector3 {
|
||||
x: self[0],
|
||||
y: self[1],
|
||||
z: self[2],
|
||||
},
|
||||
s: self[3],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "mint")]
|
||||
impl<N: Real, S: Storage<N, U4, U1>> Into<mint::Quaternion<N>> for UnitQuaternionBase<N, S> {
|
||||
fn into(self) -> mint::Quaternion<N> {
|
||||
mint::Quaternion {
|
||||
v: mint::Vector3 {
|
||||
x: self[0],
|
||||
y: self[1],
|
||||
z: self[2],
|
||||
},
|
||||
s: self[3],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,8 @@ use na::{
|
|||
Matrix6x2, Matrix6x3, Matrix6x4, Matrix6x5,
|
||||
Point3, Translation3, Isometry3, Similarity3, Affine3,
|
||||
Projective3, Transform3, Rotation3, UnitQuaternion};
|
||||
#[cfg(feature = "mint")]
|
||||
use na::Quaternion;
|
||||
|
||||
|
||||
#[cfg(feature = "arbitrary")]
|
||||
|
@ -283,3 +285,18 @@ mint_vector_conversion!(
|
|||
mint_vector_conversion_3, Vector3, 3;
|
||||
mint_vector_conversion_4, Vector4, 4;
|
||||
);
|
||||
|
||||
|
||||
#[test]
|
||||
fn mint_quaternion_conversions() {
|
||||
let q = Quaternion::new(0.1f64, 0.2, 0.3, 0.4);
|
||||
let mq: mint::Quaternion<f64> = q.into();
|
||||
let q2 = Quaternion::from(mq);
|
||||
|
||||
assert_eq!(mq.v.x, q[0]);
|
||||
assert_eq!(mq.v.y, q[1]);
|
||||
assert_eq!(mq.v.z, q[2]);
|
||||
assert_eq!(mq.s, q[3]);
|
||||
|
||||
assert_eq!(q, q2);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue