semantic_scene/scene/
object.rs1use std::fmt;
4
5use crate::{Aabb, Obb};
6
7#[derive(Debug, Clone, PartialEq)]
11pub struct SemanticObject<ObjectCategory> {
12 index: i32,
13 category: Option<ObjectCategory>,
14 obb: Obb,
15}
16
17impl<ObjectCategory> SemanticObject<ObjectCategory> {
18 #[must_use]
22 pub const fn new(index: i32, category: Option<ObjectCategory>, obb: Obb) -> Self {
23 Self {
24 index,
25 category,
26 obb,
27 }
28 }
29
30 #[must_use]
32 pub const fn index(&self) -> i32 {
33 self.index
34 }
35
36 #[must_use]
38 pub const fn semantic_id(&self) -> i32 {
39 self.index
40 }
41
42 #[must_use]
44 pub const fn category(&self) -> Option<&ObjectCategory> {
45 self.category.as_ref()
46 }
47
48 #[must_use]
50 pub fn aabb(&self) -> Aabb {
51 self.obb.to_aabb()
52 }
53
54 #[must_use]
56 pub const fn obb(&self) -> &Obb {
57 &self.obb
58 }
59}
60
61impl<OC: fmt::Display> fmt::Display for SemanticObject<OC> {
62 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
63 let category = self
64 .category
65 .as_ref()
66 .map_or_else(|| "none".to_string(), ToString::to_string);
67 write!(
68 formatter,
69 "object {}: category={}, {}",
70 self.index, category, self.obb
71 )
72 }
73}