use core::ops::{Mul, Sub};
use crate::{
algebra::Cross,
common,
numeric::{NegOne, One, Zero},
vector::{Vector, Vector3Fields},
};
impl<T> Vector<T, 3> {
#[inline]
pub const fn new(x: T, y: T, z: T) -> Self {
Self::from_array([x, y, z])
}
}
impl<T> Vector<T, 3>
where
T: Zero + One,
{
pub const X: Self = Self::new(T::ONE, T::ZERO, T::ZERO);
pub const Y: Self = Self::new(T::ZERO, T::ONE, T::ZERO);
pub const Z: Self = Self::new(T::ZERO, T::ZERO, T::ONE);
pub const AXES: [Self; 3] = [Self::X, Self::Y, Self::Z];
}
impl<T> Vector<T, 3>
where
T: Zero + NegOne,
{
pub const NEG_X: Self = Self::new(T::NEG_ONE, T::ZERO, T::ZERO);
pub const NEG_Y: Self = Self::new(T::ZERO, T::NEG_ONE, T::ZERO);
pub const NEG_Z: Self = Self::new(T::ZERO, T::ZERO, T::NEG_ONE);
}
common::_impl_layout_field_access!([T], Vector<T, 3> => Vector3Fields<T>);
impl<T> Vector<T, 3>
where
T: Copy + Mul<Output = T> + Sub<Output = T>,
{
#[inline]
pub fn cross(self, rhs: Self) -> Self {
Self::new(
self.y * rhs.z - self.z * rhs.y,
self.z * rhs.x - self.x * rhs.z,
self.x * rhs.y - self.y * rhs.x,
)
}
}
impl<T> Cross for Vector<T, 3>
where
T: Copy + Mul<Output = T> + Sub<Output = T>,
{
type Output = Self;
#[inline]
fn cross(self, rhs: Self) -> Self::Output {
Vector::<T, 3>::cross(self, rhs)
}
}