forked from M-Labs/nalgebra
Implement Abomonation for remaining types
This commit is contained in:
parent
916006f80a
commit
e09af0ca82
@ -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::SubsetOf;
|
use alga::general::SubsetOf;
|
||||||
use alga::linear::NormedSpace;
|
use alga::linear::NormedSpace;
|
||||||
|
|
||||||
@ -36,6 +39,21 @@ impl<'de, T: Deserialize<'de>> Deserialize<'de> for Unit<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "abomonation-serialize")]
|
||||||
|
impl<T: Abomonation> Abomonation for Unit<T> {
|
||||||
|
unsafe fn entomb(&self, writer: &mut Vec<u8>) {
|
||||||
|
self.value.entomb(writer);
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe fn embalm(&mut self) {
|
||||||
|
self.value.embalm();
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe fn exhume<'a, 'b>(&'a mut self, bytes: &'b mut [u8]) -> Option<&'b mut [u8]> {
|
||||||
|
self.value.exhume(bytes)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<T: NormedSpace> Unit<T> {
|
impl<T: NormedSpace> Unit<T> {
|
||||||
/// Normalize the given value and return it wrapped on a `Unit` structure.
|
/// Normalize the given value and return it wrapped on a `Unit` structure.
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -11,6 +11,9 @@ use core::storage::{Storage, OwnedStorage};
|
|||||||
use core::allocator::{Allocator, OwnedAllocator};
|
use core::allocator::{Allocator, OwnedAllocator};
|
||||||
use geometry::{TranslationBase, PointBase};
|
use geometry::{TranslationBase, PointBase};
|
||||||
|
|
||||||
|
#[cfg(feature = "abomonation-serialize")]
|
||||||
|
use abomonation::Abomonation;
|
||||||
|
|
||||||
|
|
||||||
/// An isometry that uses a data storage deduced from the allocator `A`.
|
/// An isometry that uses a data storage deduced from the allocator `A`.
|
||||||
pub type OwnedIsometryBase<N, D, A, R> =
|
pub type OwnedIsometryBase<N, D, A, R> =
|
||||||
@ -32,6 +35,29 @@ pub struct IsometryBase<N: Scalar, D: DimName, S, R> {
|
|||||||
_noconstruct: PhantomData<N>
|
_noconstruct: PhantomData<N>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "abomonation-serialize")]
|
||||||
|
impl<N, D, S, R> Abomonation for IsometryBase<N, D, S, R>
|
||||||
|
where N: Scalar,
|
||||||
|
D: DimName,
|
||||||
|
R: Abomonation,
|
||||||
|
TranslationBase<N, D, S>: Abomonation
|
||||||
|
{
|
||||||
|
unsafe fn entomb(&self, writer: &mut Vec<u8>) {
|
||||||
|
self.rotation.entomb(writer);
|
||||||
|
self.translation.entomb(writer);
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe fn embalm(&mut self) {
|
||||||
|
self.rotation.embalm();
|
||||||
|
self.translation.embalm();
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe fn exhume<'a, 'b>(&'a mut self, bytes: &'b mut [u8]) -> Option<&'b mut [u8]> {
|
||||||
|
self.rotation.exhume(bytes)
|
||||||
|
.and_then(|bytes| self.translation.exhume(bytes))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<N, D: DimName, S, R> IsometryBase<N, D, S, R>
|
impl<N, D: DimName, S, R> IsometryBase<N, D, S, R>
|
||||||
where N: Real,
|
where N: Real,
|
||||||
S: OwnedStorage<N, D, U1>,
|
S: OwnedStorage<N, D, U1>,
|
||||||
|
@ -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;
|
use alga::general::Real;
|
||||||
|
|
||||||
use core::{Unit, ColumnVector, OwnedColumnVector, MatrixSlice, MatrixSliceMut, SquareMatrix,
|
use core::{Unit, ColumnVector, OwnedColumnVector, MatrixSlice, MatrixSliceMut, SquareMatrix,
|
||||||
@ -56,6 +59,24 @@ impl<'de, N, S> Deserialize<'de> for QuaternionBase<N, S>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "abomonation-serialize")]
|
||||||
|
impl<N, S> Abomonation for QuaternionBase<N, S>
|
||||||
|
where N: Real,
|
||||||
|
S: Storage<N, U4, U1>,
|
||||||
|
ColumnVector<N, U4, 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, S> Eq for QuaternionBase<N, S>
|
impl<N, S> Eq for QuaternionBase<N, S>
|
||||||
where N: Real + Eq,
|
where N: Real + Eq,
|
||||||
|
@ -10,6 +10,9 @@ use core::storage::{Storage, OwnedStorage};
|
|||||||
use core::allocator::{Allocator, OwnedAllocator};
|
use core::allocator::{Allocator, OwnedAllocator};
|
||||||
use geometry::{PointBase, TranslationBase, IsometryBase};
|
use geometry::{PointBase, TranslationBase, IsometryBase};
|
||||||
|
|
||||||
|
#[cfg(feature = "abomonation-serialize")]
|
||||||
|
use abomonation::Abomonation;
|
||||||
|
|
||||||
|
|
||||||
/// A similarity that uses a data storage deduced from the allocator `A`.
|
/// A similarity that uses a data storage deduced from the allocator `A`.
|
||||||
pub type OwnedSimilarityBase<N, D, A, R> =
|
pub type OwnedSimilarityBase<N, D, A, R> =
|
||||||
@ -25,6 +28,24 @@ pub struct SimilarityBase<N: Scalar, D: DimName, S, R> {
|
|||||||
scaling: N
|
scaling: N
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[cfg(feature = "abomonation-serialize")]
|
||||||
|
impl<N: Scalar, D: DimName, S, R> Abomonation for SimilarityBase<N, D, S, R>
|
||||||
|
where IsometryBase<N, D, S, R>: Abomonation
|
||||||
|
{
|
||||||
|
unsafe fn entomb(&self, writer: &mut Vec<u8>) {
|
||||||
|
self.isometry.entomb(writer)
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe fn embalm(&mut self) {
|
||||||
|
self.isometry.embalm()
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe fn exhume<'a, 'b>(&'a mut self, bytes: &'b mut [u8]) -> Option<&'b mut [u8]> {
|
||||||
|
self.isometry.exhume(bytes)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<N, D: DimName, S, R> SimilarityBase<N, D, S, R>
|
impl<N, D: DimName, S, R> SimilarityBase<N, D, S, R>
|
||||||
where N: Real,
|
where N: Real,
|
||||||
S: OwnedStorage<N, D, U1>,
|
S: OwnedStorage<N, D, U1>,
|
||||||
|
@ -89,13 +89,16 @@ an optimized set of tools for computer graphics and physics. Those features incl
|
|||||||
|
|
||||||
#[cfg(feature = "arbitrary")]
|
#[cfg(feature = "arbitrary")]
|
||||||
extern crate quickcheck;
|
extern crate quickcheck;
|
||||||
|
|
||||||
#[cfg(feature = "serde")]
|
#[cfg(feature = "serde")]
|
||||||
extern crate serde;
|
extern crate serde;
|
||||||
#[cfg(feature = "serde")]
|
#[cfg(feature = "serde")]
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate serde_derive;
|
extern crate serde_derive;
|
||||||
|
|
||||||
#[cfg(feature = "abomonation")]
|
#[cfg(feature = "abomonation")]
|
||||||
extern crate abomonation;
|
extern crate abomonation;
|
||||||
|
|
||||||
extern crate num_traits as num;
|
extern crate num_traits as num;
|
||||||
extern crate num_complex;
|
extern crate num_complex;
|
||||||
extern crate rand;
|
extern crate rand;
|
||||||
|
@ -4,7 +4,10 @@ extern crate abomonation;
|
|||||||
|
|
||||||
use rand::random;
|
use rand::random;
|
||||||
use abomonation::{Abomonation, encode, decode};
|
use abomonation::{Abomonation, encode, decode};
|
||||||
use nalgebra::{DMatrix, Matrix3x4, Point3, Translation3, Rotation3};
|
use nalgebra::{
|
||||||
|
DMatrix, Matrix3x4, Point3, Translation3, Rotation3, Isometry3, Quaternion,
|
||||||
|
IsometryMatrix3, Similarity3, SimilarityMatrix3
|
||||||
|
};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn abomonate_dmatrix() {
|
fn abomonate_dmatrix() {
|
||||||
@ -25,6 +28,11 @@ test_abomonation! {
|
|||||||
abomonate_point3, Point3<f32>;
|
abomonate_point3, Point3<f32>;
|
||||||
abomonate_translation3, Translation3<f64>;
|
abomonate_translation3, Translation3<f64>;
|
||||||
abomonate_rotation3, Rotation3<f64>;
|
abomonate_rotation3, Rotation3<f64>;
|
||||||
|
abomonate_isometry3, Isometry3<f32>;
|
||||||
|
abomonate_isometry_matrix3, IsometryMatrix3<f64>;
|
||||||
|
abomonate_similarity3, Similarity3<f32>;
|
||||||
|
abomonate_similarity_matrix3, SimilarityMatrix3<f32>;
|
||||||
|
abomonate_quaternion, Quaternion<f32>;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn assert_encode_and_decode<T: Abomonation + PartialEq>(data: &T) {
|
fn assert_encode_and_decode<T: Abomonation + PartialEq>(data: &T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user