ecitygml_core/model/
construction.rs

1use crate::model::core::{OccupiedSpace, ThematicSurface};
2use crate::operations::{CityObjectVisitor, FeatureWithGeometry, Visitable};
3use egml::model::geometry::Envelope;
4use nalgebra::Isometry3;
5
6#[derive(Debug, Clone, PartialEq)]
7pub struct WallSurface {
8    pub thematic_surface: ThematicSurface,
9    pub door_surface: Vec<DoorSurface>,
10    pub window_surface: Vec<WindowSurface>,
11}
12
13impl WallSurface {
14    pub fn new(thematic_surface: ThematicSurface) -> Self {
15        Self {
16            thematic_surface,
17            door_surface: Vec::new(),
18            window_surface: Vec::new(),
19        }
20    }
21}
22
23impl Visitable for WallSurface {
24    fn accept<V: CityObjectVisitor>(&self, visitor: &mut V) {
25        visitor.visit_wall_surface(self);
26        self.door_surface.iter().for_each(|x| x.accept(visitor));
27        self.window_surface.iter().for_each(|x| x.accept(visitor));
28    }
29}
30
31impl FeatureWithGeometry for WallSurface {
32    fn envelope(&self) -> Option<Envelope> {
33        let mut envelopes: Vec<Option<Envelope>> = vec![self.thematic_surface.envelope()];
34        envelopes.extend(self.door_surface.iter().map(|x| x.envelope()));
35        envelopes.extend(self.window_surface.iter().map(|x| x.envelope()));
36
37        Envelope::from_optional_envelopes(&envelopes).expect("should work")
38    }
39
40    fn apply_transform(&mut self, m: &Isometry3<f64>) {
41        self.thematic_surface.apply_transform(m);
42        self.door_surface
43            .iter_mut()
44            .for_each(|x| x.apply_transform(m));
45        self.window_surface
46            .iter_mut()
47            .for_each(|x| x.apply_transform(m));
48    }
49}
50
51#[derive(Debug, Clone, PartialEq)]
52pub struct RoofSurface {
53    pub thematic_surface: ThematicSurface,
54}
55
56impl RoofSurface {
57    pub fn new(thematic_surface: ThematicSurface) -> Self {
58        Self { thematic_surface }
59    }
60}
61
62impl Visitable for RoofSurface {
63    fn accept<V: CityObjectVisitor>(&self, visitor: &mut V) {
64        visitor.visit_roof_surface(self);
65    }
66}
67
68impl FeatureWithGeometry for RoofSurface {
69    fn envelope(&self) -> Option<Envelope> {
70        self.thematic_surface.envelope()
71    }
72
73    fn apply_transform(&mut self, m: &Isometry3<f64>) {
74        self.thematic_surface.apply_transform(m);
75    }
76}
77
78#[derive(Debug, Clone, PartialEq)]
79pub struct GroundSurface {
80    pub thematic_surface: ThematicSurface,
81}
82
83impl GroundSurface {
84    pub fn new(thematic_surface: ThematicSurface) -> Self {
85        Self { thematic_surface }
86    }
87}
88
89impl Visitable for GroundSurface {
90    fn accept<V: CityObjectVisitor>(&self, visitor: &mut V) {
91        visitor.visit_ground_surface(self);
92    }
93}
94
95impl FeatureWithGeometry for GroundSurface {
96    fn envelope(&self) -> Option<Envelope> {
97        self.thematic_surface.envelope()
98    }
99
100    fn apply_transform(&mut self, m: &Isometry3<f64>) {
101        self.thematic_surface.apply_transform(m);
102    }
103}
104
105#[derive(Debug, Clone, PartialEq)]
106pub struct WindowSurface {
107    pub occupied_space: OccupiedSpace,
108}
109
110impl WindowSurface {
111    pub fn new(occupied_space: OccupiedSpace) -> Self {
112        Self { occupied_space }
113    }
114}
115
116impl Visitable for WindowSurface {
117    fn accept<V: CityObjectVisitor>(&self, visitor: &mut V) {
118        visitor.visit_window_surface(self);
119    }
120}
121
122impl FeatureWithGeometry for WindowSurface {
123    fn envelope(&self) -> Option<Envelope> {
124        self.occupied_space.envelope()
125    }
126
127    fn apply_transform(&mut self, m: &Isometry3<f64>) {
128        self.occupied_space.apply_transform(m);
129    }
130}
131
132#[derive(Debug, Clone, PartialEq)]
133pub struct DoorSurface {
134    pub occupied_space: OccupiedSpace,
135}
136
137impl DoorSurface {
138    pub fn new(occupied_space: OccupiedSpace) -> Self {
139        Self { occupied_space }
140    }
141}
142
143impl Visitable for DoorSurface {
144    fn accept<V: CityObjectVisitor>(&self, visitor: &mut V) {
145        visitor.visit_door_surface(self);
146    }
147}
148
149impl FeatureWithGeometry for DoorSurface {
150    fn envelope(&self) -> Option<Envelope> {
151        self.occupied_space.envelope()
152    }
153
154    fn apply_transform(&mut self, m: &Isometry3<f64>) {
155        self.occupied_space.apply_transform(m);
156    }
157}