Simplify "fold_array" macro (#527)

This commit is contained in:
Bryce Besler 2021-04-06 08:06:21 -06:00 committed by GitHub
parent 637c566cc2
commit 3e93bac9f5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 28 deletions

View file

@ -139,30 +139,8 @@ macro_rules! impl_assignment_operator {
}
macro_rules! fold_array {
(&$method:ident, { $x:expr }) => {
*$x
};
(&$method:ident, { $x:expr, $y:expr }) => {
$x.$method(&$y)
};
(&$method:ident, { $x:expr, $y:expr, $z:expr }) => {
$x.$method(&$y).$method(&$z)
};
(&$method:ident, { $x:expr, $y:expr, $z:expr, $w:expr }) => {
$x.$method(&$y).$method(&$z).$method(&$w)
};
($method:ident, { $x:expr }) => {
$x
};
($method:ident, { $x:expr, $y:expr }) => {
$x.$method($y)
};
($method:ident, { $x:expr, $y:expr, $z:expr }) => {
$x.$method($y).$method($z)
};
($method:ident, { $x:expr, $y:expr, $z:expr, $w:expr }) => {
$x.$method($y).$method($z).$method($w)
};
($method:ident, $x:expr) => ($x);
($method:ident, $x:expr, $($y:expr),+) => ($x.$method(fold_array!($method, $($y),+)))
}
/// Generate array conversion implementations for a compound array type

View file

@ -127,12 +127,12 @@ macro_rules! impl_point {
#[inline]
fn sum(self) -> S where S: Add<Output = S> {
fold_array!(add, { $(self.$field),+ })
fold_array!(add, $(self.$field),+ )
}
#[inline]
fn product(self) -> S where S: Mul<Output = S> {
fold_array!(mul, { $(self.$field),+ })
fold_array!(mul, $(self.$field),+ )
}
fn is_finite(&self) -> bool where S: Float {

View file

@ -163,12 +163,12 @@ macro_rules! impl_vector {
#[inline]
fn sum(self) -> S where S: Add<Output = S> {
fold_array!(add, { $(self.$field),+ })
fold_array!(add, $(self.$field),+ )
}
#[inline]
fn product(self) -> S where S: Mul<Output = S> {
fold_array!(mul, { $(self.$field),+ })
fold_array!(mul, $(self.$field),+ )
}
fn is_finite(&self) -> bool where S: Float {