From 9a98b0cf24648502cc05d89254b535bb75fd881d Mon Sep 17 00:00:00 2001 From: zyansheep Date: Wed, 13 Jul 2022 23:02:17 -0400 Subject: [PATCH] various implementations --- Cargo.toml | 4 ++-- src/base/array_storage.rs | 6 +++--- src/base/unit.rs | 7 +++++-- src/geometry/dual_quaternion.rs | 6 +++++- src/geometry/isometry.rs | 7 ++++++- src/geometry/orthographic.rs | 6 +++++- src/geometry/perspective.rs | 6 +++++- src/geometry/quaternion.rs | 6 +++++- src/geometry/rotation.rs | 6 +++++- src/geometry/scale.rs | 6 +++++- src/geometry/similarity.rs | 7 ++++++- src/geometry/translation.rs | 6 +++++- tests/core/rkyv.rs | 32 ++++++++++++++++++++++++-------- 13 files changed, 81 insertions(+), 24 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 7c70eee1..0d17f8ac 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -71,7 +71,7 @@ nalgebra-macros = { version = "0.1", path = "nalgebra-macros", optional = true } typenum = "1.12" rand-package = { package = "rand", version = "0.8", optional = true, default-features = false } num-traits = { version = "0.2", default-features = false } -num-complex = { version = "0.4", default-features = false } +num-complex = { version = "0.4", default-features = false } # { version = "0.4", default-features = false } num-rational = { version = "0.4", default-features = false } approx = { version = "0.5", default-features = false } simba = { version = "0.7", default-features = false } @@ -80,7 +80,7 @@ rand_distr = { version = "0.4", default-features = false, optional = true } matrixmultiply = { version = "0.3", optional = true } serde = { version = "1.0", default-features = false, features = [ "derive" ], optional = true } rkyv = { version = "0.7", optional = true } -rkyv_wrappers = { git = "https://github.com/rkyv/rkyv_contrib", optional = true } +rkyv_wrappers = { git = "https://github.com/rkyv/rkyv_contrib", optional = true } bytecheck = { version = "~0.6.1", optional = true } mint = { version = "0.5", optional = true } quickcheck = { version = "1", optional = true } diff --git a/src/base/array_storage.rs b/src/base/array_storage.rs index cd534baa..457fa35e 100644 --- a/src/base/array_storage.rs +++ b/src/base/array_storage.rs @@ -30,9 +30,9 @@ use std::mem; #[cfg_attr( feature = "rkyv-serialize-no-std", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize), - archive(as = "Self", bound(archive = " - T: rkyv::Archive, - [[T; R]; C]: rkyv::Archive + archive(as = "ArrayStorage", bound(archive = " + T: rkyv::Archive, + [[T; R]; C]: rkyv::Archive ")) )] #[cfg_attr(feature = "rkyv-serialize", derive(bytecheck::CheckBytes))] diff --git a/src/base/unit.rs b/src/base/unit.rs index 6fc00092..27588af0 100644 --- a/src/base/unit.rs +++ b/src/base/unit.rs @@ -21,11 +21,14 @@ use crate::{Dim, Matrix, OMatrix, RealField, Scalar, SimdComplexField, SimdRealF /// in their documentation, read their dedicated pages directly. #[repr(transparent)] #[derive(Clone, Hash, Copy)] -#[cfg_attr(feature = "rkyv-serialize", derive(bytecheck::CheckBytes))] #[cfg_attr( feature = "rkyv-serialize-no-std", - derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize) + derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize), + archive(as = "Unit", bound(archive = " + T: rkyv::Archive, + ")) )] +#[cfg_attr(feature = "rkyv-serialize", derive(bytecheck::CheckBytes))] // #[cfg_attr(feature = "cuda", derive(cust_core::DeviceCopy))] pub struct Unit { pub(crate) value: T, diff --git a/src/geometry/dual_quaternion.rs b/src/geometry/dual_quaternion.rs index 6f1b7053..1d488d83 100644 --- a/src/geometry/dual_quaternion.rs +++ b/src/geometry/dual_quaternion.rs @@ -43,7 +43,11 @@ use simba::scalar::{ClosedNeg, RealField}; #[cfg_attr(feature = "rkyv-serialize", derive(bytecheck::CheckBytes))] #[cfg_attr( feature = "rkyv-serialize-no-std", - derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize) + derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize), + archive(as = "DualQuaternion", bound(archive = " + T: rkyv::Archive, + Quaternion: rkyv::Archive> + ")) )] #[cfg_attr(feature = "cuda", derive(cust_core::DeviceCopy))] pub struct DualQuaternion { diff --git a/src/geometry/isometry.rs b/src/geometry/isometry.rs index 92169742..214f9e90 100755 --- a/src/geometry/isometry.rs +++ b/src/geometry/isometry.rs @@ -68,7 +68,12 @@ use crate::geometry::{AbstractRotation, Point, Translation}; )] #[cfg_attr( feature = "rkyv-serialize-no-std", - derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize) + derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize), + archive(as = "Isometry", bound(archive = " + T: rkyv::Archive, + R: rkyv::Archive, + Translation: rkyv::Archive> + ")) )] #[cfg_attr(feature = "rkyv-serialize", derive(bytecheck::CheckBytes))] pub struct Isometry { diff --git a/src/geometry/orthographic.rs b/src/geometry/orthographic.rs index 7348f676..acd2d02c 100644 --- a/src/geometry/orthographic.rs +++ b/src/geometry/orthographic.rs @@ -22,7 +22,11 @@ use crate::geometry::{Point3, Projective3}; #[cfg_attr(feature = "rkyv-serialize", derive(bytecheck::CheckBytes))] #[cfg_attr( feature = "rkyv-serialize-no-std", - derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize) + derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize), + archive(as = "Orthographic3", bound(archive = " + T: rkyv::Archive, + Matrix4: rkyv::Archive> + ")) )] #[cfg_attr(feature = "cuda", derive(cust_core::DeviceCopy))] #[derive(Copy, Clone)] diff --git a/src/geometry/perspective.rs b/src/geometry/perspective.rs index 351960bb..1c5e2ec9 100644 --- a/src/geometry/perspective.rs +++ b/src/geometry/perspective.rs @@ -23,7 +23,11 @@ use crate::geometry::{Point3, Projective3}; #[cfg_attr(feature = "rkyv-serialize", derive(bytecheck::CheckBytes))] #[cfg_attr( feature = "rkyv-serialize-no-std", - derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize) + derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize), + archive(as = "Perspective3", bound(archive = " + T: rkyv::Archive, + Matrix4: rkyv::Archive> + ")) )] #[cfg_attr(feature = "cuda", derive(cust_core::DeviceCopy))] #[derive(Copy, Clone)] diff --git a/src/geometry/quaternion.rs b/src/geometry/quaternion.rs index f38dca6f..ece0346e 100755 --- a/src/geometry/quaternion.rs +++ b/src/geometry/quaternion.rs @@ -26,7 +26,11 @@ use crate::geometry::{Point3, Rotation}; #[cfg_attr(feature = "rkyv-serialize", derive(bytecheck::CheckBytes))] #[cfg_attr( feature = "rkyv-serialize-no-std", - derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize) + derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize), + archive(as = "Quaternion", bound(archive = " + T: rkyv::Archive, + Vector4: rkyv::Archive> + ")) )] #[cfg_attr(feature = "cuda", derive(cust_core::DeviceCopy))] pub struct Quaternion { diff --git a/src/geometry/rotation.rs b/src/geometry/rotation.rs index 2a8bf427..a923af8b 100755 --- a/src/geometry/rotation.rs +++ b/src/geometry/rotation.rs @@ -52,7 +52,11 @@ use crate::geometry::Point; #[cfg_attr(feature = "rkyv-serialize", derive(bytecheck::CheckBytes))] #[cfg_attr( feature = "rkyv-serialize-no-std", - derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize) + derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize), + archive(as = "Rotation", bound(archive = " + T: rkyv::Archive, + SMatrix: rkyv::Archive> + ")) )] #[cfg_attr(feature = "cuda", derive(cust_core::DeviceCopy))] #[derive(Copy, Clone)] diff --git a/src/geometry/scale.rs b/src/geometry/scale.rs index 37da1ef0..6dd0ce39 100755 --- a/src/geometry/scale.rs +++ b/src/geometry/scale.rs @@ -20,7 +20,11 @@ use crate::geometry::Point; #[cfg_attr(feature = "rkyv-serialize", derive(bytecheck::CheckBytes))] #[cfg_attr( feature = "rkyv-serialize-no-std", - derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize) + derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize), + archive(as = "Scale", bound(archive = " + T: rkyv::Archive, + SVector: rkyv::Archive> + ")) )] #[cfg_attr(feature = "cuda", derive(cust_core::DeviceCopy))] #[derive(Copy, Clone)] diff --git a/src/geometry/similarity.rs b/src/geometry/similarity.rs index 8c38ff1e..6c7d5418 100755 --- a/src/geometry/similarity.rs +++ b/src/geometry/similarity.rs @@ -36,7 +36,12 @@ use crate::geometry::{AbstractRotation, Isometry, Point, Translation}; )] #[cfg_attr( feature = "rkyv-serialize-no-std", - derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize) + derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize), + archive(as = "Similarity", bound(archive = " + T: rkyv::Archive, + R: rkyv::Archive, + Isometry: rkyv::Archive> + ")) )] #[cfg_attr(feature = "rkyv-serialize", derive(bytecheck::CheckBytes))] pub struct Similarity { diff --git a/src/geometry/translation.rs b/src/geometry/translation.rs index bef66f68..980b885f 100755 --- a/src/geometry/translation.rs +++ b/src/geometry/translation.rs @@ -20,7 +20,11 @@ use crate::geometry::Point; #[cfg_attr(feature = "rkyv-serialize", derive(bytecheck::CheckBytes))] #[cfg_attr( feature = "rkyv-serialize-no-std", - derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize) + derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize), + archive(as = "Translation", bound(archive = " + T: rkyv::Archive, + SVector: rkyv::Archive> + ")) )] #[cfg_attr(feature = "cuda", derive(cust_core::DeviceCopy))] #[derive(Copy, Clone)] diff --git a/tests/core/rkyv.rs b/tests/core/rkyv.rs index d2b7bfb3..7e2da7aa 100644 --- a/tests/core/rkyv.rs +++ b/tests/core/rkyv.rs @@ -6,9 +6,9 @@ use na::{ SimilarityMatrix3, Translation2, Translation3, Unit, Vector2, }; use rand; -use rkyv::{Archive, Serialize, Deserialize}; +use rkyv::{Archive, Serialize, Deserialize, Infallible}; -macro_rules! test_rkyv( +macro_rules! test_rkyv_archived_impls( ($($test: ident, $ty: ident);* $(;)*) => {$( #[test] fn $test() { @@ -22,20 +22,36 @@ macro_rules! test_rkyv( } )*} ); +macro_rules! test_rkyv( + ($($test: ident, $ty: ident);* $(;)*) => {$( + #[test] + fn $test() { + let value: $ty = rand::random(); + let bytes = rkyv::to_bytes::<_, 256>(&value).unwrap(); + + let archived = rkyv::check_archived_root::<$ty>(&bytes[..]).unwrap(); + let deserialized: $ty = archived.deserialize(&mut Infallible).unwrap(); + assert_eq!(deserialized, value); + } + )*} +); + +test_rkyv_archived_impls!( + rkyv_matrix3x4, Matrix3x4; +); test_rkyv!( - rkyv_matrix3x4, Matrix3x4; // rkyv_point3, Point3; - /* rkyv_translation3, Translation3; - rkyv_rotation3, Rotation3; + rkyv_translation3, Translation3; + /* rkyv_rotation3, Rotation3; rkyv_isometry3, Isometry3; rkyv_isometry_matrix3, IsometryMatrix3; rkyv_similarity3, Similarity3; rkyv_similarity_matrix3, SimilarityMatrix3; - rkyv_quaternion, Quaternion; - rkyv_point2, Point2; + rkyv_quaternion, Quaternion; */ + // rkyv_point2, Point2; rkyv_translation2, Translation2; - rkyv_rotation2, Rotation2; + /* rkyv_rotation2, Rotation2; rkyv_isometry2, Isometry2; rkyv_isometry_matrix2, IsometryMatrix2; rkyv_similarity2, Similarity2;