use std::ops;
use nalgebra::{SimdRealField, SVector};
#[derive(Debug, Clone, PartialEq)]
pub struct BVector<T: SimdRealField + Copy, const N: usize> {
pub data_vector: SVector<T, N>,
}
impl<T: SimdRealField + Copy, const N: usize> BVector<T, N> {
pub fn from_element(element: T) -> Self {
BVector {
data_vector: SVector::<T, N>::from_element(element),
}
}
pub fn from_array(data: [T; N]) -> Self
where
T: Copy,
{
BVector {
data_vector: SVector::<T, N>::from_row_slice(&data),
}
}
pub fn dot(&self, other: &Self) -> T {
self.data_vector.dot(&other.data_vector)
}
pub fn len(&self) -> usize {
N
}
pub fn is_empty(&self) -> bool {
N == 0
}
pub fn get(&self, index: usize) -> T {
assert!(index < N, "Index out of bounds");
self.data_vector[index]
}
}
impl<T: SimdRealField + Copy, const N: usize> ops::Add for BVector<T, N> {
type Output = BVector<T, N>;
fn add(self, rhs: Self) -> Self::Output {
BVector {
data_vector: self.data_vector + rhs.data_vector,
}
}
}
#[macro_export]
macro_rules! bvector {
($($x:expr),+ $(,)?) => {
{
$crate::BVector::from_array([$( $x ),+])
}
};
}