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