use std::fmt;
use crate::{Aabb, Obb};
#[derive(Debug, Clone, PartialEq)]
pub struct SemanticObject<ObjectCategory> {
index: i32,
category: Option<ObjectCategory>,
obb: Obb,
}
impl<ObjectCategory> SemanticObject<ObjectCategory> {
#[must_use]
pub const fn new(index: i32, category: Option<ObjectCategory>, obb: Obb) -> Self {
Self {
index,
category,
obb,
}
}
#[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 category(&self) -> Option<&ObjectCategory> {
self.category.as_ref()
}
#[must_use]
pub fn aabb(&self) -> Aabb {
self.obb.to_aabb()
}
#[must_use]
pub const fn obb(&self) -> &Obb {
&self.obb
}
}
impl<OC: fmt::Display> fmt::Display for SemanticObject<OC> {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
let category = self
.category
.as_ref()
.map_or_else(|| "none".to_string(), ToString::to_string);
write!(
formatter,
"object {}: category={}, {}",
self.index, category, self.obb
)
}
}