Implement Abomonation for static-size points

This commit is contained in:
Eduard Bopp 2017-08-14 12:18:47 +02:00
parent 65fa4cf740
commit 49f12a379d
2 changed files with 29 additions and 1 deletions

View File

@ -6,6 +6,9 @@ use approx::ApproxEq;
#[cfg(feature = "serde-serialize")]
use serde::{Serialize, Serializer, Deserialize, Deserializer};
#[cfg(feature = "abomonation-serialize")]
use abomonation::Abomonation;
use core::{Scalar, ColumnVector, OwnedColumnVector};
use core::iter::{MatrixIter, MatrixIterMut};
use core::dimension::{DimName, DimNameSum, DimNameAdd, U1};
@ -75,6 +78,26 @@ impl<'de, N, D, S> Deserialize<'de> for PointBase<N, D, S>
}
}
#[cfg(feature = "abomonation-serialize")]
impl<N, D, S> Abomonation for PointBase<N, D, S>
where N: Scalar,
D: DimName,
S: Storage<N, D, U1>,
ColumnVector<N, D, S>: Abomonation
{
unsafe fn entomb(&self, writer: &mut Vec<u8>) {
self.coords.entomb(writer)
}
unsafe fn embalm(&mut self) {
self.coords.embalm()
}
unsafe fn exhume<'a, 'b>(&'a mut self, bytes: &'b mut [u8]) -> Option<&'b mut [u8]> {
self.coords.exhume(bytes)
}
}
impl<N: Scalar, D: DimName, S: Storage<N, D, U1>> PointBase<N, D, S> {
/// Creates a new point with the given coordinates.
#[inline]

View File

@ -4,13 +4,18 @@ extern crate abomonation;
use rand::random;
use abomonation::{Abomonation, encode, decode};
use nalgebra::Matrix3x4;
use nalgebra::{Matrix3x4, Point3};
#[test]
fn abomonate_matrix3x4() {
assert_encode_and_decode(&random::<Matrix3x4<f32>>());
}
#[test]
fn abomonate_point3() {
assert_encode_and_decode(&random::<Point3<f64>>());
}
fn assert_encode_and_decode<T: Abomonation + PartialEq>(data: &T) {
let mut bytes = Vec::new();
unsafe { encode(data, &mut bytes); }