ecitygml_core/model/
transportation.rs1use crate::model::core::{Space, ThematicSurface};
2use crate::operations::{CityObjectVisitor, FeatureWithGeometry, Visitable};
3use egml::model::geometry::Envelope;
4use nalgebra::Isometry3;
5
6#[derive(Debug, Clone, PartialEq)]
7pub struct Road {
8 pub space: Space,
9 pub section: Vec<Section>,
10 pub intersection: Vec<Intersection>,
11}
12
13impl Road {
14 pub fn new(space: Space) -> Self {
15 Self {
16 space,
17 section: Default::default(),
18 intersection: Default::default(),
19 }
20 }
21}
22
23impl Visitable for Road {
24 fn accept<V: CityObjectVisitor>(&self, visitor: &mut V) {
25 visitor.visit_road(self);
26 self.section.iter().for_each(|x| x.accept(visitor));
27 self.intersection.iter().for_each(|x| x.accept(visitor));
28 }
29}
30
31impl FeatureWithGeometry for Road {
32 fn envelope(&self) -> Option<Envelope> {
33 let mut envelopes: Vec<Option<Envelope>> = vec![];
34 envelopes.extend(self.section.iter().map(|x| x.envelope()));
35 envelopes.extend(self.intersection.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.section.iter_mut().for_each(|x| x.apply_transform(m));
42 self.intersection
43 .iter_mut()
44 .for_each(|x| x.apply_transform(m));
45 }
46}
47
48#[derive(Debug, Clone, PartialEq)]
49pub struct Section {
50 pub space: Space,
51 pub traffic_space: Vec<TrafficSpace>,
52 pub auxiliary_traffic_space: Vec<AuxiliaryTrafficSpace>,
53}
54
55impl Section {
56 pub fn new(space: Space) -> Self {
57 Self {
58 space,
59 traffic_space: Vec::new(),
60 auxiliary_traffic_space: Vec::new(),
61 }
62 }
63}
64
65impl Visitable for Section {
66 fn accept<V: CityObjectVisitor>(&self, visitor: &mut V) {
67 visitor.visit_section(self);
68 self.traffic_space.iter().for_each(|x| x.accept(visitor));
69 self.auxiliary_traffic_space
70 .iter()
71 .for_each(|x| x.accept(visitor));
72 }
73}
74
75impl FeatureWithGeometry for Section {
76 fn envelope(&self) -> Option<Envelope> {
77 let mut envelopes: Vec<Option<Envelope>> = vec![];
78 envelopes.extend(self.traffic_space.iter().map(|x| x.envelope()));
79 envelopes.extend(self.auxiliary_traffic_space.iter().map(|x| x.envelope()));
80
81 Envelope::from_optional_envelopes(&envelopes).expect("should work")
82 }
83
84 fn apply_transform(&mut self, m: &Isometry3<f64>) {
85 self.traffic_space
86 .iter_mut()
87 .for_each(|x| x.apply_transform(m));
88 self.auxiliary_traffic_space
89 .iter_mut()
90 .for_each(|x| x.apply_transform(m));
91 }
92}
93
94#[derive(Debug, Clone, PartialEq)]
95pub struct Intersection {
96 pub space: Space,
97 pub traffic_space: Vec<TrafficSpace>,
98 pub auxiliary_traffic_space: Vec<AuxiliaryTrafficSpace>,
99}
100
101impl Intersection {
102 pub fn new(space: Space) -> Self {
103 Self {
104 space,
105 traffic_space: Vec::new(),
106 auxiliary_traffic_space: Vec::new(),
107 }
108 }
109}
110
111impl Visitable for Intersection {
112 fn accept<V: CityObjectVisitor>(&self, visitor: &mut V) {
113 visitor.visit_intersection(self);
114 self.traffic_space.iter().for_each(|x| x.accept(visitor));
115 self.auxiliary_traffic_space
116 .iter()
117 .for_each(|x| x.accept(visitor));
118 }
119}
120
121impl FeatureWithGeometry for Intersection {
122 fn envelope(&self) -> Option<Envelope> {
123 let mut envelopes: Vec<Option<Envelope>> = vec![];
124 envelopes.extend(self.traffic_space.iter().map(|x| x.envelope()));
125 envelopes.extend(self.auxiliary_traffic_space.iter().map(|x| x.envelope()));
126
127 Envelope::from_optional_envelopes(&envelopes).expect("should work")
128 }
129
130 fn apply_transform(&mut self, m: &Isometry3<f64>) {
131 self.traffic_space
132 .iter_mut()
133 .for_each(|x| x.apply_transform(m));
134 self.auxiliary_traffic_space
135 .iter_mut()
136 .for_each(|x| x.apply_transform(m));
137 }
138}
139
140#[derive(Debug, Clone, PartialEq)]
141pub struct TrafficSpace {
142 pub space: Space,
143 pub traffic_area: Vec<TrafficArea>, }
145
146impl TrafficSpace {
147 pub fn new(space: Space) -> Self {
148 Self {
149 space,
150 traffic_area: Vec::new(),
151 }
152 }
153}
154
155impl Visitable for TrafficSpace {
156 fn accept<V: CityObjectVisitor>(&self, visitor: &mut V) {
157 visitor.visit_traffic_space(self);
158 self.traffic_area.iter().for_each(|x| x.accept(visitor));
159 }
160}
161
162impl FeatureWithGeometry for TrafficSpace {
163 fn envelope(&self) -> Option<Envelope> {
164 let mut envelopes: Vec<Option<Envelope>> = vec![self.space.envelope()];
165 envelopes.extend(self.traffic_area.iter().map(|x| x.envelope()));
166
167 Envelope::from_optional_envelopes(&envelopes).expect("should work")
168 }
169
170 fn apply_transform(&mut self, m: &Isometry3<f64>) {
171 self.space.apply_transform(m);
172 self.traffic_area
173 .iter_mut()
174 .for_each(|x| x.apply_transform(m));
175 }
176}
177
178#[derive(Debug, Clone, PartialEq)]
179pub struct AuxiliaryTrafficSpace {
180 pub space: Space,
181 pub auxiliary_traffic_area: Vec<AuxiliaryTrafficArea>, }
183
184impl AuxiliaryTrafficSpace {
185 pub fn new(space: Space) -> Self {
186 Self {
187 space,
188 auxiliary_traffic_area: Vec::new(),
189 }
190 }
191}
192
193impl Visitable for AuxiliaryTrafficSpace {
194 fn accept<V: CityObjectVisitor>(&self, visitor: &mut V) {
195 visitor.visit_auxiliary_traffic_space(self);
196 self.auxiliary_traffic_area
197 .iter()
198 .for_each(|x| x.accept(visitor));
199 }
200}
201
202impl FeatureWithGeometry for AuxiliaryTrafficSpace {
203 fn envelope(&self) -> Option<Envelope> {
204 let mut envelopes: Vec<Option<Envelope>> = vec![self.space.envelope()];
205 envelopes.extend(self.auxiliary_traffic_area.iter().map(|x| x.envelope()));
206
207 Envelope::from_optional_envelopes(&envelopes).expect("should work")
208 }
209
210 fn apply_transform(&mut self, m: &Isometry3<f64>) {
211 self.space.apply_transform(m);
212 self.auxiliary_traffic_area
213 .iter_mut()
214 .for_each(|x| x.apply_transform(m));
215 }
216}
217
218#[derive(Debug, Clone, PartialEq)]
219pub struct TrafficArea {
220 pub thematic_surface: ThematicSurface,
221}
222
223impl TrafficArea {
224 pub fn new(thematic_surface: ThematicSurface) -> Self {
225 Self { thematic_surface }
226 }
227}
228
229impl Visitable for TrafficArea {
230 fn accept<V: CityObjectVisitor>(&self, visitor: &mut V) {
231 visitor.visit_traffic_area(self);
232 }
233}
234
235impl FeatureWithGeometry for TrafficArea {
236 fn envelope(&self) -> Option<Envelope> {
237 self.thematic_surface.envelope()
238 }
239
240 fn apply_transform(&mut self, m: &Isometry3<f64>) {
241 self.thematic_surface.apply_transform(m);
242 }
243}
244
245#[derive(Debug, Clone, PartialEq)]
246pub struct AuxiliaryTrafficArea {
247 pub thematic_surface: ThematicSurface,
248}
249
250impl AuxiliaryTrafficArea {
251 pub fn new(thematic_surface: ThematicSurface) -> Self {
252 Self { thematic_surface }
253 }
254}
255
256impl Visitable for AuxiliaryTrafficArea {
257 fn accept<V: CityObjectVisitor>(&self, visitor: &mut V) {
258 visitor.visit_auxiliary_traffic_area(self);
259 }
260}
261
262impl FeatureWithGeometry for AuxiliaryTrafficArea {
263 fn envelope(&self) -> Option<Envelope> {
264 self.thematic_surface.envelope()
265 }
266
267 fn apply_transform(&mut self, m: &Isometry3<f64>) {
268 self.thematic_surface.apply_transform(m);
269 }
270}