forked from M-Labs/nalgebra
Implement Abomonation for translations
This commit is contained in:
parent
7c3a05f668
commit
308177a7d6
@ -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, ClosedNeg};
|
use alga::general::{Real, ClosedNeg};
|
||||||
|
|
||||||
use core::{Scalar, ColumnVector, OwnedSquareMatrix};
|
use core::{Scalar, ColumnVector, OwnedSquareMatrix};
|
||||||
@ -50,6 +53,25 @@ impl<'de, N, D, S> Deserialize<'de> for TranslationBase<N, D, S>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "abomonation-serialize")]
|
||||||
|
impl<N, D, S> Abomonation for TranslationBase<N, D, S>
|
||||||
|
where N: Scalar,
|
||||||
|
D: DimName,
|
||||||
|
ColumnVector<N, D, S>: Abomonation
|
||||||
|
{
|
||||||
|
unsafe fn entomb(&self, writer: &mut Vec<u8>) {
|
||||||
|
self.vector.entomb(writer)
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe fn embalm(&mut self) {
|
||||||
|
self.vector.embalm()
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe fn exhume<'a, 'b>(&'a mut self, bytes: &'b mut [u8]) -> Option<&'b mut [u8]> {
|
||||||
|
self.vector.exhume(bytes)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<N, D: DimName, S> TranslationBase<N, D, S>
|
impl<N, D: DimName, S> TranslationBase<N, D, S>
|
||||||
where N: Scalar,
|
where N: Scalar,
|
||||||
S: Storage<N, D, U1> {
|
S: Storage<N, D, U1> {
|
||||||
|
@ -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};
|
use nalgebra::{DMatrix, Matrix3x4, Point3, Translation3};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn abomonate_matrix3x4() {
|
fn abomonate_matrix3x4() {
|
||||||
@ -21,6 +21,11 @@ fn abomonate_dmatrix() {
|
|||||||
assert_encode_and_decode(&DMatrix::<f32>::new_random(3, 5));
|
assert_encode_and_decode(&DMatrix::<f32>::new_random(3, 5));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn abomonate_translation3() {
|
||||||
|
assert_encode_and_decode(&random::<Translation3<f32>>());
|
||||||
|
}
|
||||||
|
|
||||||
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
Block a user