From b6a0221af11d7e709b2c490f9fd07799dfb32d04 Mon Sep 17 00:00:00 2001 From: Kevin Reid Date: Thu, 25 Apr 2024 15:30:21 -0700 Subject: [PATCH] Add componentwise binary operators to `FaceMap`. --- all-is-cubes-base/src/math/face.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/all-is-cubes-base/src/math/face.rs b/all-is-cubes-base/src/math/face.rs index eb92ac6d6..cd52cfa6e 100644 --- a/all-is-cubes-base/src/math/face.rs +++ b/all-is-cubes-base/src/math/face.rs @@ -892,6 +892,27 @@ where } } +macro_rules! impl_binary_operator_for_facemap { + ($trait:ident :: $method:ident) => { + impl ops::$trait for FaceMap { + type Output = FaceMap; + /// Apply the operator pairwise to the values for all six faces. + #[inline] + fn $method(self, other: FaceMap) -> FaceMap { + self.zip(other, |_, a, b| ::$method(a, b)) + } + } + }; +} +impl_binary_operator_for_facemap!(BitAnd::bitand); +impl_binary_operator_for_facemap!(BitOr::bitor); +impl_binary_operator_for_facemap!(BitXor::bitxor); +impl_binary_operator_for_facemap!(Add::add); +impl_binary_operator_for_facemap!(Mul::mul); +impl_binary_operator_for_facemap!(Sub::sub); +impl_binary_operator_for_facemap!(Div::div); +impl_binary_operator_for_facemap!(Rem::rem); + /// The combination of a [`Cube`] and [`Face7`] identifying one face of it or the interior. /// This pattern appears in cursor selection and collision detection. #[derive(Clone, Copy, Hash, Eq, PartialEq)]