From 49f12a379d0dfcef93f0b9de1595329732d34eff Mon Sep 17 00:00:00 2001 From: Eduard Bopp Date: Mon, 14 Aug 2017 12:18:47 +0200 Subject: [PATCH] Implement Abomonation for static-size points --- src/geometry/point.rs | 23 +++++++++++++++++++++++ tests/abomonation.rs | 7 ++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/geometry/point.rs b/src/geometry/point.rs index 53f914a2..8587e528 100644 --- a/src/geometry/point.rs +++ b/src/geometry/point.rs @@ -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 } } +#[cfg(feature = "abomonation-serialize")] +impl Abomonation for PointBase + where N: Scalar, + D: DimName, + S: Storage, + ColumnVector: Abomonation +{ + unsafe fn entomb(&self, writer: &mut Vec) { + 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> PointBase { /// Creates a new point with the given coordinates. #[inline] diff --git a/tests/abomonation.rs b/tests/abomonation.rs index 57696cea..1da6ba3c 100644 --- a/tests/abomonation.rs +++ b/tests/abomonation.rs @@ -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::>()); } +#[test] +fn abomonate_point3() { + assert_encode_and_decode(&random::>()); +} + fn assert_encode_and_decode(data: &T) { let mut bytes = Vec::new(); unsafe { encode(data, &mut bytes); }