fj_kernel/objects/
stores.rs

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