Skip to content

Commit

Permalink
Merge pull request #925 from CAD97/bytemuck
Browse files Browse the repository at this point in the history
Impl bytemuck traits for geometry types
  • Loading branch information
sebcrozet committed Jul 27, 2021
2 parents 15c4a25 + 07c3fbc commit 99a79d5
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/geometry/dual_quaternion.rs
Expand Up @@ -250,6 +250,22 @@ where
}
}

#[cfg(feature = "bytemuck")]
unsafe impl<T> bytemuck::Zeroable for DualQuaternion<T>
where
T: Scalar + bytemuck::Zeroable,
Quaternion<T>: bytemuck::Zeroable,
{
}

#[cfg(feature = "bytemuck")]
unsafe impl<T> bytemuck::Pod for DualQuaternion<T>
where
T: Scalar + bytemuck::Pod,
Quaternion<T>: bytemuck::Pod,
{
}

#[cfg(feature = "serde-serialize-no-std")]
impl<T: SimdRealField> Serialize for DualQuaternion<T>
where
Expand Down
17 changes: 17 additions & 0 deletions src/geometry/orthographic.rs
Expand Up @@ -18,6 +18,7 @@ use crate::base::{Matrix4, Vector, Vector3};
use crate::geometry::{Point3, Projective3};

/// A 3D orthographic projection stored as a homogeneous 4x4 matrix.
#[repr(C)]
pub struct Orthographic3<T> {
matrix: Matrix4<T>,
}
Expand All @@ -44,6 +45,22 @@ impl<T: RealField> PartialEq for Orthographic3<T> {
}
}

#[cfg(feature = "bytemuck")]
unsafe impl<T> bytemuck::Zeroable for Orthographic3<T>
where
T: RealField + bytemuck::Zeroable,
Matrix4<T>: bytemuck::Zeroable,
{
}

#[cfg(feature = "bytemuck")]
unsafe impl<T> bytemuck::Pod for Orthographic3<T>
where
T: RealField + bytemuck::Pod,
Matrix4<T>: bytemuck::Pod,
{
}

#[cfg(feature = "serde-serialize-no-std")]
impl<T: RealField + Serialize> Serialize for Orthographic3<T> {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
Expand Down
17 changes: 17 additions & 0 deletions src/geometry/perspective.rs
Expand Up @@ -19,6 +19,7 @@ use crate::base::{Matrix4, Vector, Vector3};
use crate::geometry::{Point3, Projective3};

/// A 3D perspective projection stored as a homogeneous 4x4 matrix.
#[repr(C)]
pub struct Perspective3<T> {
matrix: Matrix4<T>,
}
Expand All @@ -45,6 +46,22 @@ impl<T: RealField> PartialEq for Perspective3<T> {
}
}

#[cfg(feature = "bytemuck")]
unsafe impl<T> bytemuck::Zeroable for Perspective3<T>
where
T: RealField + bytemuck::Zeroable,
Matrix4<T>: bytemuck::Zeroable,
{
}

#[cfg(feature = "bytemuck")]
unsafe impl<T> bytemuck::Pod for Perspective3<T>
where
T: RealField + bytemuck::Pod,
Matrix4<T>: bytemuck::Pod,
{
}

#[cfg(feature = "serde-serialize-no-std")]
impl<T: RealField + Serialize> Serialize for Perspective3<T> {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
Expand Down
16 changes: 16 additions & 0 deletions src/geometry/rotation.rs
Expand Up @@ -83,6 +83,22 @@ where
}
}

#[cfg(feature = "bytemuck")]
unsafe impl<T, const D: usize> bytemuck::Zeroable for Rotation<T, D>
where
T: Scalar + bytemuck::Zeroable,
SMatrix<T, D, D>: bytemuck::Zeroable,
{
}

#[cfg(feature = "bytemuck")]
unsafe impl<T, const D: usize> bytemuck::Pod for Rotation<T, D>
where
T: Scalar + bytemuck::Pod,
SMatrix<T, D, D>: bytemuck::Pod,
{
}

#[cfg(feature = "abomonation-serialize")]
impl<T, const D: usize> Abomonation for Rotation<T, D>
where
Expand Down
21 changes: 21 additions & 0 deletions src/geometry/transform.rs
Expand Up @@ -197,6 +197,27 @@ where
}
}

#[cfg(feature = "bytemuck")]
unsafe impl<T, C: TCategory, const D: usize> bytemuck::Zeroable for Transform<T, C, D>
where
T: RealField + bytemuck::Zeroable,
Const<D>: DimNameAdd<U1>,
DefaultAllocator: Allocator<T, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>>,
OMatrix<T, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>>: bytemuck::Zeroable,
{
}

#[cfg(feature = "bytemuck")]
unsafe impl<T, C: TCategory, const D: usize> bytemuck::Pod for Transform<T, C, D>
where
T: RealField + bytemuck::Pod,
Const<D>: DimNameAdd<U1>,
DefaultAllocator: Allocator<T, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>>,
OMatrix<T, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>>: bytemuck::Pod,
Owned<T, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>>: Copy,
{
}

#[cfg(feature = "serde-serialize-no-std")]
impl<T: RealField, C: TCategory, const D: usize> Serialize for Transform<T, C, D>
where
Expand Down
16 changes: 16 additions & 0 deletions src/geometry/translation.rs
Expand Up @@ -50,6 +50,22 @@ where
}
}

#[cfg(feature = "bytemuck")]
unsafe impl<T, const D: usize> bytemuck::Zeroable for Translation<T, D>
where
T: Scalar + bytemuck::Zeroable,
SVector<T, D>: bytemuck::Zeroable,
{
}

#[cfg(feature = "bytemuck")]
unsafe impl<T, const D: usize> bytemuck::Pod for Translation<T, D>
where
T: Scalar + bytemuck::Pod,
SVector<T, D>: bytemuck::Pod,
{
}

#[cfg(feature = "abomonation-serialize")]
impl<T, const D: usize> Abomonation for Translation<T, D>
where
Expand Down

0 comments on commit 99a79d5

Please sign in to comment.