From cb0812aaf31f573dc0724240fa306d57bdfcec70 Mon Sep 17 00:00:00 2001 From: CAD97 Date: Mon, 28 Jun 2021 20:36:28 -0500 Subject: [PATCH] Add bytemuck impls to geometry types --- src/geometry/dual_quaternion.rs | 6 ++++++ src/geometry/orthographic.rs | 6 ++++++ src/geometry/perspective.rs | 6 ++++++ src/geometry/rotation.rs | 16 ++++++++++++++++ src/geometry/transform.rs | 18 ++++++++++++++++++ src/geometry/translation.rs | 16 ++++++++++++++++ 6 files changed, 68 insertions(+) diff --git a/src/geometry/dual_quaternion.rs b/src/geometry/dual_quaternion.rs index 63148836..d745f1d3 100644 --- a/src/geometry/dual_quaternion.rs +++ b/src/geometry/dual_quaternion.rs @@ -241,6 +241,12 @@ where } } +#[cfg(feature = "bytemuck")] +unsafe impl bytemuck::Zeroable for DualQuaternion where Quaternion: bytemuck::Zeroable {} + +#[cfg(feature = "bytemuck")] +unsafe impl bytemuck::Pod for DualQuaternion where Quaternion: bytemuck::Pod {} + #[cfg(feature = "serde-serialize-no-std")] impl Serialize for DualQuaternion where diff --git a/src/geometry/orthographic.rs b/src/geometry/orthographic.rs index 17a5b969..ade84092 100644 --- a/src/geometry/orthographic.rs +++ b/src/geometry/orthographic.rs @@ -44,6 +44,12 @@ impl PartialEq for Orthographic3 { } } +#[cfg(feature = "bytemuck")] +unsafe impl bytemuck::Zeroable for Orthographic3 where Matrix4: bytemuck::Zeroable {} + +#[cfg(feature = "bytemuck")] +unsafe impl bytemuck::Pod for Orthographic3 where Matrix4: bytemuck::Pod {} + #[cfg(feature = "serde-serialize-no-std")] impl Serialize for Orthographic3 { fn serialize(&self, serializer: S) -> Result diff --git a/src/geometry/perspective.rs b/src/geometry/perspective.rs index 6ad9707f..c7dd8b3e 100644 --- a/src/geometry/perspective.rs +++ b/src/geometry/perspective.rs @@ -45,6 +45,12 @@ impl PartialEq for Perspective3 { } } +#[cfg(feature = "bytemuck")] +unsafe impl bytemuck::Zeroable for Perspective3 where Matrix4: bytemuck::Zeroable {} + +#[cfg(feature = "bytemuck")] +unsafe impl bytemuck::Pod for Perspective3 where Matrix4: bytemuck::Pod {} + #[cfg(feature = "serde-serialize-no-std")] impl Serialize for Perspective3 { fn serialize(&self, serializer: S) -> Result diff --git a/src/geometry/rotation.rs b/src/geometry/rotation.rs index f3127fb9..89bc082f 100755 --- a/src/geometry/rotation.rs +++ b/src/geometry/rotation.rs @@ -83,6 +83,22 @@ where } } +#[cfg(feature = "bytemuck")] +unsafe impl bytemuck::Zeroable for Rotation +where + T: Scalar, + SMatrix: bytemuck::Zeroable, +{ +} + +#[cfg(feature = "bytemuck")] +unsafe impl bytemuck::Pod for Rotation +where + T: Scalar, + SMatrix: bytemuck::Pod, +{ +} + #[cfg(feature = "abomonation-serialize")] impl Abomonation for Rotation where diff --git a/src/geometry/transform.rs b/src/geometry/transform.rs index 682d2bd6..051fd3d5 100755 --- a/src/geometry/transform.rs +++ b/src/geometry/transform.rs @@ -194,6 +194,24 @@ where } } +#[cfg(feature = "bytemuck")] +unsafe impl bytemuck::Zeroable for Transform +where + Const: DimNameAdd, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, + OMatrix, U1>, DimNameSum, U1>>: bytemuck::Zeroable, +{ +} + +#[cfg(feature = "bytemuck")] +unsafe impl bytemuck::Pod for Transform +where + Const: DimNameAdd, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, + OMatrix, U1>, DimNameSum, U1>>: bytemuck::Pod, +{ +} + #[cfg(feature = "serde-serialize-no-std")] impl Serialize for Transform where diff --git a/src/geometry/translation.rs b/src/geometry/translation.rs index 18fa7e04..758a21ca 100755 --- a/src/geometry/translation.rs +++ b/src/geometry/translation.rs @@ -50,6 +50,22 @@ where } } +#[cfg(feature = "bytemuck")] +unsafe impl bytemuck::Zeroable for Translation +where + T: Scalar, + SVector: bytemuck::Zeroable, +{ +} + +#[cfg(feature = "bytemuck")] +unsafe impl bytemuck::Pod for Translation +where + T: Scalar, + SVector: bytemuck::Pod, +{ +} + #[cfg(feature = "abomonation-serialize")] impl Abomonation for Translation where