parent
d8fa3ff241
commit
b9513257b8
|
@ -1,4 +1,6 @@
|
||||||
use crate::{Quaternion, SimdRealField};
|
use crate::{Quaternion, SimdRealField};
|
||||||
|
#[cfg(feature = "serde-serialize")]
|
||||||
|
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||||
|
|
||||||
/// A dual quaternion.
|
/// A dual quaternion.
|
||||||
///
|
///
|
||||||
|
@ -27,7 +29,6 @@ use crate::{Quaternion, SimdRealField};
|
||||||
/// See https://github.com/dimforge/nalgebra/issues/487
|
/// See https://github.com/dimforge/nalgebra/issues/487
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(Debug, Default, Eq, PartialEq, Copy, Clone)]
|
#[derive(Debug, Default, Eq, PartialEq, Copy, Clone)]
|
||||||
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
|
|
||||||
pub struct DualQuaternion<N: SimdRealField> {
|
pub struct DualQuaternion<N: SimdRealField> {
|
||||||
/// The real component of the quaternion
|
/// The real component of the quaternion
|
||||||
pub real: Quaternion<N>,
|
pub real: Quaternion<N>,
|
||||||
|
@ -80,3 +81,36 @@ where
|
||||||
*self = self.normalize();
|
*self = self.normalize();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "serde-serialize")]
|
||||||
|
impl<N: SimdRealField> Serialize for DualQuaternion<N>
|
||||||
|
where
|
||||||
|
N: Serialize,
|
||||||
|
{
|
||||||
|
fn serialize<S>(&self, serializer: S) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>
|
||||||
|
where
|
||||||
|
S: Serializer,
|
||||||
|
{
|
||||||
|
self.as_ref().serialize(serializer)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "serde-serialize")]
|
||||||
|
impl<'a, N: SimdRealField> Deserialize<'a> for DualQuaternion<N>
|
||||||
|
where
|
||||||
|
N: Deserialize<'a>,
|
||||||
|
{
|
||||||
|
fn deserialize<Des>(deserializer: Des) -> Result<Self, Des::Error>
|
||||||
|
where
|
||||||
|
Des: Deserializer<'a>,
|
||||||
|
{
|
||||||
|
type Dq<N> = [N; 8];
|
||||||
|
|
||||||
|
let dq: Dq<N> = Dq::<N>::deserialize(deserializer)?;
|
||||||
|
|
||||||
|
Ok(Self {
|
||||||
|
real: Quaternion::new(dq[3], dq[0], dq[1], dq[2]),
|
||||||
|
dual: Quaternion::new(dq[7], dq[4], dq[5], dq[6]),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -4,9 +4,15 @@
|
||||||
//! The tests here only check that the necessary trait implementations are correctly implemented,
|
//! The tests here only check that the necessary trait implementations are correctly implemented,
|
||||||
//! in addition to some sanity checks with example input.
|
//! in addition to some sanity checks with example input.
|
||||||
|
|
||||||
use nalgebra::{DMatrix, MatrixMN, U4, U5};
|
use nalgebra::{MatrixMN, U4, U5};
|
||||||
|
|
||||||
use matrixcompare::{assert_matrix_eq, DenseAccess};
|
#[cfg(feature = "arbitrary")]
|
||||||
|
use nalgebra::DMatrix;
|
||||||
|
|
||||||
|
use matrixcompare::assert_matrix_eq;
|
||||||
|
|
||||||
|
#[cfg(feature = "arbitrary")]
|
||||||
|
use matrixcompare::DenseAccess;
|
||||||
|
|
||||||
#[cfg(feature = "arbitrary")]
|
#[cfg(feature = "arbitrary")]
|
||||||
quickcheck! {
|
quickcheck! {
|
||||||
|
|
Loading…
Reference in New Issue