forked from M-Labs/nalgebra
Implement Abomonation for static-size points
This commit is contained in:
parent
65fa4cf740
commit
49f12a379d
@ -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]
|
||||
|
@ -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); }
|
||||
|
Loading…
Reference in New Issue
Block a user