diff --git a/applications/autoware/common_types/src/geometry.rs b/applications/autoware/common_types/src/geometry.rs new file mode 100644 index 000000000..b666cae9b --- /dev/null +++ b/applications/autoware/common_types/src/geometry.rs @@ -0,0 +1,52 @@ +pub use crate::{Header, Vector3}; +use alloc::vec::Vec; + +/// Represents a 3D point with 32-bit floating point coordinates. +pub type Point32 = Vector3; + +/// Represents a polygon defined by a sequence of 3D points. +/// +/// The first and last points are assumed to be connected. +#[repr(transparent)] +#[derive(Debug, Clone)] +pub struct Polygon { + /// Sequence of 3D points defining the polygon. + pub points: Vec, +} + +impl Polygon { + #[inline] + pub const fn into_stamped(self, header: Header) -> PolygonStamped { + PolygonStamped { + header, + polygon: self, + } + } +} + +/// A polygon with a reference coordinate frame and timestamp. +#[derive(Debug, Clone)] +pub struct PolygonStamped { + pub header: Header, + pub polygon: Polygon, +} + +impl From for Polygon { + fn from(stamped: PolygonStamped) -> Self { + stamped.polygon + } +} + +impl core::ops::Deref for PolygonStamped { + type Target = Polygon; + + fn deref(&self) -> &Self::Target { + &self.polygon + } +} + +impl core::ops::DerefMut for PolygonStamped { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.polygon + } +} diff --git a/applications/autoware/common_types/src/lib.rs b/applications/autoware/common_types/src/lib.rs index 2f5859597..67d7882cb 100644 --- a/applications/autoware/common_types/src/lib.rs +++ b/applications/autoware/common_types/src/lib.rs @@ -16,6 +16,7 @@ extern crate alloc; +pub mod geometry; pub mod transform; #[derive(Debug, Clone)]