lib_jsl_geometry/
registry.rs1use crate::common::{
15 FaceId, IsGeometryTableBase, LineId, PointId, TetrahedronId, TriangleId,
16};
17use crate::tables::{HashGeometryTable, SharedGeometryTable};
18use crate::three_d::{
19 Line3D, CoordinateVector3D, PolygonFace3D, Tetrahedron3D, Triangle3D, UnitVector3D,
20};
21use std::cell::RefCell;
22use std::rc::Rc;
23
24#[derive(Debug, Clone)]
29
30pub struct GeometryTableRegistry {
31 point_table: SharedGeometryTable<PointId, CoordinateVector3D>,
32 line_table: SharedGeometryTable<LineId, Line3D>,
33 face_table: SharedGeometryTable<FaceId, PolygonFace3D>,
34 triangle_table: SharedGeometryTable<TriangleId, Triangle3D>,
35 tetrahedron_table: SharedGeometryTable<TetrahedronId, Tetrahedron3D>,
36}
37
38impl GeometryTableRegistry {
39 pub fn new() -> Self {
43 Self {
44 point_table: Rc::new(RefCell::new(HashGeometryTable::new())),
45 line_table: Rc::new(RefCell::new(HashGeometryTable::new())),
46 face_table: Rc::new(RefCell::new(HashGeometryTable::new())),
47 triangle_table: Rc::new(RefCell::new(HashGeometryTable::new())),
48 tetrahedron_table: Rc::new(RefCell::new(HashGeometryTable::new())),
49 }
50 }
51}
52
53impl Default for GeometryTableRegistry {
54 fn default() -> Self {
55 Self::new()
56 }
57}
58
59impl<'a> IsGeometryTableBase<'a> for GeometryTableRegistry {
60 type Point = CoordinateVector3D;
61 type Normal = UnitVector3D;
62 type Line = Line3D;
63 type Face = PolygonFace3D;
64 type Triangle = Triangle3D;
65 type Tetrahedron = Tetrahedron3D;
66 type PointTable = SharedGeometryTable<PointId, CoordinateVector3D>;
67 type LineTable = SharedGeometryTable<LineId, Line3D>;
68 type FaceTable = SharedGeometryTable<FaceId, PolygonFace3D>;
69 type TriangleTable = SharedGeometryTable<TriangleId, Triangle3D>;
70 type TetrahedronTable = SharedGeometryTable<TetrahedronId, Tetrahedron3D>;
71
72 fn point_table(&self) -> &Self::PointTable {
73 &self.point_table
74 }
75
76 fn point_table_mut(&mut self) -> &mut Self::PointTable {
77 &mut self.point_table
78 }
79
80 fn line_table(&self) -> &Self::LineTable {
81 &self.line_table
82 }
83
84 fn line_table_mut(&mut self) -> &mut Self::LineTable {
85 &mut self.line_table
86 }
87
88 fn face_table(&self) -> &Self::FaceTable {
89 &self.face_table
90 }
91
92 fn face_table_mut(&mut self) -> &mut Self::FaceTable {
93 &mut self.face_table
94 }
95
96 fn triangle_table(&self) -> &Self::TriangleTable {
97 &self.triangle_table
98 }
99
100 fn triangle_table_mut(&mut self) -> &mut Self::TriangleTable {
101 &mut self.triangle_table
102 }
103
104 fn tetrahedron_table(&self) -> &Self::TetrahedronTable {
105 &self.tetrahedron_table
106 }
107
108 fn tetrahedron_table_mut(&mut self) -> &mut Self::TetrahedronTable {
109 &mut self.tetrahedron_table
110 }
111}