Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Impl bytemuck traits for geometry types #925

Merged
merged 4 commits into from
Jul 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/geometry/dual_quaternion.rs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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