1use std::ops;
2
3use nalgebra::{SimdRealField, SVector};
4
5#[derive(Debug, Clone, PartialEq)]
8pub struct BVector<T: SimdRealField + Copy, const N: usize> {
9 pub data_vector: SVector<T, N>,
10}
11
12impl<T: SimdRealField + Copy, const N: usize> BVector<T, N> {
13 pub fn from_element(element: T) -> Self {
15 BVector {
16 data_vector: SVector::<T, N>::from_element(element),
17 }
18 }
19
20 pub fn from_array(data: [T; N]) -> Self
22 where
23 T: Copy,
24 {
25 BVector {
26 data_vector: SVector::<T, N>::from_row_slice(&data),
27 }
28 }
29
30 pub fn dot(&self, other: &Self) -> T {
31 self.data_vector.dot(&other.data_vector)
32 }
33
34 pub fn len(&self) -> usize {
35 N
36 }
37
38 pub fn get(&self, index: usize) -> T {
39 assert!(index < N, "Index out of bounds");
40 self.data_vector[index]
41 }
42}
43
44impl<T: SimdRealField + Copy, const N: usize> ops::Add for BVector<T, N> {
45 type Output = BVector<T, N>;
46
47 fn add(self, rhs: Self) -> Self::Output {
48 BVector {
49 data_vector: self.data_vector + rhs.data_vector,
50 }
51 }
52}
53
54#[macro_export]
61macro_rules! bvector {
62 ($($x:expr),+ $(,)?) => {
63 {
64 $crate::BVector::from_array([$( $x ),+])
66 }
67 };
68}
69