ecitygml_core/model/
building.rs1use crate::model::construction::{GroundSurface, RoofSurface, WallSurface};
2use crate::model::core::OccupiedSpace;
3use crate::operations::{CityObjectVisitor, FeatureWithGeometry, Visitable};
4use egml::model::geometry::Envelope;
5use nalgebra::Isometry3;
6
7#[derive(Debug, Clone, PartialEq)]
8pub struct Building {
9 pub occupied_space: OccupiedSpace,
10 pub wall_surface: Vec<WallSurface>,
11 pub roof_surface: Vec<RoofSurface>,
12 pub ground_surface: Vec<GroundSurface>,
13 pub building_constructive_element: Vec<BuildingConstructiveElement>,
14}
15
16impl Building {
17 pub fn new(occupied_space: OccupiedSpace) -> Self {
18 Self {
19 occupied_space,
20 wall_surface: Vec::new(),
21 roof_surface: Vec::new(),
22 ground_surface: Vec::new(),
23 building_constructive_element: Vec::new(),
24 }
25 }
26}
27
28impl Visitable for Building {
29 fn accept<V: CityObjectVisitor>(&self, visitor: &mut V) {
30 visitor.visit_building(self);
31 self.wall_surface.iter().for_each(|x| x.accept(visitor));
32 self.roof_surface.iter().for_each(|x| x.accept(visitor));
33 self.ground_surface.iter().for_each(|x| x.accept(visitor));
34 self.building_constructive_element
35 .iter()
36 .for_each(|x| x.accept(visitor));
37 }
38}
39
40impl FeatureWithGeometry for Building {
41 fn envelope(&self) -> Option<Envelope> {
42 let mut envelopes: Vec<Option<Envelope>> = vec![];
44 envelopes.extend(self.wall_surface.iter().map(|x| x.envelope()));
45 envelopes.extend(self.roof_surface.iter().map(|x| x.envelope()));
46 envelopes.extend(self.ground_surface.iter().map(|x| x.envelope()));
47 envelopes.extend(
48 self.building_constructive_element
49 .iter()
50 .map(|x| x.envelope()),
51 );
52
53 Envelope::from_optional_envelopes(&envelopes).expect("should work")
54 }
55
56 fn apply_transform(&mut self, m: &Isometry3<f64>) {
57 self.wall_surface
59 .iter_mut()
60 .for_each(|x| x.apply_transform(m));
61 self.roof_surface
62 .iter_mut()
63 .for_each(|x| x.apply_transform(m));
64 self.ground_surface
65 .iter_mut()
66 .for_each(|x| x.apply_transform(m));
67 self.building_constructive_element
68 .iter_mut()
69 .for_each(|x| x.apply_transform(m));
70 }
71}
72
73#[derive(Debug, Clone, PartialEq)]
74pub struct BuildingConstructiveElement {
75 pub occupied_space: OccupiedSpace,
76}
77
78impl BuildingConstructiveElement {
79 pub fn new(occupied_space: OccupiedSpace) -> Self {
80 Self { occupied_space }
81 }
82}
83
84impl Visitable for BuildingConstructiveElement {
85 fn accept<V: CityObjectVisitor>(&self, visitor: &mut V) {
86 visitor.visit_building_constructive_element(self);
87 }
88}
89
90impl FeatureWithGeometry for BuildingConstructiveElement {
91 fn envelope(&self) -> Option<Envelope> {
92 self.occupied_space.envelope()
93 }
94
95 fn apply_transform(&mut self, m: &Isometry3<f64>) {
96 self.occupied_space.apply_transform(m);
97 }
98}