use super::*;
pub type Bool2 = Vec2<bool>;
pub type Bool3 = Vec3<bool>;
pub type Bool4 = Vec4<bool>;
macro_rules! bools {
($bools:ident $vec:ident { $($field:ident),+ }) => {
#[doc = stringify!($bools)]
#[doc = " constructor."]
#[allow(non_snake_case)]
#[inline]
pub const fn $bools($($field: bool),+) -> $bools {
$bools { $($field),+ }
}
impl<T> $vec<T> {
#[inline]
pub fn is_finite(self) -> $bools where T: Float {
$vec { $($field: self.$field.is_finite()),+ }
}
#[inline]
pub fn is_infinite(self) -> $bools where T: Float {
$vec { $($field: self.$field.is_infinite()),+ }
}
#[inline]
pub fn eq(self, rhs: $vec<T>) -> $bools where T: PartialEq {
$vec { $($field: self.$field == rhs.$field),+ }
}
#[inline]
pub fn ne(self, rhs: $vec<T>) -> $bools where T: PartialEq {
$vec { $($field: self.$field != rhs.$field),+ }
}
#[inline]
pub fn lt(self, rhs: $vec<T>) -> $bools where T: PartialOrd {
$vec { $($field: self.$field < rhs.$field),+ }
}
#[inline]
pub fn le(self, rhs: $vec<T>) -> $bools where T: PartialOrd {
$vec { $($field: self.$field <= rhs.$field),+ }
}
#[inline]
pub fn gt(self, rhs: $vec<T>) -> $bools where T: PartialOrd {
$vec { $($field: self.$field > rhs.$field),+ }
}
#[inline]
pub fn ge(self, rhs: $vec<T>) -> $bools where T: PartialOrd {
$vec { $($field: self.$field >= rhs.$field),+ }
}
}
impl<T> $vec<T> {
#[inline]
pub fn is_close(self, rhs: $vec<T>) -> $bools where T: Float {
$vec { $($field: self.$field.is_close(rhs.$field)),+ }
}
#[inline]
pub fn all_close(self, rhs: $vec<T>) -> bool where T: Float {
self.is_close(rhs).all()
}
}
impl $bools {
#[inline]
pub const fn any(self) -> bool {
infix!(| $(self.$field),+)
}
#[inline]
pub const fn all(self) -> bool {
infix!(& $(self.$field),+)
}
#[inline]
pub const fn none(self) -> bool {
!self.any()
}
#[inline]
pub fn select<T>(self, lhs: $vec<T>, rhs: $vec<T>) -> $vec<T> {
$vec { $($field: if self.$field { lhs.$field } else { rhs.$field }),+ }
}
}
impl<U, T: ops::BitAnd<U>> ops::BitAnd<$vec<U>> for $vec<T> {
type Output = $vec<T::Output>;
#[inline]
fn bitand(self, rhs: $vec<U>) -> $vec<T::Output> {
$vec { $($field: self.$field & rhs.$field),+ }
}
}
impl<U, T: ops::BitOr<U>> ops::BitOr<$vec<U>> for $vec<T> {
type Output = $vec<T::Output>;
#[inline]
fn bitor(self, rhs: $vec<U>) -> $vec<T::Output> {
$vec { $($field: self.$field | rhs.$field),+ }
}
}
impl<U, T: ops::BitXor<U>> ops::BitXor<$vec<U>> for $vec<T> {
type Output = $vec<T::Output>;
#[inline]
fn bitxor(self, rhs: $vec<U>) -> $vec<T::Output> {
$vec { $($field: self.$field ^ rhs.$field),+ }
}
}
impl<T: ops::Not> ops::Not for $vec<T> {
type Output = $vec<T::Output>;
#[inline]
fn not(self) -> $vec<T::Output> {
$vec { $($field: !self.$field),+ }
}
}
};
}
bools!(Bool2 Vec2 { x, y });
bools!(Bool3 Vec3 { x, y, z });
bools!(Bool4 Vec4 { x, y, z, w });