ecitygml_core/model/
building.rs1use crate::model::construction::{GroundSurface, RoofSurface, WallSurface};
2use crate::model::core::CityObject;
3use crate::operations::{CityObjectVisitor, FeatureWithGeometry, Visitable};
4use egml::model::base;
5use egml::model::base::Gml;
6use egml::model::geometry::Envelope;
7use nalgebra::Isometry3;
8
9#[derive(Debug, Clone, PartialEq)]
10pub struct Building {
11 pub city_object: CityObject, pub wall_surface: Vec<WallSurface>,
13 pub roof_surface: Vec<RoofSurface>,
14 pub ground_surface: Vec<GroundSurface>,
15}
16
17impl Building {
18 pub fn new(id: base::Id) -> Self {
19 let gml = Gml::new(id);
20 let city_object = CityObject::new(gml);
21
22 Self {
23 city_object,
24 wall_surface: Vec::new(),
25 roof_surface: Vec::new(),
26 ground_surface: Vec::new(),
27 }
28 }
29}
30
31impl Visitable for Building {
32 fn accept<V: CityObjectVisitor>(&self, visitor: &mut V) {
33 visitor.visit_building(self);
34 self.wall_surface.iter().for_each(|x| x.accept(visitor));
35 self.roof_surface.iter().for_each(|x| x.accept(visitor));
36 self.ground_surface.iter().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
48 Envelope::from_optional_envelopes(&envelopes).expect("should work")
49 }
50
51 fn apply_transform(&mut self, m: &Isometry3<f64>) {
52 self.wall_surface
54 .iter_mut()
55 .for_each(|x| x.apply_transform(m));
56 self.roof_surface
57 .iter_mut()
58 .for_each(|x| x.apply_transform(m));
59 self.ground_surface
60 .iter_mut()
61 .for_each(|x| x.apply_transform(m));
62 }
63}