Skip to content

Commit

Permalink
Add componentwise binary operators to FaceMap.
Browse files Browse the repository at this point in the history
  • Loading branch information
kpreid committed Jun 2, 2024
1 parent fe33008 commit b6a0221
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions all-is-cubes-base/src/math/face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,27 @@ where
}
}

macro_rules! impl_binary_operator_for_facemap {
($trait:ident :: $method:ident) => {
impl<V: ops::$trait> ops::$trait for FaceMap<V> {
type Output = FaceMap<V::Output>;
/// Apply the operator pairwise to the values for all six faces.
#[inline]
fn $method(self, other: FaceMap<V>) -> FaceMap<V::Output> {
self.zip(other, |_, a, b| <V as ops::$trait>::$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)]
Expand Down

0 comments on commit b6a0221

Please sign in to comment.