semantic_scene/scene/
level.rs1use std::fmt;
4
5use crate::{Aabb, Vec3};
6
7#[derive(Debug, Clone, PartialEq)]
12pub struct SemanticLevel {
13 index: i32,
14 label: String,
15 position: Vec3,
16 aabb: Aabb,
17 region_indices: Vec<usize>,
18 object_indices: Vec<usize>,
19}
20
21impl SemanticLevel {
22 #[must_use]
23 pub(crate) const fn new(index: i32, label: String, position: Vec3, aabb: Aabb) -> Self {
24 Self {
25 index,
26 label,
27 position,
28 aabb,
29 region_indices: Vec::new(),
30 object_indices: Vec::new(),
31 }
32 }
33
34 #[must_use]
39 pub fn id(&self) -> String {
40 self.index.to_string()
41 }
42
43 #[must_use]
45 pub const fn index(&self) -> i32 {
46 self.index
47 }
48
49 #[must_use]
51 pub fn label(&self) -> &str {
52 &self.label
53 }
54
55 #[must_use]
57 pub const fn position(&self) -> Vec3 {
58 self.position
59 }
60
61 #[must_use]
63 pub const fn aabb(&self) -> &Aabb {
64 &self.aabb
65 }
66
67 #[must_use]
69 pub fn region_indices(&self) -> &[usize] {
70 &self.region_indices
71 }
72
73 #[must_use]
75 pub fn object_indices(&self) -> &[usize] {
76 &self.object_indices
77 }
78
79 pub(crate) fn add_region(&mut self, region_index: usize) {
80 self.region_indices.push(region_index);
81 }
82
83 pub(crate) fn add_object(&mut self, object_index: usize) {
84 self.object_indices.push(object_index);
85 }
86}
87
88impl fmt::Display for SemanticLevel {
89 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
90 write!(
91 formatter,
92 "level {}: regions={}, objects={}, bounds=[{}]",
93 self.index,
94 self.region_indices.len(),
95 self.object_indices.len(),
96 self.aabb
97 )
98 }
99}