3 For working with small vectors in $ℝ^2$ or $ℝ^3$. |
3 For working with small vectors in $ℝ^2$ or $ℝ^3$. |
4 */ |
4 */ |
5 |
5 |
6 use std::ops::{Add,Sub,AddAssign,SubAssign,Mul,Div,MulAssign,DivAssign,Neg,Index,IndexMut}; |
6 use std::ops::{Add,Sub,AddAssign,SubAssign,Mul,Div,MulAssign,DivAssign,Neg,Index,IndexMut}; |
7 use std::slice::{Iter,IterMut}; |
7 use std::slice::{Iter,IterMut}; |
|
8 use std::fmt::{Display, Formatter}; |
8 use crate::types::{Float,Num,SignedNum}; |
9 use crate::types::{Float,Num,SignedNum}; |
9 use crate::maputil::{FixedLength,FixedLengthMut,map1,map2,map1_mut,map2_mut}; |
10 use crate::maputil::{FixedLength,FixedLengthMut,map1,map2,map1_mut,map2_mut}; |
10 use crate::euclidean::*; |
11 use crate::euclidean::*; |
11 use crate::norms::*; |
12 use crate::norms::*; |
12 use crate::linops::AXPY; |
13 use crate::linops::AXPY; |
19 #[derive(Copy,Clone,Debug,PartialEq,Eq)] |
20 #[derive(Copy,Clone,Debug,PartialEq,Eq)] |
20 pub struct Loc<F, const N : usize>( |
21 pub struct Loc<F, const N : usize>( |
21 /// An array of the elements of the vector |
22 /// An array of the elements of the vector |
22 pub [F; N] |
23 pub [F; N] |
23 ); |
24 ); |
|
25 |
|
26 impl<F : Display, const N : usize> Display for Loc<F, N>{ |
|
27 // Required method |
|
28 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { |
|
29 write!(f, "[")?; |
|
30 let mut comma = ""; |
|
31 for e in self.iter() { |
|
32 write!(f, "{comma}{e}")?; |
|
33 comma = ", "; |
|
34 } |
|
35 write!(f, "]") |
|
36 } |
|
37 } |
24 |
38 |
25 // Need to manually implement as [F; N] serialisation is provided only for some N. |
39 // Need to manually implement as [F; N] serialisation is provided only for some N. |
26 impl<F, const N : usize> Serialize for Loc<F, N> |
40 impl<F, const N : usize> Serialize for Loc<F, N> |
27 where |
41 where |
28 F: Serialize, |
42 F: Serialize, |