robot_description_builder/link/
geometry.rs

1mod 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
15// TODO: Maybe only exported for `wrapping` feature
16pub use geometry_shape_data::GeometryShapeContainer;
17
18use std::fmt::Debug;
19
20use crate::transform::Mirror;
21
22// use self::geometry_shape_data::GeometryShapeContainer;
23
24/// A trait to mirror items inside of a `Box<T>`.
25pub trait BoxedMirror {
26	/// Performs a `Mirror::mirrored` on a Boxed Implementor.
27	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
45/// An interface for working with `Geometry`s generically.
46// LONGTERM-TODO: DECIDE IF `Box<dyn dyn GeometryInterface + Sync + Send>` should be replaced with [`GeometryShapeContainer`]
47pub trait GeometryInterface: Debug + BoxedMirror {
48	/// Provides the volume of a `Geometry`.
49	fn volume(&self) -> f32;
50	/// Provides the surface area of a `Geometry`.
51	fn surface_area(&self) -> f32;
52	/// Allows for Cloning of Boxed Geometries.
53	///
54	/// This has similiar functionality to [`Clone::clone`] except that it allows items to be [`Box`ed](Box).
55	fn boxed_clone(&self) -> Box<dyn GeometryInterface + Sync + Send>;
56
57	/// Get's the untransformed boundingbox size of the geometry from it's center. (X, Y, Z).
58	fn bounding_box(&self) -> (f32, f32, f32);
59
60	/// Gets a `GeometryShapeContainer` of the current Shape.
61	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		// Should probably just get shape data
73		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}