fj_core/objects/
stores.rs

1use crate::storage::{Handle, Store};
2
3use super::{
4    Curve, Cycle, Face, HalfEdge, Region, Shell, Sketch, Solid, Surface, Vertex,
5};
6
7/// The available object stores
8#[derive(Debug, Default)]
9pub struct Objects {
10    /// Store for [`Curve`]s
11    pub curves: Store<Curve>,
12
13    /// Store for [`Cycle`]s
14    pub cycles: Store<Cycle>,
15
16    /// Store for [`Face`]s
17    pub faces: Store<Face>,
18
19    /// Store for [`HalfEdge`]s
20    pub half_edges: Store<HalfEdge>,
21
22    /// Store for [`Region`]s
23    pub regions: Store<Region>,
24
25    /// Store for [`Shell`]s
26    pub shells: Store<Shell>,
27
28    /// Store for [`Sketch`]es
29    pub sketches: Store<Sketch>,
30
31    /// Store for [`Solid`]s
32    pub solids: Store<Solid>,
33
34    /// Store for [`Surface`]s
35    pub surfaces: Surfaces,
36
37    /// Store for [`Vertex`] objects
38    pub vertices: Store<Vertex>,
39}
40
41impl Objects {
42    /// Construct a new instance of `Stores`
43    pub fn new() -> Self {
44        Self::default()
45    }
46}
47
48/// Store for [`Surface`]s
49#[derive(Debug)]
50pub struct Surfaces {
51    store: Store<Surface>,
52
53    xy_plane: Handle<Surface>,
54    xz_plane: Handle<Surface>,
55    yz_plane: Handle<Surface>,
56}
57
58impl Surfaces {
59    /// Reserve a slot for an object in the store
60    pub fn reserve(&self) -> Handle<Surface> {
61        self.store.reserve()
62    }
63
64    /// Insert an object into the store
65    pub fn insert(&mut self, handle: Handle<Surface>, surface: Surface) {
66        self.store.insert(handle, surface);
67    }
68
69    /// Access the xy-plane
70    pub fn xy_plane(&self) -> Handle<Surface> {
71        self.xy_plane.clone()
72    }
73
74    /// Access the xz-plane
75    pub fn xz_plane(&self) -> Handle<Surface> {
76        self.xz_plane.clone()
77    }
78
79    /// Access the yz-plane
80    pub fn yz_plane(&self) -> Handle<Surface> {
81        self.yz_plane.clone()
82    }
83}
84
85impl Default for Surfaces {
86    fn default() -> Self {
87        let mut store: Store<Surface> = Store::new();
88
89        let xy_plane = store.reserve();
90        store.insert(xy_plane.clone(), Surface::new());
91
92        let xz_plane = store.reserve();
93        store.insert(xz_plane.clone(), Surface::new());
94
95        let yz_plane = store.reserve();
96        store.insert(yz_plane.clone(), Surface::new());
97
98        Self {
99            store,
100            xy_plane,
101            xz_plane,
102            yz_plane,
103        }
104    }
105}