| 2 Array containers that support vector space operations on floats. |
2 Array containers that support vector space operations on floats. |
| 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 crate::euclidean::*; |
6 use crate::euclidean::*; |
| 7 use crate::instance::{BasicDecomposition, Instance, MyCow, Ownable}; |
7 use crate::instance::{BasicDecomposition, Instance}; |
| 8 use crate::linops::{Linear, Mapping, VectorSpace, AXPY}; |
8 use crate::linops::{Linear, Mapping, VectorSpace, AXPY}; |
| 9 use crate::mapping::Space; |
9 use crate::mapping::Space; |
| 10 use crate::maputil::{map1, map1_mut, map2, map2_mut, FixedLength, FixedLengthMut}; |
10 use crate::maputil::{map1, map1_mut, map2, map2_mut, FixedLength, FixedLengthMut}; |
| 11 use crate::norms::*; |
11 use crate::norms::*; |
| |
12 use crate::self_ownable; |
| 12 use crate::types::{Float, Num, SignedNum}; |
13 use crate::types::{Float, Num, SignedNum}; |
| 13 use serde::ser::{Serialize, SerializeSeq, Serializer}; |
14 use serde::ser::{Serialize, SerializeSeq, Serializer}; |
| 14 use std::fmt::{Display, Formatter}; |
15 use std::fmt::{Display, Formatter}; |
| 15 use std::ops::{ |
16 use std::ops::{ |
| 16 Add, AddAssign, Div, DivAssign, Index, IndexMut, Mul, MulAssign, Neg, Sub, SubAssign, |
17 Add, AddAssign, Div, DivAssign, Index, IndexMut, Mul, MulAssign, Neg, Sub, SubAssign, |
| 25 pub struct Loc<const N: usize, F = f64>( |
26 pub struct Loc<const N: usize, F = f64>( |
| 26 /// An array of the elements of the vector |
27 /// An array of the elements of the vector |
| 27 pub [F; N], |
28 pub [F; N], |
| 28 ); |
29 ); |
| 29 |
30 |
| 30 /// Trait for ownable-by-consumption objects |
31 self_ownable!(Loc<N, F> where const N: usize, F: Copy); |
| 31 impl<const N: usize, F: Copy> Ownable for Loc<N, F> { |
|
| 32 type OwnedVariant = Self; |
|
| 33 |
|
| 34 #[inline] |
|
| 35 fn into_owned(self) -> Self::OwnedVariant { |
|
| 36 self |
|
| 37 } |
|
| 38 |
|
| 39 /// Returns an owned instance of a reference. |
|
| 40 fn clone_owned(&self) -> Self::OwnedVariant { |
|
| 41 self.clone() |
|
| 42 } |
|
| 43 |
|
| 44 /// Returns an owned instance of a reference. |
|
| 45 fn cow_owned<'b>(self) -> MyCow<'b, Self::OwnedVariant> |
|
| 46 where |
|
| 47 Self: 'b, |
|
| 48 { |
|
| 49 MyCow::Owned(self) |
|
| 50 } |
|
| 51 } |
|
| 52 |
32 |
| 53 impl<F: Display, const N: usize> Display for Loc<N, F> { |
33 impl<F: Display, const N: usize> Display for Loc<N, F> { |
| 54 // Required method |
34 // Required method |
| 55 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { |
35 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { |
| 56 write!(f, "[")?; |
36 write!(f, "[")?; |