Update impls of abomonation.
This commit is contained in:
parent
0ec7dc4461
commit
378b39db9c
@ -1,5 +1,7 @@
|
||||
use num::Zero;
|
||||
use num_complex::Complex;
|
||||
#[cfg(feature = "abomonation-serialize")]
|
||||
use std::io::{Result as IOResult, Write};
|
||||
|
||||
use approx::{AbsDiffEq, RelativeEq, UlpsEq};
|
||||
use std::any::TypeId;
|
||||
@ -125,17 +127,17 @@ where
|
||||
|
||||
#[cfg(feature = "abomonation-serialize")]
|
||||
impl<N: Scalar, R: Dim, C: Dim, S: Abomonation> Abomonation for Matrix<N, R, C, S> {
|
||||
unsafe fn entomb(&self, writer: &mut Vec<u8>) {
|
||||
unsafe fn entomb<W: Write>(&self, writer: &mut W) -> IOResult<()> {
|
||||
self.data.entomb(writer)
|
||||
}
|
||||
|
||||
unsafe fn embalm(&mut self) {
|
||||
self.data.embalm()
|
||||
}
|
||||
|
||||
unsafe fn exhume<'a, 'b>(&'a mut self, bytes: &'b mut [u8]) -> Option<&'b mut [u8]> {
|
||||
self.data.exhume(bytes)
|
||||
}
|
||||
|
||||
fn extent(&self) -> usize {
|
||||
self.data.extent()
|
||||
}
|
||||
}
|
||||
|
||||
impl<N: Scalar, R: Dim, C: Dim, S> Matrix<N, R, C, S> {
|
||||
|
@ -1,29 +1,31 @@
|
||||
use std::ops::{Deref, DerefMut, Mul};
|
||||
use std::fmt::{self, Debug, Formatter};
|
||||
use std::hash::{Hash, Hasher};
|
||||
#[cfg(feature = "abomonation-serialize")]
|
||||
use std::io::{Result as IOResult, Write};
|
||||
use std::ops::{Deref, DerefMut, Mul};
|
||||
|
||||
#[cfg(feature = "serde-serialize")]
|
||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||
#[cfg(feature = "serde-serialize")]
|
||||
use serde::ser::SerializeSeq;
|
||||
#[cfg(feature = "serde-serialize")]
|
||||
use serde::de::{Error, SeqAccess, Visitor};
|
||||
#[cfg(feature = "serde-serialize")]
|
||||
use std::mem;
|
||||
use serde::ser::SerializeSeq;
|
||||
#[cfg(feature = "serde-serialize")]
|
||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||
#[cfg(feature = "serde-serialize")]
|
||||
use std::marker::PhantomData;
|
||||
#[cfg(feature = "serde-serialize")]
|
||||
use std::mem;
|
||||
|
||||
#[cfg(feature = "abomonation-serialize")]
|
||||
use abomonation::Abomonation;
|
||||
|
||||
use typenum::Prod;
|
||||
use generic_array::{ArrayLength, GenericArray};
|
||||
use typenum::Prod;
|
||||
|
||||
use base::Scalar;
|
||||
use base::dimension::{DimName, U1};
|
||||
use base::storage::{ContiguousStorage, ContiguousStorageMut, Owned, Storage, StorageMut};
|
||||
use base::allocator::Allocator;
|
||||
use base::default_allocator::DefaultAllocator;
|
||||
use base::dimension::{DimName, U1};
|
||||
use base::storage::{ContiguousStorage, ContiguousStorageMut, Owned, Storage, StorageMut};
|
||||
use base::Scalar;
|
||||
|
||||
/*
|
||||
*
|
||||
@ -360,16 +362,12 @@ where
|
||||
Prod<R::Value, C::Value>: ArrayLength<N>,
|
||||
N: Abomonation,
|
||||
{
|
||||
unsafe fn entomb(&self, writer: &mut Vec<u8>) {
|
||||
unsafe fn entomb<W: Write>(&self, writer: &mut W) -> IOResult<()> {
|
||||
for element in self.data.as_slice() {
|
||||
element.entomb(writer);
|
||||
element.entomb(writer)?;
|
||||
}
|
||||
}
|
||||
|
||||
unsafe fn embalm(&mut self) {
|
||||
for element in self.data.as_mut_slice() {
|
||||
element.embalm();
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
unsafe fn exhume<'a, 'b>(&'a mut self, mut bytes: &'b mut [u8]) -> Option<&'b mut [u8]> {
|
||||
@ -383,4 +381,11 @@ where
|
||||
}
|
||||
Some(bytes)
|
||||
}
|
||||
|
||||
fn extent(&self) -> usize {
|
||||
self.data
|
||||
.as_slice()
|
||||
.iter()
|
||||
.fold(0, |acc, e| acc + e.extent())
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,5 @@
|
||||
#[cfg(feature = "abomonation-serialize")]
|
||||
use std::io::{Result as IOResult, Write};
|
||||
use std::ops::Deref;
|
||||
|
||||
#[cfg(all(feature = "alloc", not(feature = "std")))]
|
||||
@ -238,17 +240,17 @@ where
|
||||
|
||||
#[cfg(feature = "abomonation-serialize")]
|
||||
impl<N: Abomonation, R: Dim, C: Dim> Abomonation for MatrixVec<N, R, C> {
|
||||
unsafe fn entomb(&self, writer: &mut Vec<u8>) {
|
||||
unsafe fn entomb<W: Write>(&self, writer: &mut W) -> IOResult<()> {
|
||||
self.data.entomb(writer)
|
||||
}
|
||||
|
||||
unsafe fn embalm(&mut self) {
|
||||
self.data.embalm()
|
||||
}
|
||||
|
||||
unsafe fn exhume<'a, 'b>(&'a mut self, bytes: &'b mut [u8]) -> Option<&'b mut [u8]> {
|
||||
self.data.exhume(bytes)
|
||||
}
|
||||
|
||||
fn extent(&self) -> usize {
|
||||
self.data.extent()
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl<N: Scalar, R: DimName> ContiguousStorage<N, R, Dynamic> for MatrixVec<N, R, Dynamic>
|
||||
|
@ -1,4 +1,6 @@
|
||||
use approx::RelativeEq;
|
||||
#[cfg(feature = "abomonation-serialize")]
|
||||
use std::io::{Result as IOResult, Write};
|
||||
use std::mem;
|
||||
use std::ops::{Deref, Neg};
|
||||
|
||||
@ -42,12 +44,12 @@ 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 entomb<W: Write>(&self, writer: &mut W) -> IOResult<()> {
|
||||
self.value.entomb(writer)
|
||||
}
|
||||
|
||||
unsafe fn embalm(&mut self) {
|
||||
self.value.embalm();
|
||||
fn extent(&self) -> usize {
|
||||
self.value.extent()
|
||||
}
|
||||
|
||||
unsafe fn exhume<'a, 'b>(&'a mut self, bytes: &'b mut [u8]) -> Option<&'b mut [u8]> {
|
||||
|
@ -1,6 +1,8 @@
|
||||
use approx::{AbsDiffEq, RelativeEq, UlpsEq};
|
||||
use std::fmt;
|
||||
use std::hash;
|
||||
#[cfg(feature = "abomonation-serialize")]
|
||||
use std::io::{Result as IOResult, Write};
|
||||
use std::marker::PhantomData;
|
||||
|
||||
#[cfg(feature = "serde-serialize")]
|
||||
@ -65,14 +67,13 @@ where
|
||||
Translation<N, D>: Abomonation,
|
||||
DefaultAllocator: Allocator<N, D>,
|
||||
{
|
||||
unsafe fn entomb(&self, writer: &mut Vec<u8>) {
|
||||
self.rotation.entomb(writer);
|
||||
self.translation.entomb(writer);
|
||||
unsafe fn entomb<W: Write>(&self, writer: &mut W) -> IOResult<()> {
|
||||
self.rotation.entomb(writer)?;
|
||||
self.translation.entomb(writer)
|
||||
}
|
||||
|
||||
unsafe fn embalm(&mut self) {
|
||||
self.rotation.embalm();
|
||||
self.translation.embalm();
|
||||
fn extent(&self) -> usize {
|
||||
self.rotation.extent() + self.translation.extent()
|
||||
}
|
||||
|
||||
unsafe fn exhume<'a, 'b>(&'a mut self, bytes: &'b mut [u8]) -> Option<&'b mut [u8]> {
|
||||
@ -253,7 +254,8 @@ where
|
||||
) -> bool {
|
||||
self.translation
|
||||
.relative_eq(&other.translation, epsilon, max_relative)
|
||||
&& self.rotation
|
||||
&& self
|
||||
.rotation
|
||||
.relative_eq(&other.rotation, epsilon, max_relative)
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,8 @@ use num::One;
|
||||
use std::cmp::Ordering;
|
||||
use std::fmt;
|
||||
use std::hash;
|
||||
#[cfg(feature = "abomonation-serialize")]
|
||||
use std::io::{Result as IOResult, Write};
|
||||
|
||||
#[cfg(feature = "serde-serialize")]
|
||||
use serde;
|
||||
@ -92,12 +94,12 @@ where
|
||||
VectorN<N, D>: Abomonation,
|
||||
DefaultAllocator: Allocator<N, D>,
|
||||
{
|
||||
unsafe fn entomb(&self, writer: &mut Vec<u8>) {
|
||||
unsafe fn entomb<W: Write>(&self, writer: &mut W) -> IOResult<()> {
|
||||
self.coords.entomb(writer)
|
||||
}
|
||||
|
||||
unsafe fn embalm(&mut self) {
|
||||
self.coords.embalm()
|
||||
fn extent(&self) -> usize {
|
||||
self.coords.extent()
|
||||
}
|
||||
|
||||
unsafe fn exhume<'a, 'b>(&'a mut self, bytes: &'b mut [u8]) -> Option<&'b mut [u8]> {
|
||||
|
@ -2,6 +2,8 @@ use approx::{AbsDiffEq, RelativeEq, UlpsEq};
|
||||
use num::Zero;
|
||||
use std::fmt;
|
||||
use std::hash;
|
||||
#[cfg(feature = "abomonation-serialize")]
|
||||
use std::io::{Result as IOResult, Write};
|
||||
|
||||
#[cfg(feature = "serde-serialize")]
|
||||
use base::storage::Owned;
|
||||
@ -33,12 +35,12 @@ impl<N: Real> Abomonation for Quaternion<N>
|
||||
where
|
||||
Vector4<N>: Abomonation,
|
||||
{
|
||||
unsafe fn entomb(&self, writer: &mut Vec<u8>) {
|
||||
unsafe fn entomb<W: Write>(&self, writer: &mut W) -> IOResult<()> {
|
||||
self.coords.entomb(writer)
|
||||
}
|
||||
|
||||
unsafe fn embalm(&mut self) {
|
||||
self.coords.embalm()
|
||||
fn extent(&self) -> usize {
|
||||
self.coords.extent()
|
||||
}
|
||||
|
||||
unsafe fn exhume<'a, 'b>(&'a mut self, bytes: &'b mut [u8]) -> Option<&'b mut [u8]> {
|
||||
|
@ -2,6 +2,8 @@ use approx::{AbsDiffEq, RelativeEq, UlpsEq};
|
||||
use num::{One, Zero};
|
||||
use std::fmt;
|
||||
use std::hash;
|
||||
#[cfg(feature = "abomonation-serialize")]
|
||||
use std::io::{Result as IOResult, Write};
|
||||
|
||||
#[cfg(feature = "serde-serialize")]
|
||||
use serde;
|
||||
@ -64,12 +66,12 @@ where
|
||||
MatrixN<N, D>: Abomonation,
|
||||
DefaultAllocator: Allocator<N, D, D>,
|
||||
{
|
||||
unsafe fn entomb(&self, writer: &mut Vec<u8>) {
|
||||
unsafe fn entomb<W: Write>(&self, writer: &mut W) -> IOResult<()> {
|
||||
self.matrix.entomb(writer)
|
||||
}
|
||||
|
||||
unsafe fn embalm(&mut self) {
|
||||
self.matrix.embalm()
|
||||
fn extent(&self) -> usize {
|
||||
self.matrix.extent()
|
||||
}
|
||||
|
||||
unsafe fn exhume<'a, 'b>(&'a mut self, bytes: &'b mut [u8]) -> Option<&'b mut [u8]> {
|
||||
|
@ -1,6 +1,8 @@
|
||||
use approx::{AbsDiffEq, RelativeEq, UlpsEq};
|
||||
use std::fmt;
|
||||
use std::hash;
|
||||
#[cfg(feature = "abomonation-serialize")]
|
||||
use std::io::{Result as IOResult, Write};
|
||||
|
||||
#[cfg(feature = "serde-serialize")]
|
||||
use serde;
|
||||
@ -58,12 +60,12 @@ where
|
||||
Isometry<N, D, R>: Abomonation,
|
||||
DefaultAllocator: Allocator<N, D>,
|
||||
{
|
||||
unsafe fn entomb(&self, writer: &mut Vec<u8>) {
|
||||
unsafe fn entomb<W: Write>(&self, writer: &mut W) -> IOResult<()> {
|
||||
self.isometry.entomb(writer)
|
||||
}
|
||||
|
||||
unsafe fn embalm(&mut self) {
|
||||
self.isometry.embalm()
|
||||
fn extent(&self) -> usize {
|
||||
self.isometry.extent()
|
||||
}
|
||||
|
||||
unsafe fn exhume<'a, 'b>(&'a mut self, bytes: &'b mut [u8]) -> Option<&'b mut [u8]> {
|
||||
@ -328,7 +330,8 @@ where
|
||||
) -> bool {
|
||||
self.isometry
|
||||
.relative_eq(&other.isometry, epsilon, max_relative)
|
||||
&& self.scaling
|
||||
&& self
|
||||
.scaling
|
||||
.relative_eq(&other.scaling, epsilon, max_relative)
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,8 @@ use approx::{AbsDiffEq, RelativeEq, UlpsEq};
|
||||
use num::{One, Zero};
|
||||
use std::fmt;
|
||||
use std::hash;
|
||||
#[cfg(feature = "abomonation-serialize")]
|
||||
use std::io::{Result as IOResult, Write};
|
||||
|
||||
#[cfg(feature = "serde-serialize")]
|
||||
use serde;
|
||||
@ -64,12 +66,12 @@ where
|
||||
VectorN<N, D>: Abomonation,
|
||||
DefaultAllocator: Allocator<N, D>,
|
||||
{
|
||||
unsafe fn entomb(&self, writer: &mut Vec<u8>) {
|
||||
unsafe fn entomb<W: Write>(&self, writer: &mut W) -> IOResult<()> {
|
||||
self.vector.entomb(writer)
|
||||
}
|
||||
|
||||
unsafe fn embalm(&mut self) {
|
||||
self.vector.embalm()
|
||||
fn extent(&self) -> usize {
|
||||
self.vector.extent()
|
||||
}
|
||||
|
||||
unsafe fn exhume<'a, 'b>(&'a mut self, bytes: &'b mut [u8]) -> Option<&'b mut [u8]> {
|
||||
|
Loading…
Reference in New Issue
Block a user