aeon_tk/element/
support.rs1use crate::geometry::IndexSpace;
2
3pub trait Support<const N: usize> {
4 fn num_points(&self) -> usize;
5 fn point(&self, i: usize) -> [f64; N];
6}
7
8pub struct Uniform<const N: usize>([usize; N]);
10
11impl<const N: usize> Uniform<N> {
12 pub fn new(width: [usize; N]) -> Self {
13 Self(width)
14 }
15}
16
17impl<const N: usize> Support<N> for Uniform<N> {
18 fn num_points(&self) -> usize {
19 self.0.iter().product()
20 }
21
22 fn point(&self, i: usize) -> [f64; N] {
23 let spacing: [f64; N] = std::array::from_fn(|i| 2.0 / (self.0[i] - 1) as f64);
24 let cartesian = IndexSpace::new(self.0).cartesian_from_linear(i);
25
26 std::array::from_fn(|i| spacing[i] * cartesian[i] as f64 - 1.0)
27 }
28}