use std::fmt;
use crate::{Aabb, Obb, SemanticScene};
#[derive(Debug, Clone, PartialEq)]
pub struct SemanticObject {
index: i32,
region_index: Option<usize>,
category_index: Option<usize>,
obb: Obb,
}
impl SemanticObject {
#[must_use]
pub(crate) const fn new(
index: i32,
region_index: Option<usize>,
category_index: Option<usize>,
obb: Obb,
) -> Self {
Self {
index,
region_index,
category_index,
obb,
}
}
#[must_use]
pub fn id(&self, scene: &SemanticScene) -> String {
self.region_index.map_or_else(
|| format!("_{}", self.index),
|region_index| format!("{}_{}", scene.regions()[region_index].id(scene), self.index),
)
}
#[must_use]
pub const fn index(&self) -> i32 {
self.index
}
#[must_use]
pub const fn semantic_id(&self) -> i32 {
self.index
}
#[must_use]
pub const fn region_index(&self) -> Option<usize> {
self.region_index
}
#[must_use]
pub const fn category_index(&self) -> Option<usize> {
self.category_index
}
#[must_use]
pub fn aabb(&self) -> Aabb {
self.obb.to_aabb()
}
#[must_use]
pub const fn obb(&self) -> &Obb {
&self.obb
}
}
impl fmt::Display for SemanticObject {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
let region = self
.region_index
.map_or_else(|| "none".to_string(), |index| index.to_string());
let category = self
.category_index
.map_or_else(|| "none".to_string(), |index| index.to_string());
write!(
formatter,
"object {}: region={}, category={}, {}",
self.index, region, category, self.obb
)
}
}