spatialrust_core/
metadata.rs1use spatialrust_math::Vec3;
2
3#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
5#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
6pub struct FrameId(pub String);
7
8impl FrameId {
9 #[must_use]
11 pub fn new(value: impl Into<String>) -> Self {
12 Self(value.into())
13 }
14}
15
16#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
18#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
19pub struct Timestamp(pub u64);
20
21impl Timestamp {
22 #[must_use]
24 pub const fn from_nanos(value: u64) -> Self {
25 Self(value)
26 }
27
28 #[must_use]
30 pub const fn as_nanos(self) -> u64 {
31 self.0
32 }
33}
34
35#[derive(Clone, Debug, Default, PartialEq)]
37#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
38pub struct SpatialMetadata {
39 pub frame_id: FrameId,
41 pub timestamp: Timestamp,
43 pub sensor_origin: Option<Vec3<f32>>,
45 pub unit: String,
47}
48
49impl SpatialMetadata {
50 #[must_use]
52 pub fn new(frame_id: impl Into<FrameId>, timestamp: Timestamp) -> Self {
53 Self { frame_id: frame_id.into(), timestamp, unit: "meter".to_owned(), ..Self::default() }
54 }
55}
56
57impl From<String> for FrameId {
58 fn from(value: String) -> Self {
59 Self(value)
60 }
61}
62
63impl From<&str> for FrameId {
64 fn from(value: &str) -> Self {
65 Self(value.to_owned())
66 }
67}