Add is_finite to array and quaternion

This commit is contained in:
Richard Dodd 2018-04-29 14:21:42 +01:00
parent f82e421e2c
commit f8e92ed327
4 changed files with 17 additions and 7 deletions

View file

@ -118,6 +118,10 @@ macro_rules! impl_point {
fn product(self) -> S where S: Mul<Output = S> {
fold_array!(mul, { $(self.$field),+ })
}
fn is_finite(&self) -> bool where S: BaseFloat {
$(self.$field.is_finite())&&+
}
}
impl<S: NumCast + Copy> $PointN<S> {

View file

@ -173,6 +173,10 @@ impl<S: BaseFloat> Quaternion<S> {
(self * scale1 + other * scale2) * Rad::sin(theta).recip()
}
}
pub fn is_finite(&self) -> bool {
self.s.is_finite() && self.v.is_finite()
}
}
impl<S: BaseFloat> Zero for Quaternion<S> {

View file

@ -87,6 +87,11 @@ where
fn product(self) -> Self::Element
where
Self::Element: Mul<Output = <Self as Array>::Element>;
/// Whether all elements of the array are finite
fn is_finite(&self) -> bool
where
Self::Element: BaseFloat;
}
/// Element-wise arithmetic operations. These are supplied for pragmatic

View file

@ -118,13 +118,6 @@ macro_rules! impl_vector {
$VectorN::new($($field),+)
}
impl<S: BaseFloat> $VectorN<S> {
/// True if all entries in the vector are finite
pub fn is_finite(&self) -> bool {
$(self.$field.is_finite())&&+
}
}
impl<S: NumCast + Copy> $VectorN<S> {
/// Component-wise casting to another type.
#[inline]
@ -170,6 +163,10 @@ macro_rules! impl_vector {
fn product(self) -> S where S: Mul<Output = S> {
fold_array!(mul, { $(self.$field),+ })
}
fn is_finite(&self) -> bool where S: BaseFloat {
$(self.$field.is_finite())&&+
}
}
impl<S: BaseNum> Zero for $VectorN<S> {