robot_description_builder/link/
geometry.rs1mod box_geometry;
2mod cylinder_geometry;
3mod geometry_shape_data;
4mod mesh_geometry;
5use nalgebra::Matrix3;
6mod sphere_geometry;
7
8pub use box_geometry::BoxGeometry;
9pub use cylinder_geometry::CylinderGeometry;
10pub use mesh_geometry::MeshGeometry;
11pub use sphere_geometry::SphereGeometry;
12
13pub use geometry_shape_data::GeometryShapeData;
14
15pub use geometry_shape_data::GeometryShapeContainer;
17
18use std::fmt::Debug;
19
20use crate::transform::Mirror;
21
22pub trait BoxedMirror {
26 fn boxed_mirrored(
28 &self,
29 mirror_matrix: &Matrix3<f32>,
30 ) -> Box<dyn GeometryInterface + Sync + Send>;
31}
32
33impl<Geometry> BoxedMirror for Geometry
34where
35 Geometry: GeometryInterface + Mirror + Sync + Send,
36{
37 fn boxed_mirrored(
38 &self,
39 mirror_matrix: &Matrix3<f32>,
40 ) -> Box<dyn GeometryInterface + Sync + Send> {
41 self.mirrored(mirror_matrix).boxed_clone()
42 }
43}
44
45pub trait GeometryInterface: Debug + BoxedMirror {
48 fn volume(&self) -> f32;
50 fn surface_area(&self) -> f32;
52 fn boxed_clone(&self) -> Box<dyn GeometryInterface + Sync + Send>;
56
57 fn bounding_box(&self) -> (f32, f32, f32);
59
60 fn shape_container(&self) -> GeometryShapeContainer;
62}
63
64impl Mirror for Box<dyn GeometryInterface + Sync + Send> {
65 fn mirrored(&self, mirror_matrix: &Matrix3<f32>) -> Self {
66 self.boxed_mirrored(mirror_matrix)
67 }
68}
69
70impl PartialEq for (dyn GeometryInterface + Sync + Send) {
71 fn eq(&self, other: &Self) -> bool {
72 self.volume() == other.volume()
74 && self.surface_area() == other.surface_area()
75 && self.bounding_box() == other.bounding_box()
76 }
77}
78
79impl From<&(dyn GeometryInterface + Sync + Send)> for Box<dyn GeometryInterface + Sync + Send> {
80 fn from(value: &(dyn GeometryInterface + Sync + Send)) -> Self {
81 value.boxed_clone()
82 }
83}