mod euclidean;
mod ops;
#[cfg(feature = "serde")]
mod serde;
use core::ops::{Index, IndexMut};
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[repr(C)]
pub struct Vector<T, const N: usize> {
pub data: [T; N],
}
pub type Vector2<T> = Vector<T, 2>;
pub type Vector3<T> = Vector<T, 3>;
impl<T, const N: usize> Vector<T, N> {
#[inline(always)]
pub const fn from_array(data: [T; N]) -> Self {
Self { data }
}
}
impl<T: Copy, const N: usize> Vector<T, N> {
#[inline(always)]
pub const fn splat(value: T) -> Self {
Self { data: [value; N] }
}
}
impl<T> Vector<T, 2> {
#[inline(always)]
pub const fn new(x: T, y: T) -> Self {
Self { data: [x, y] }
}
}
impl<T> Vector<T, 3> {
#[inline(always)]
pub const fn new(x: T, y: T, z: T) -> Self {
Self { data: [x, y, z] }
}
}
impl<T> Vector<T, 4> {
#[inline(always)]
pub const fn new(x: T, y: T, z: T, w: T) -> Self {
Self { data: [x, y, z, w] }
}
}
impl<T: Default + Copy, const N: usize> Default for Vector<T, N> {
#[inline(always)]
fn default() -> Self {
Self::splat(T::default())
}
}
impl<T, const N: usize> From<[T; N]> for Vector<T, N> {
#[inline(always)]
fn from(data: [T; N]) -> Self {
Self { data }
}
}
impl<T, const N: usize> Index<usize> for Vector<T, N> {
type Output = T;
#[inline(always)]
fn index(&self, i: usize) -> &T {
&self.data[i]
}
}
impl<T, const N: usize> IndexMut<usize> for Vector<T, N> {
#[inline(always)]
fn index_mut(&mut self, i: usize) -> &mut T {
&mut self.data[i]
}
}