use std::fmt;
use crate::{Aabb, Vec3};
use super::{SemanticObject, SemanticRegion};
#[derive(Debug, Clone, PartialEq)]
pub struct SemanticLevel<ObjectCategory, RegionCategory> {
index: i32,
label: String,
position: Vec3,
aabb: Aabb,
regions: Vec<SemanticRegion<ObjectCategory, RegionCategory>>,
}
impl<ObjectCategory, RegionCategory> SemanticLevel<ObjectCategory, RegionCategory> {
#[must_use]
pub const fn new(
index: i32,
label: String,
position: Vec3,
aabb: Aabb,
regions: Vec<SemanticRegion<ObjectCategory, RegionCategory>>,
) -> Self {
Self {
index,
label,
position,
aabb,
regions,
}
}
#[must_use]
pub fn id(&self) -> String {
self.index.to_string()
}
#[must_use]
pub const fn index(&self) -> i32 {
self.index
}
#[must_use]
pub fn label(&self) -> &str {
&self.label
}
#[must_use]
pub const fn position(&self) -> Vec3 {
self.position
}
#[must_use]
pub const fn aabb(&self) -> &Aabb {
&self.aabb
}
#[must_use]
pub fn regions(&self) -> &[SemanticRegion<ObjectCategory, RegionCategory>] {
&self.regions
}
pub fn objects(&self) -> impl Iterator<Item = &SemanticObject<ObjectCategory>> {
self.regions.iter().flat_map(SemanticRegion::objects)
}
}
impl<OC, RC> fmt::Display for SemanticLevel<OC, RC> {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
formatter,
"level {}: regions={}, objects={}, bounds=[{}]",
self.index,
self.regions.len(),
self.objects().count(),
self.aabb
)
}
}