Implement Abomonation for rotations

This commit is contained in:
Eduard Bopp 2017-08-14 12:41:03 +02:00
parent 308177a7d6
commit f67a7bd324
2 changed files with 28 additions and 1 deletions

View File

@ -5,6 +5,9 @@ use approx::ApproxEq;
#[cfg(feature = "serde-serialize")]
use serde::{Serialize, Serializer, Deserialize, Deserializer};
#[cfg(feature = "abomonation-serialize")]
use abomonation::Abomonation;
use alga::general::Real;
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>
where N: Scalar,
S: Storage<N, D, D> {

View File

@ -4,7 +4,7 @@ extern crate abomonation;
use rand::random;
use abomonation::{Abomonation, encode, decode};
use nalgebra::{DMatrix, Matrix3x4, Point3, Translation3};
use nalgebra::{DMatrix, Matrix3x4, Point3, Translation3, Rotation3};
#[test]
fn abomonate_matrix3x4() {
@ -26,6 +26,11 @@ fn abomonate_translation3() {
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) {
let mut bytes = Vec::new();
unsafe { encode(data, &mut bytes); }