1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use crate::{
access,
err::Error,
file::Build,
geom::{Cube, Grid},
ord::{X, Y, Z},
};
use arctk_attr::load;
use std::path::Path;
#[load]
#[derive(Clone)]
pub struct GridBuilder {
boundary: Cube,
res: [usize; 3],
}
impl GridBuilder {
access!(boundary, Cube);
access!(res, [usize; 3]);
#[inline]
#[must_use]
pub fn new(boundary: Cube, res: [usize; 3]) -> Self {
debug_assert!(res[X] > 0);
debug_assert!(res[Y] > 0);
debug_assert!(res[Z] > 0);
Self { boundary, res }
}
#[inline]
#[must_use]
pub const fn num_cells(&self) -> usize {
self.res[X] * self.res[Y] * self.res[Z]
}
}
impl Build for GridBuilder {
type Inst = crate::geom::Grid;
#[inline]
fn build(self, _in_dir: &Path) -> Result<Self::Inst, Error> {
Ok(Grid::new(self.boundary, self.res))
}
}