diff --git a/src/box2d.rs b/src/box2d.rs index 825f585..c121232 100644 --- a/src/box2d.rs +++ b/src/box2d.rs @@ -101,6 +101,19 @@ impl fmt::Debug for Box2D { } } +#[cfg(feature = "arbitrary")] +impl<'a, T, U> arbitrary::Arbitrary<'a> for Box2D +where + T: arbitrary::Arbitrary<'a>, +{ + fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result { + Ok(Box2D::new( + arbitrary::Arbitrary::arbitrary(u)?, + arbitrary::Arbitrary::arbitrary(u)?, + )) + } +} + #[cfg(feature = "bytemuck")] unsafe impl Zeroable for Box2D {} diff --git a/src/box3d.rs b/src/box3d.rs index 710c862..00d4dc0 100644 --- a/src/box3d.rs +++ b/src/box3d.rs @@ -71,6 +71,19 @@ impl fmt::Debug for Box3D { } } +#[cfg(feature = "arbitrary")] +impl<'a, T, U> arbitrary::Arbitrary<'a> for Box3D +where + T: arbitrary::Arbitrary<'a>, +{ + fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result { + Ok(Box3D::new( + arbitrary::Arbitrary::arbitrary(u)?, + arbitrary::Arbitrary::arbitrary(u)?, + )) + } +} + #[cfg(feature = "bytemuck")] unsafe impl Zeroable for Box3D {} diff --git a/src/homogen.rs b/src/homogen.rs index 0cf3746..0e5dc71 100644 --- a/src/homogen.rs +++ b/src/homogen.rs @@ -80,6 +80,23 @@ where } } +#[cfg(feature = "arbitrary")] +impl<'a, T, U> arbitrary::Arbitrary<'a> for HomogeneousVector +where + T: arbitrary::Arbitrary<'a>, +{ + fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result { + let (x, y, z, w) = arbitrary::Arbitrary::arbitrary(u)?; + Ok(HomogeneousVector { + x, + y, + z, + w, + _unit: PhantomData, + }) + } +} + #[cfg(feature = "bytemuck")] unsafe impl Zeroable for HomogeneousVector {} diff --git a/src/length.rs b/src/length.rs index 6f0f3b1..3316077 100644 --- a/src/length.rs +++ b/src/length.rs @@ -77,6 +77,16 @@ where } } +#[cfg(feature = "arbitrary")] +impl<'a, T, U> arbitrary::Arbitrary<'a> for Length +where + T: arbitrary::Arbitrary<'a>, +{ + fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result { + Ok(Length(arbitrary::Arbitrary::arbitrary(u)?, PhantomData)) + } +} + #[cfg(feature = "bytemuck")] unsafe impl Zeroable for Length {} diff --git a/src/point.rs b/src/point.rs index b94dc42..af3bcc8 100644 --- a/src/point.rs +++ b/src/point.rs @@ -874,6 +874,22 @@ where } } +#[cfg(feature = "arbitrary")] +impl<'a, T, U> arbitrary::Arbitrary<'a> for Point3D +where + T: arbitrary::Arbitrary<'a>, +{ + fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result { + let (x, y, z) = arbitrary::Arbitrary::arbitrary(u)?; + Ok(Point3D { + x, + y, + z, + _unit: PhantomData, + }) + } +} + #[cfg(feature = "bytemuck")] unsafe impl Zeroable for Point3D {} diff --git a/src/rigid.rs b/src/rigid.rs index 9f5bfd4..00fea7c 100644 --- a/src/rigid.rs +++ b/src/rigid.rs @@ -223,6 +223,19 @@ impl Clone for RigidTransform3D { } } +#[cfg(feature = "arbitrary")] +impl<'a, T, Src, Dst> arbitrary::Arbitrary<'a> for RigidTransform3D +where + T: arbitrary::Arbitrary<'a>, +{ + fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result { + Ok(RigidTransform3D { + rotation: arbitrary::Arbitrary::arbitrary(u)?, + translation: arbitrary::Arbitrary::arbitrary(u)?, + }) + } +} + #[cfg(feature = "bytemuck")] unsafe impl Zeroable for RigidTransform3D {} diff --git a/src/rotation.rs b/src/rotation.rs index 1be36c4..d12d29f 100644 --- a/src/rotation.rs +++ b/src/rotation.rs @@ -73,6 +73,16 @@ where } } +#[cfg(feature = "arbitrary")] +impl<'a, T, Src, Dst> arbitrary::Arbitrary<'a> for Rotation2D +where + T: arbitrary::Arbitrary<'a>, +{ + fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result { + Ok(Rotation2D::new(arbitrary::Arbitrary::arbitrary(u)?)) + } +} + #[cfg(feature = "bytemuck")] unsafe impl Zeroable for Rotation2D {} @@ -312,6 +322,20 @@ where } } +/// Note: the quaternions produced by this implementation are not normalized +/// (nor even necessarily finite). That is, this is not appropriate to use to +/// choose an actual “arbitrary rotation”, at least not without postprocessing. +#[cfg(feature = "arbitrary")] +impl<'a, T, Src, Dst> arbitrary::Arbitrary<'a> for Rotation3D +where + T: arbitrary::Arbitrary<'a>, +{ + fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result { + let (i, j, k, r) = arbitrary::Arbitrary::arbitrary(u)?; + Ok(Rotation3D::quaternion(i, j, k, r)) + } +} + #[cfg(feature = "bytemuck")] unsafe impl Zeroable for Rotation3D {} diff --git a/src/scale.rs b/src/scale.rs index 2d908b0..da1b7d6 100644 --- a/src/scale.rs +++ b/src/scale.rs @@ -324,6 +324,16 @@ impl Scale { } } +#[cfg(feature = "arbitrary")] +impl<'a, T, Src, Dst> arbitrary::Arbitrary<'a> for Scale +where + T: arbitrary::Arbitrary<'a>, +{ + fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result { + Ok(Scale::new(arbitrary::Arbitrary::arbitrary(u)?)) + } +} + #[cfg(feature = "bytemuck")] unsafe impl Zeroable for Scale {} diff --git a/src/size.rs b/src/size.rs index fe45733..2b9a45a 100644 --- a/src/size.rs +++ b/src/size.rs @@ -997,6 +997,22 @@ where } } +#[cfg(feature = "arbitrary")] +impl<'a, T, U> arbitrary::Arbitrary<'a> for Size3D +where + T: arbitrary::Arbitrary<'a>, +{ + fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result { + let (width, height, depth) = arbitrary::Arbitrary::arbitrary(u)?; + Ok(Size3D { + width, + height, + depth, + _unit: PhantomData, + }) + } +} + #[cfg(feature = "bytemuck")] unsafe impl Zeroable for Size3D {} diff --git a/src/translation.rs b/src/translation.rs index cde3786..7c32d98 100644 --- a/src/translation.rs +++ b/src/translation.rs @@ -419,6 +419,22 @@ pub struct Translation3D { pub _unit: PhantomData<(Src, Dst)>, } +#[cfg(feature = "arbitrary")] +impl<'a, T, Src, Dst> arbitrary::Arbitrary<'a> for Translation3D +where + T: arbitrary::Arbitrary<'a>, +{ + fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result { + let (x, y, z) = arbitrary::Arbitrary::arbitrary(u)?; + Ok(Translation3D { + x, + y, + z, + _unit: PhantomData, + }) + } +} + impl Copy for Translation3D {} impl Clone for Translation3D { diff --git a/src/vector.rs b/src/vector.rs index e0b9128..30258c4 100644 --- a/src/vector.rs +++ b/src/vector.rs @@ -1000,6 +1000,22 @@ where } } +#[cfg(feature = "arbitrary")] +impl<'a, T, U> arbitrary::Arbitrary<'a> for Vector3D +where + T: arbitrary::Arbitrary<'a>, +{ + fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result { + let (x, y, z) = arbitrary::Arbitrary::arbitrary(u)?; + Ok(Vector3D { + x, + y, + z, + _unit: PhantomData, + }) + } +} + #[cfg(feature = "bytemuck")] unsafe impl Zeroable for Vector3D {} @@ -2054,6 +2070,27 @@ impl BoolVector3D { } } +#[cfg(feature = "arbitrary")] +impl<'a> arbitrary::Arbitrary<'a> for BoolVector2D { + fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result { + Ok(BoolVector2D { + x: arbitrary::Arbitrary::arbitrary(u)?, + y: arbitrary::Arbitrary::arbitrary(u)?, + }) + } +} + +#[cfg(feature = "arbitrary")] +impl<'a> arbitrary::Arbitrary<'a> for BoolVector3D { + fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result { + Ok(BoolVector3D { + x: arbitrary::Arbitrary::arbitrary(u)?, + y: arbitrary::Arbitrary::arbitrary(u)?, + z: arbitrary::Arbitrary::arbitrary(u)?, + }) + } +} + /// Convenience constructor. #[inline] pub const fn vec2(x: T, y: T) -> Vector2D {