Simplify "fold_array" macro (#527)
This commit is contained in:
parent
637c566cc2
commit
3e93bac9f5
3 changed files with 6 additions and 28 deletions
|
@ -139,30 +139,8 @@ macro_rules! impl_assignment_operator {
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! fold_array {
|
macro_rules! fold_array {
|
||||||
(&$method:ident, { $x:expr }) => {
|
($method:ident, $x:expr) => ($x);
|
||||||
*$x
|
($method:ident, $x:expr, $($y:expr),+) => ($x.$method(fold_array!($method, $($y),+)))
|
||||||
};
|
|
||||||
(&$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)
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Generate array conversion implementations for a compound array type
|
/// Generate array conversion implementations for a compound array type
|
||||||
|
|
|
@ -127,12 +127,12 @@ macro_rules! impl_point {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn sum(self) -> S where S: Add<Output = S> {
|
fn sum(self) -> S where S: Add<Output = S> {
|
||||||
fold_array!(add, { $(self.$field),+ })
|
fold_array!(add, $(self.$field),+ )
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn product(self) -> S where S: Mul<Output = S> {
|
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 {
|
fn is_finite(&self) -> bool where S: Float {
|
||||||
|
|
|
@ -163,12 +163,12 @@ macro_rules! impl_vector {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn sum(self) -> S where S: Add<Output = S> {
|
fn sum(self) -> S where S: Add<Output = S> {
|
||||||
fold_array!(add, { $(self.$field),+ })
|
fold_array!(add, $(self.$field),+ )
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn product(self) -> S where S: Mul<Output = S> {
|
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 {
|
fn is_finite(&self) -> bool where S: Float {
|
||||||
|
|
Loading…
Reference in a new issue