diff --git a/all-is-cubes/src/block/modifier/zoom.rs b/all-is-cubes/src/block/modifier/zoom.rs index 4d2914b91..4fa2f0bd9 100644 --- a/all-is-cubes/src/block/modifier/zoom.rs +++ b/all-is-cubes/src/block/modifier/zoom.rs @@ -13,7 +13,6 @@ use crate::universe; /// Design note: This is a struct separate from [`Modifier`] so that it can have a /// constructor accepting only valid bounds. #[derive(Clone, Debug, Eq, Hash, PartialEq)] -#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] pub struct Zoom { /// Scale factor to zoom in by. scale: Resolution, @@ -155,6 +154,30 @@ impl universe::VisitHandles for Zoom { } } +#[cfg(feature = "arbitrary")] +impl<'a> arbitrary::Arbitrary<'a> for Zoom { + fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result { + let scale = u.arbitrary()?; + let max_offset = GridCoordinate::from(scale) - 1; + Ok(Self::new( + scale, + GridPoint::new( + u.int_in_range(0..=max_offset)?, + u.int_in_range(0..=max_offset)?, + u.int_in_range(0..=max_offset)?, + ), + )) + } + + fn size_hint(depth: usize) -> (usize, Option) { + use arbitrary::{size_hint::and_all, Arbitrary}; + and_all(&[ + ::size_hint(depth), + <[GridCoordinate; 3] as Arbitrary>::size_hint(depth), + ]) + } +} + #[cfg(test)] mod tests { use super::*;