use core::ops::Neg;
use crate::{
common,
numeric::{Abs, BoundedMax, BoundedMin, IsZero, MinMax, Negate, One, Zero},
tuple::Tuple,
vector::Vector,
};
crate::impl_numeric_casts_wrapper!([T, const N: usize], wrapper: Vector, Vector<T, N> => Vector<U, N>, item: T, field: data);
impl<T, const N: usize> Vector<T, N>
where
T: Zero,
{
pub const ZERO: Self = Self::from_array([T::ZERO; N]);
}
impl<T, const N: usize> Zero for Vector<T, N>
where
T: Zero,
{
const ZERO: Self = Vector::ZERO;
}
impl<T, const N: usize> Vector<T, N>
where
T: Copy + Zero + PartialEq,
{
#[inline]
pub fn is_zero(self) -> bool {
self == Self::ZERO
}
}
impl<T, const N: usize> IsZero for Vector<T, N>
where
T: Copy + Zero + PartialEq,
{
#[inline]
fn is_zero(self) -> bool {
Vector::is_zero(self)
}
}
impl<T, const N: usize> Vector<T, N>
where
T: One,
{
pub const ONE: Self = Self::from_array([T::ONE; N]);
}
impl<T, const N: usize> One for Vector<T, N>
where
T: One,
{
const ONE: Self = Vector::ONE;
}
impl<T, const N: usize> Vector<T, N>
where
T: Copy + BoundedMin,
{
pub const MIN: Self = Self::from_tuple(Tuple::MIN);
}
impl<T, const N: usize> BoundedMin for Vector<T, N>
where
T: Copy + BoundedMin,
{
const MIN: Self = Vector::MIN;
}
impl<T, const N: usize> Vector<T, N>
where
T: Copy + BoundedMax,
{
pub const MAX: Self = Self::from_tuple(Tuple::MAX);
}
impl<T, const N: usize> BoundedMax for Vector<T, N>
where
T: Copy + BoundedMax,
{
const MAX: Self = Vector::MAX;
}
impl<T, const N: usize> Vector<T, N>
where
T: Copy + MinMax,
{
#[inline]
pub fn min(self, rhs: Self) -> Self {
Vector::from_tuple(self.into_tuple().min(rhs.into_tuple()))
}
#[inline]
pub fn max(self, rhs: Self) -> Self {
Vector::from_tuple(self.into_tuple().max(rhs.into_tuple()))
}
}
impl<T, const N: usize> MinMax for Vector<T, N>
where
T: Copy + MinMax,
{
#[inline]
fn minimum(self, rhs: Self) -> Self {
Vector::min(self, rhs)
}
#[inline]
fn maximum(self, rhs: Self) -> Self {
Vector::max(self, rhs)
}
}
impl<T, const N: usize> Vector<T, N>
where
T: Copy + Neg<Output = T>,
{
#[inline]
pub fn negate(self) -> Self {
let out = self.into_tuple().negate();
Self::from_tuple(out)
}
}
impl<T, const N: usize> Negate for Vector<T, N>
where
T: Copy + Neg<Output = T>,
{
#[inline]
fn negate(self) -> Self::Output {
Vector::negate(self)
}
}
impl<T, const N: usize> Vector<T, N>
where
T: Copy + Abs,
{
#[inline]
pub fn abs(self) -> Self {
Vector::from_tuple(self.into_tuple().abs())
}
}
impl<T, const N: usize> Abs for Vector<T, N>
where
T: Copy + Abs,
{
#[inline]
fn abs(self) -> Self {
Vector::abs(self)
}
}
common::_impl_tuple_wrapper_numeric_predicates!([T, const N: usize], Vector<T, N>, item: T, len: N);