Skip to content

Commit

Permalink
feat: derive bytemuck traits for Isometry and Similarity
Browse files Browse the repository at this point in the history
  • Loading branch information
sebcrozet committed Oct 16, 2024
1 parent 338a22b commit cff4b99
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ macros = ["nalgebra-macros"]

# Conversion
convert-mint = ["mint"]
convert-bytemuck = ["bytemuck"]
convert-bytemuck = ["bytemuck", "num-complex/bytemuck"]
convert-glam014 = ["glam014"]
convert-glam015 = ["glam015"]
convert-glam016 = ["glam016"]
Expand Down
19 changes: 19 additions & 0 deletions src/geometry/isometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ use crate::base::storage::Owned;
use crate::base::{Const, DefaultAllocator, OMatrix, SVector, Scalar, Unit};
use crate::geometry::{AbstractRotation, Point, Translation};

use crate::{Isometry3, Quaternion, Vector3, Vector4};

#[cfg(feature = "rkyv-serialize")]
use rkyv::bytecheck;

Expand Down Expand Up @@ -99,6 +101,23 @@ where
}
}

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

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

/// # From the translation and rotation parts
impl<T: Scalar, R: AbstractRotation<T, D>, const D: usize> Isometry<T, R, D> {
/// Creates a new isometry from its rotational and translational parts.
Expand Down
15 changes: 15 additions & 0 deletions src/geometry/similarity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,21 @@ where
}
}

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

#[cfg(feature = "bytemuck")]
unsafe impl<T: Scalar, R, const D: usize> bytemuck::Pod for Similarity<T, R, D>
where
Isometry<T, R, D>: bytemuck::Pod,
R: Copy,
T: Copy,
{
}

impl<T: Scalar + Zero, R, const D: usize> Similarity<T, R, D>
where
R: AbstractRotation<T, D>,
Expand Down

0 comments on commit cff4b99

Please sign in to comment.