Implement Abomonation for rotations
This commit is contained in:
parent
308177a7d6
commit
f67a7bd324
|
@ -5,6 +5,9 @@ use approx::ApproxEq;
|
||||||
#[cfg(feature = "serde-serialize")]
|
#[cfg(feature = "serde-serialize")]
|
||||||
use serde::{Serialize, Serializer, Deserialize, Deserializer};
|
use serde::{Serialize, Serializer, Deserialize, Deserializer};
|
||||||
|
|
||||||
|
#[cfg(feature = "abomonation-serialize")]
|
||||||
|
use abomonation::Abomonation;
|
||||||
|
|
||||||
use alga::general::Real;
|
use alga::general::Real;
|
||||||
|
|
||||||
use core::{SquareMatrix, Scalar, OwnedSquareMatrix};
|
use core::{SquareMatrix, Scalar, OwnedSquareMatrix};
|
||||||
|
@ -49,6 +52,25 @@ impl<'de, N, D, S> Deserialize<'de> for RotationBase<N, D, S>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "abomonation-serialize")]
|
||||||
|
impl<N, D, S> Abomonation for RotationBase<N, D, S>
|
||||||
|
where N: Scalar,
|
||||||
|
D: DimName,
|
||||||
|
SquareMatrix<N, D, S>: Abomonation
|
||||||
|
{
|
||||||
|
unsafe fn entomb(&self, writer: &mut Vec<u8>) {
|
||||||
|
self.matrix.entomb(writer)
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe fn embalm(&mut self) {
|
||||||
|
self.matrix.embalm()
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe fn exhume<'a, 'b>(&'a mut self, bytes: &'b mut [u8]) -> Option<&'b mut [u8]> {
|
||||||
|
self.matrix.exhume(bytes)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<N: Scalar, D: DimName, S: Storage<N, D, D>> RotationBase<N, D, S>
|
impl<N: Scalar, D: DimName, S: Storage<N, D, D>> RotationBase<N, D, S>
|
||||||
where N: Scalar,
|
where N: Scalar,
|
||||||
S: Storage<N, D, D> {
|
S: Storage<N, D, D> {
|
||||||
|
|
|
@ -4,7 +4,7 @@ extern crate abomonation;
|
||||||
|
|
||||||
use rand::random;
|
use rand::random;
|
||||||
use abomonation::{Abomonation, encode, decode};
|
use abomonation::{Abomonation, encode, decode};
|
||||||
use nalgebra::{DMatrix, Matrix3x4, Point3, Translation3};
|
use nalgebra::{DMatrix, Matrix3x4, Point3, Translation3, Rotation3};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn abomonate_matrix3x4() {
|
fn abomonate_matrix3x4() {
|
||||||
|
@ -26,6 +26,11 @@ fn abomonate_translation3() {
|
||||||
assert_encode_and_decode(&random::<Translation3<f32>>());
|
assert_encode_and_decode(&random::<Translation3<f32>>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn abomonate_rotation3() {
|
||||||
|
assert_encode_and_decode(&random::<Rotation3<f64>>());
|
||||||
|
}
|
||||||
|
|
||||||
fn assert_encode_and_decode<T: Abomonation + PartialEq>(data: &T) {
|
fn assert_encode_and_decode<T: Abomonation + PartialEq>(data: &T) {
|
||||||
let mut bytes = Vec::new();
|
let mut bytes = Vec::new();
|
||||||
unsafe { encode(data, &mut bytes); }
|
unsafe { encode(data, &mut bytes); }
|
||||||
|
|
Loading…
Reference in New Issue