mod component;
mod iter;
mod vector2d;
mod vector3d;
pub use self::{
component::Component,
iter::Iter,
vector2d::{F32x2, I16x2, I32x2, I8x2, U16x2, U32x2, U8x2, Vector2d},
vector3d::{F32x3, I16x3, I32x3, I8x3, U16x3, U32x3, U8x3, Vector3d},
};
use core::{fmt::Debug, iter::FromIterator};
#[allow(unused_imports)]
use crate::F32Ext;
pub trait Vector<C>: Copy + Debug + Default + FromIterator<C> + Send + Sync
where
C: Component,
{
const AXES: usize;
fn get(self, index: usize) -> Option<C>;
fn dot(self, rhs: Self) -> C;
fn from_slice(slice: &[C]) -> Self {
Self::from_iter(slice.iter().cloned())
}
fn iter(&self) -> Iter<'_, Self, C> {
Iter::new(self)
}
fn distance(self, rhs: Self) -> f32
where
C: Into<f32>,
{
let differences = self
.iter()
.zip(rhs.iter())
.map(|(a, b)| a.into() - b.into());
differences.map(|n| n * n).sum::<f32>().sqrt()
}
fn magnitude(self) -> f32
where
C: Into<f32>,
{
self.iter()
.map(|n| {
let n = n.into();
n * n
})
.sum::<f32>()
.sqrt()
}
}