From 26ffc61a0e25e13b57fc671e03fe87e56e9fd926 Mon Sep 17 00:00:00 2001 From: Kevin Reid Date: Mon, 13 Jan 2025 20:41:30 -0800 Subject: [PATCH] math: `impl ops::*Assign for FaceMap` --- all-is-cubes-base/src/math/face.rs | 31 +++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/all-is-cubes-base/src/math/face.rs b/all-is-cubes-base/src/math/face.rs index e3670e168..dc598b77e 100644 --- a/all-is-cubes-base/src/math/face.rs +++ b/all-is-cubes-base/src/math/face.rs @@ -909,7 +909,7 @@ where } macro_rules! impl_binary_operator_for_facemap { - ($trait:ident :: $method:ident) => { + ($trait:ident :: $method:ident, $assign_trait:ident :: $assign_method:ident) => { impl ops::$trait for FaceMap { type Output = FaceMap; /// Apply the operator pairwise to the values for all six faces. @@ -918,16 +918,29 @@ macro_rules! impl_binary_operator_for_facemap { self.zip(other, |_, a, b| ::$method(a, b)) } } + + impl ops::$assign_trait for FaceMap { + /// Apply the operator pairwise to the values for all six faces. + #[inline] + fn $assign_method(&mut self, rhs: Self) { + self.nx.$assign_method(rhs.nx); + self.ny.$assign_method(rhs.ny); + self.nz.$assign_method(rhs.nz); + self.px.$assign_method(rhs.px); + self.py.$assign_method(rhs.py); + self.pz.$assign_method(rhs.pz); + } + } }; } -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); +impl_binary_operator_for_facemap!(BitAnd::bitand, BitAndAssign::bitand_assign); +impl_binary_operator_for_facemap!(BitOr::bitor, BitOrAssign::bitor_assign); +impl_binary_operator_for_facemap!(BitXor::bitxor, BitXorAssign::bitxor_assign); +impl_binary_operator_for_facemap!(Add::add, AddAssign::add_assign); +impl_binary_operator_for_facemap!(Mul::mul, MulAssign::mul_assign); +impl_binary_operator_for_facemap!(Sub::sub, SubAssign::sub_assign); +impl_binary_operator_for_facemap!(Div::div, DivAssign::div_assign); +impl_binary_operator_for_facemap!(Rem::rem, RemAssign::rem_assign); /// The combination of a [`Cube`] and [`Face7`] identifying one face of it or the interior. /// This pattern appears in cursor selection and collision detection.