pub trait Vector {
type VectorType;
fn zeros() -> Self::VectorType;
fn ones() -> Self::VectorType;
fn mul(&self, rhs: &[f32]) -> Self::VectorType;
fn add(&self, rhs: &[f32]) -> Self::VectorType;
fn sub(&self, rhs: &[f32]) -> Self::VectorType;
fn scale(&self, factor: f32) -> Self::VectorType;
fn mag(&self) -> f32;
fn mag2(&self) -> f32;
fn dot(&self, rhs: &[f32]) -> f32;
}
#[cfg(any(feature = "Matrix4", feature = "Matrix3"))]
pub trait MulVectorMatrix<Matrix> {
type VectorType;
fn mul_matrix_left(&self, lhs: &Matrix) -> Self::VectorType;
fn mul_matrix(&self, rhs: &Matrix) -> Self::VectorType;
}
macro_rules! impl_vector {
($type:ty, $n:expr) => {
impl Vector for $type {
type VectorType = $type;
fn zeros() -> $type {
[0.; $n]
}
fn ones() -> $type {
[1.; $n]
}
fn mul(&self, rhs: &[f32]) -> $type {
let mut dst = *self;
mul(&mut dst, rhs);
dst
}
fn add(&self, rhs: &[f32]) -> $type {
let mut dst = *self;
add(&mut dst, rhs);
dst
}
fn sub(&self, rhs: &[f32]) -> $type {
let mut dst = *self;
sub(&mut dst, rhs);
dst
}
fn scale(&self, factor: f32) -> $type {
let mut dst = *self;
scale(&mut dst, factor);
dst
}
fn mag(&self) -> f32 {
mag(self)
}
fn mag2(&self) -> f32 {
mag2(self)
}
fn dot(&self, rhs: &[f32]) -> f32 {
dot(self, rhs)
}
}
};
}