lib_jsl_geometry/
dim_3.rs1use lib_jsl_core::ErrorsJSL;
4pub mod line3d;
6pub mod free_vector3d;
8pub(crate) mod coordinate_conversions;
10pub mod surface_mesh3d;
12pub mod plane3d;
14pub mod coordinate_vector3d;
16pub mod polygon_face3d;
18pub mod triangle3d;
20pub mod tetrahedron3d;
22pub mod volume_mesh3d;
24pub(crate) mod transform_support;
25pub mod unit_vector3d;
27
28use crate::common::{
29 FaceId, GeometricPrimitive, GeometryMeasure, HasCenter, HasCentroid, HasEdges, HasFaces,
30 HasTetrahedra, HasVertices, IsUnitVector, PointId, TetrahedronId,
31};
32use crate::one_d::IsLine;
33use crate::two_d::IsPolygon;
34use crate::zero_d::IsPoint;
35pub use line3d::Line3D;
36pub use free_vector3d::FreeVector3D;
37pub use surface_mesh3d::SurfaceMesh3D;
38pub use plane3d::Plane3D;
39pub use coordinate_vector3d::CoordinateVector3D;
40pub use polygon_face3d::PolygonFace3D;
41pub use tetrahedron3d::Tetrahedron3D;
42pub use triangle3d::Triangle3D;
43pub use unit_vector3d::UnitVector3D;
44pub use volume_mesh3d::VolumeMesh3D;
45
46pub trait IsSphere<T: IsPoint>:
48 GeometricPrimitive + HasCenter<Point = T> + crate::common::HasMeasure
49{
50 fn radius(&self) -> GeometryMeasure;
52 fn diameter(&self) -> GeometryMeasure;
54 fn surface_area(&self) -> GeometryMeasure;
56 fn volume(&self) -> GeometryMeasure;
58}
59
60pub trait IsTetrahedron<'a, T: IsPoint, N: IsUnitVector>:
62 GeometricPrimitive + HasVertices<'a, Vertex = T> + HasEdges + HasCentroid<Point = T> + crate::common::HasMeasure
63where
64 <Self as HasEdges>::Edge: IsLine<'a, T>,
65{
66 fn a_id(&self) -> PointId;
68 fn set_a_id(&mut self, point_id: PointId) -> Result<(), ErrorsJSL>;
70 fn b_id(&self) -> PointId;
72 fn set_b_id(&mut self, point_id: PointId) -> Result<(), ErrorsJSL>;
74 fn c_id(&self) -> PointId;
76 fn set_c_id(&mut self, point_id: PointId) -> Result<(), ErrorsJSL>;
78 fn d_id(&self) -> PointId;
80 fn set_d_id(&mut self, point_id: PointId) -> Result<(), ErrorsJSL>;
82
83 fn a(&self) -> Option<T> {
85 self.get_vertex(&self.a_id())
86 }
87
88 fn b(&self) -> Option<T> {
90 self.get_vertex(&self.b_id())
91 }
92
93 fn c(&self) -> Option<T> {
95 self.get_vertex(&self.c_id())
96 }
97
98 fn d(&self) -> Option<T> {
100 self.get_vertex(&self.d_id())
101 }
102
103 fn faces(&self) -> [Triangle3D; 4];
105 fn face_count(&self) -> usize;
107 fn surface_area(&self) -> GeometryMeasure;
109 fn signed_volume(&self) -> GeometryMeasure;
111 fn volume(&self) -> GeometryMeasure;
113}
114
115pub trait IsMesh<'a, T: IsPoint, N: IsUnitVector>:
122 GeometricPrimitive
123 + HasVertices<'a, Vertex = T>
124 + HasFaces<'a, Point = T, Normal = N>
125 + HasEdges
126where
127 <Self as HasEdges>::Edge: IsLine<'a, T>,
128{
129 fn face_ids(&self) -> Box<dyn Iterator<Item = FaceId> + '_>;
131 fn set_face_id(&mut self, index: usize, face_id: FaceId) -> Result<(), ErrorsJSL>;
133 fn face_count(&self) -> usize {
135 self.face_ids().count()
136 }
137 fn face(&self, index: usize) -> Option<<Self as HasFaces<'a>>::Face> {
139 self.face_ids().nth(index).and_then(|face_id| self.get_face(&face_id))
140 }
141 fn surface_area(&self) -> GeometryMeasure;
143 fn face_normal(&self, index: usize) -> Option<N> {
145 self.face(index).map(|face| face.normal())
146 }
147}
148
149pub trait IsSurfaceMesh<'a, T: IsPoint, N: IsUnitVector>: IsMesh<'a, T, N>
154where
155 <Self as HasEdges>::Edge: IsLine<'a, T>,
156{
157}
158
159impl<'a, T, N, M> IsSurfaceMesh<'a, T, N> for M
160where
161 T: IsPoint,
162 N: IsUnitVector,
163 M: IsMesh<'a, T, N>,
164 <M as HasEdges>::Edge: IsLine<'a, T>,
165{
166}
167
168pub trait IsVolumeMesh<'a, T: IsPoint, N: IsUnitVector>:
170 GeometricPrimitive
171 + HasVertices<'a, Vertex = T>
172 + HasTetrahedra<'a, Point = T, Normal = N>
173 + HasEdges
174where
175 <Self as HasEdges>::Edge: IsLine<'a, T>,
176{
177 fn tetrahedron_ids(&self) -> Box<dyn Iterator<Item = TetrahedronId> + '_>;
179 fn set_tetrahedron_id(&mut self, index: usize, tetrahedron_id: TetrahedronId) -> Result<(), ErrorsJSL>;
181 fn tetrahedron_count(&self) -> usize {
183 self.tetrahedron_ids().count()
184 }
185 fn tetrahedron(&self, index: usize) -> Option<<Self as HasTetrahedra<'a>>::Tetrahedron> {
187 self.tetrahedron_ids()
188 .nth(index)
189 .and_then(|tetrahedron_id| self.get_tetrahedron(&tetrahedron_id))
190 }
191 fn volume(&self) -> GeometryMeasure;
193}