48 lines
1.2 KiB
Rust
48 lines
1.2 KiB
Rust
// SPDX-FileCopyrightText: 2026 Milovann Yanatchkov
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
use crate::Entity;
|
|
|
|
/// A building — a named gathering of storeys. A container: no mesh of its
|
|
/// own; the storeys (and their members) carry the geometry.
|
|
#[derive(Debug, Clone)]
|
|
pub struct Building {
|
|
name: String,
|
|
storeys: Vec<Entity>,
|
|
}
|
|
|
|
impl Building {
|
|
pub fn new(name: String, storeys: Vec<Entity>) -> Self {
|
|
Self { name, storeys }
|
|
}
|
|
|
|
/// The building name.
|
|
pub fn name(&self) -> &str {
|
|
&self.name
|
|
}
|
|
|
|
/// The gathered storeys, bottom-up.
|
|
pub fn storeys(&self) -> &[Entity] {
|
|
&self.storeys
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
use crate::element::architecture::Storey;
|
|
use crate::geometry::Point;
|
|
|
|
#[test]
|
|
fn a_building_gathers_storeys() {
|
|
let l0 = Storey::new(0.0, vec![Entity::Point(Point::new(0.0, 0.0, 0.0))]);
|
|
let l1 = Storey::new(3000.0, vec![Entity::Point(Point::new(0.0, 0.0, 3000.0))]);
|
|
let b = Building::new(
|
|
"b03".to_string(),
|
|
vec![Entity::Storey(l0), Entity::Storey(l1)],
|
|
);
|
|
assert_eq!(b.name(), "b03");
|
|
assert_eq!(b.storeys().len(), 2);
|
|
assert!(matches!(b.storeys()[0], Entity::Storey(_)));
|
|
}
|
|
}
|