omf/data/
traits.rs

1use chrono::{DateTime, NaiveDate, Utc};
2
3use crate::pqarray::PqArrayType;
4
5pub trait FloatType: PqArrayType + Copy + Into<f64> + PartialOrd + Default + 'static {
6    const ZERO: Self;
7    const ONE: Self;
8}
9
10impl FloatType for f32 {
11    const ZERO: Self = 0.0;
12    const ONE: Self = 1.0;
13}
14
15impl FloatType for f64 {
16    const ZERO: Self = 0.0;
17    const ONE: Self = 1.0;
18}
19
20pub trait NumberType: PqArrayType + Copy + PartialOrd + Default + 'static {}
21
22impl NumberType for f32 {}
23impl NumberType for f64 {}
24impl NumberType for i64 {}
25impl NumberType for NaiveDate {}
26impl NumberType for DateTime<Utc> {}
27
28pub trait VectorSource<T: FloatType>: 'static {
29    const IS_3D: bool;
30    fn into_2d(self) -> [T; 2];
31    fn into_3d(self) -> [T; 3];
32}
33
34impl<T: FloatType> VectorSource<T> for [T; 2] {
35    const IS_3D: bool = false;
36
37    fn into_2d(self) -> [T; 2] {
38        [self[0], self[1]]
39    }
40
41    fn into_3d(self) -> [T; 3] {
42        [self[0], self[1], T::default()]
43    }
44}
45
46impl<T: FloatType> VectorSource<T> for [T; 3] {
47    const IS_3D: bool = true;
48
49    fn into_2d(self) -> [T; 2] {
50        [self[0], self[1]]
51    }
52
53    fn into_3d(self) -> [T; 3] {
54        [self[0], self[1], self[2]]
55    }
56}