Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/tests/tools/sumolib/sumolib3d/runner.py
428384 views
1
#!/usr/bin/env python
2
# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
# Copyright (C) 2016-2026 German Aerospace Center (DLR) and others.
4
# This program and the accompanying materials are made available under the
5
# terms of the Eclipse Public License 2.0 which is available at
6
# https://www.eclipse.org/legal/epl-2.0/
7
# This Source Code may also be made available under the following Secondary
8
# Licenses when the conditions for such availability set forth in the Eclipse
9
# Public License 2.0 are satisfied: GNU General Public License, version 2
10
# or later which is available at
11
# https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12
# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13
14
# @file runner.py
15
# @author Marek Heinrich
16
# @date 2016
17
18
from __future__ import absolute_import
19
from __future__ import print_function
20
21
import sys
22
import os
23
import subprocess
24
25
import unittest
26
27
# Do not use SUMO_HOME here to ensure you are always testing the
28
# functions from the same tree the test is in
29
sys.path.append(
30
os.path.join(os.path.dirname(__file__), '..', '..', '..', '..', 'tools'))
31
32
import sumolib # noqa
33
34
NODEFILE_2D = 'input_nodes_2d.nod.xml'
35
NODEFILE_3D = 'input_nodes.nod.xml'
36
EDGEFILE = 'input_edges.edg.xml'
37
NETFILE_2D = 'input_net_2d.net.xml'
38
NETFILE_3D = 'input_net_3d.net.xml'
39
40
41
class Test_Shapes(unittest.TestCase):
42
43
""" Tests to check inport of sumo elements with/without z coords. """
44
45
@classmethod
46
def setUpClass(cls):
47
""" setup generates all sumo files - once. """
48
49
netcon_bin = sumolib.checkBinary('netconvert')
50
# print ('xxxxxxxxxxxxxxxxxxx', netcon_bin)
51
52
for node_file, net_file in [
53
# (NODEFILE_2D, NETFILE_2D),
54
(NODEFILE_3D, NETFILE_3D)
55
]:
56
57
command = [netcon_bin,
58
"-n", node_file,
59
"-e", EDGEFILE,
60
"-o", net_file,
61
"--default.junctions.radius", "1.5",
62
"--junctions.corner-detail", "0",
63
"--offset.disable-normalization"]
64
65
subprocess.call(command, stdout=sys.stdout, stderr=sys.stderr)
66
67
# cls.sumo_net_2d = sumolib.net.readNet(
68
# NETFILE_2D,
69
# withInternal=True)
70
71
cls.sumo_net = sumolib.net.readNet(
72
NETFILE_3D,
73
withInternal=True)
74
75
@classmethod
76
def tearDownClass(cls):
77
""" remove the generated net file, once all tests ran """
78
79
if os.path.exists(NETFILE_2D):
80
os.remove(NETFILE_2D)
81
if os.path.exists(NETFILE_3D):
82
os.remove(NETFILE_3D)
83
84
# check node's coords
85
@unittest.skipIf(False, '')
86
def test_check_node_coords_2d_for_3d_input_node_no_z(self):
87
""" test to retrive the coords from a node with no z value
88
89
- should be a 2d coords tuple"""
90
91
self.assertEqual(
92
self.sumo_net.getNode('a0').getCoord(),
93
(100.0, 0.0))
94
95
@unittest.skipIf(False, '')
96
def test_check_node_coords_3d_for_3d_input_node_z_no_z(self):
97
""" test to retrive the coords from a node with no z value
98
99
- should be a 3d coords tuple"""
100
101
self.assertEqual(
102
self.sumo_net.getNode('a0').getCoord3D(),
103
(100.0, 0.0, 0.0))
104
105
@unittest.skipIf(False, '')
106
def test_check_node_coords_2d_for_3d_input_node_z_not_zero(self):
107
""" test to retrive the coords from a node with z!=0
108
109
- should be a 3d coords tuple"""
110
111
self.assertEqual(
112
self.sumo_net.getNode('a1').getCoord(),
113
(200.0, 0.0))
114
115
@unittest.skipIf(False, '')
116
def test_check_node_coords_3d_for_3d_input_node_z_not_zero(self):
117
""" test to retrive the coords from a node with z!=0
118
119
- should be a 3d coords tuple"""
120
121
self.assertEqual(
122
self.sumo_net.getNode('a1').getCoord3D(),
123
(200.0, 0.0, 10.0))
124
125
# check node's shape
126
127
@unittest.skipIf(False, '')
128
def test_check_node_shape_2d_on_a_node_with_no_z(self):
129
""" test to retrive the shape from a node with no z value
130
131
- should be a 2d coords tuple"""
132
133
result = self.sumo_net.getNode('a0').getShape()
134
self.assertTrue(len(result) > 0)
135
for shape_point in result:
136
self.assertTrue(len(shape_point) == 2)
137
138
@unittest.skipIf(False, '')
139
def test_check_node_shape_3d_on_a_node_with_no_z(self):
140
""" test to retrive the shape from a node with no z value
141
142
- should be a 3d coords tuple"""
143
result = self.sumo_net.getNode('a0').getShape3D()
144
self.assertTrue(len(result) > 0)
145
for shape_point in result:
146
self.assertTrue(len(shape_point) == 3)
147
148
@unittest.skipIf(False, '')
149
def test_check_node_shape_2d_on_a_node_with_z(self):
150
""" test to retrive the shape from a node with z value
151
152
- should be a 2d coords tuple"""
153
154
result = self.sumo_net.getNode('a1').getShape3D()
155
self.assertTrue(len(result) > 0)
156
for shape_point in result:
157
self.assertTrue(len(shape_point) == 3)
158
159
@unittest.skipIf(False, '')
160
def test_check_node_shape_3d_on_a_node_with_z(self):
161
""" test to retrive the shape from a node with z value
162
163
- should be a 3d coords tuple"""
164
165
result = self.sumo_net.getNode('a1').getShape3D()
166
self.assertTrue(len(result) > 0)
167
for shape_point in result:
168
self.assertTrue(len(shape_point) == 3)
169
170
# check edge's shape
171
@unittest.skipIf(False, '')
172
def test_h001_edge_shape_not_stored(self):
173
"""
174
175
The edge is the center line of an H (both directions,
176
one lane per edge).
177
178
Junction shapes are engaged so the lane of the edge
179
is somewhat shorter at the start and at the end.
180
181
Shape of the edge _is_not_ stored in sumo's net xml
182
183
"""
184
185
edge_id = 'center_we'
186
the_edge = self.sumo_net.getEdge(edge_id)
187
# the_lane = the_edge.getLane(0) # 'center_we_0'
188
189
# check edge shape
190
expected_result_raw_edge_shape_2D = \
191
[(1000, 100), (1200, 100)]
192
193
expected_result_raw_edge_shape_3D = \
194
[(1000, 100, 10), (1200, 100, 10)]
195
196
result_raw_edge_shape_2D = the_edge.getRawShape()
197
result_raw_edge_shape_3D = the_edge.getRawShape3D()
198
199
self.assertEqual(result_raw_edge_shape_2D,
200
expected_result_raw_edge_shape_2D)
201
202
self.assertEqual(result_raw_edge_shape_3D,
203
expected_result_raw_edge_shape_3D)
204
205
@unittest.skipIf(False, '')
206
def test_h001_edge_shape_stored(self):
207
"""
208
209
The edge is the center line of an H (both directions,
210
one lane per edge) with one extra shape point.
211
212
Junction shapes are engaged so the lane of the edge
213
is somewhat shorter at the start and at the end.
214
215
Shape of the edge _is_ stored in sumo's net xml
216
217
"""
218
219
edge_id = 'center_ew'
220
the_edge = self.sumo_net.getEdge(edge_id)
221
# the_lane = the_edge.getLane(0) # 'center_we_0'
222
223
# check edge shape
224
expected_result_raw_edge_shape_2D = \
225
[(1200, 100), (1100, 125), (1000, 100)]
226
227
expected_result_raw_edge_shape_3D = \
228
[(1200, 100, 10), (1100, 125, 10), (1000, 100, 10)]
229
230
result_raw_edge_shape_2D = the_edge.getRawShape()
231
result_raw_edge_shape_3D = the_edge.getRawShape3D()
232
233
self.assertEqual(result_raw_edge_shape_2D,
234
expected_result_raw_edge_shape_2D)
235
236
self.assertEqual(result_raw_edge_shape_3D,
237
expected_result_raw_edge_shape_3D)
238
239
# check lane's shape
240
@unittest.skipIf(False, '')
241
def test_h001_lane_shape_2d(self):
242
"""
243
244
The edge is the center line of an H (both directions,
245
one lane per edge).
246
247
Junction shapes are engaged so the lane of the edge
248
is somewhat shorter at the start and at the end.
249
250
2d version
251
"""
252
253
edge_id = 'center_we'
254
the_edge = self.sumo_net.getEdge(edge_id)
255
the_lane = the_edge.getLane(0) # 'center_we_0'
256
257
# check lane shape - without junction included
258
259
result_lane_shape_without_junc = \
260
the_lane.getShape(includeJunctions=False)
261
262
self.assertTrue(len(result_lane_shape_without_junc) == 2)
263
264
result_start_point_wo = result_lane_shape_without_junc[0]
265
result_end_point_wo = result_lane_shape_without_junc[1]
266
267
# check first shape point coords
268
self.assertTrue(1000 < result_start_point_wo[0] < 1200) # x
269
self.assertTrue(90 < result_start_point_wo[1] < 100) # y
270
271
# check second shape point coords
272
self.assertTrue(1000 < result_end_point_wo[0] < 1200) # x
273
self.assertTrue(90 < result_end_point_wo[1] < 100) # y
274
275
# check lane shape - with junction included
276
277
result_lane_shape_with_junc = \
278
the_lane.getShape(includeJunctions=True)
279
280
self.assertTrue(len(result_lane_shape_with_junc) == 4)
281
282
result_from_point_wi = result_lane_shape_with_junc[0]
283
result_start_point_wi = result_lane_shape_with_junc[1]
284
result_end_point_wi = result_lane_shape_with_junc[2]
285
result_to_point_wi = result_lane_shape_with_junc[3]
286
287
# check fromNode coords
288
self.assertEqual(result_from_point_wi, (1000, 100))
289
290
# check first shape point coords
291
self.assertTrue(1000 < result_start_point_wi[0] < 1200) # x
292
self.assertTrue(90 < result_start_point_wi[1] < 100) # y
293
294
# check second shape point coords
295
self.assertTrue(1000 < result_end_point_wi[0] < 1200) # x
296
self.assertTrue(90 < result_end_point_wi[1] < 100) # y
297
298
# check toNode coords
299
self.assertEqual(result_to_point_wi, (1200, 100))
300
301
@unittest.skipIf(False, '')
302
def test_h001_lane_shape_3d(self):
303
"""
304
305
The edge is the center line of an H (both directions,
306
one lane per edge).
307
308
Junction shapes are engaged so the lane of the edge
309
is somewhat shorter at the start and at the end.
310
311
3d version
312
"""
313
314
edge_id = 'center_we'
315
the_edge = self.sumo_net.getEdge(edge_id)
316
the_lane = the_edge.getLane(0) # 'center_we_0'
317
318
# check lane shape - without junction included
319
320
result_lane_shape_without_junc = \
321
the_lane.getShape3D(includeJunctions=False)
322
323
self.assertTrue(len(result_lane_shape_without_junc) == 2)
324
325
result_start_point_wo = result_lane_shape_without_junc[0]
326
result_end_point_wo = result_lane_shape_without_junc[1]
327
328
# check first shape point coords
329
self.assertTrue(1000 < result_start_point_wo[0] < 1200) # x
330
self.assertTrue(90 < result_start_point_wo[1] < 100) # y
331
self.assertTrue(result_start_point_wo[2] == 10) # z
332
333
# check second shape point coords
334
self.assertTrue(1000 < result_end_point_wo[0] < 1200) # x
335
self.assertTrue(90 < result_end_point_wo[1] < 100) # y
336
self.assertTrue(result_end_point_wo[2] == 10) # z
337
338
# check lane shape - with junction included
339
340
result_lane_shape_with_junc = \
341
the_lane.getShape3D(includeJunctions=True)
342
343
self.assertTrue(len(result_lane_shape_with_junc) == 4)
344
345
result_from_point_wi = result_lane_shape_with_junc[0]
346
result_start_point_wi = result_lane_shape_with_junc[1]
347
result_end_point_wi = result_lane_shape_with_junc[2]
348
result_to_point_wi = result_lane_shape_with_junc[3]
349
350
# check fromNode coords
351
self.assertEqual(result_from_point_wi, (1000, 100, 10))
352
353
# check first shape point coords
354
self.assertTrue(1000 < result_start_point_wi[0] < 1200) # x
355
self.assertTrue(90 < result_start_point_wi[1] < 100) # y
356
self.assertTrue(result_start_point_wi[2] == 10) # z
357
358
# check second shape point coords
359
self.assertTrue(1000 < result_end_point_wi[0] < 1200) # x
360
self.assertTrue(90 < result_end_point_wi[1] < 100) # y
361
self.assertTrue(result_end_point_wi[2] == 10) # z
362
363
# check toNode coords
364
self.assertEqual(result_to_point_wi, (1200, 100, 10))
365
366
@unittest.skipIf(False, '')
367
def test_h003_lane_shape_2d(self):
368
"""
369
370
The edge is the we-center line of an H (both directions,
371
one lane per edge).
372
373
This edge is not a straight line but has shape points defined.
374
375
Junction shapes are engaged so the lanes of the edge
376
are somewhat shorter at the start and at the end.
377
378
Still the edge goes from from to to node, so the shape
379
should start and end with these coords.
380
381
2d version.
382
"""
383
384
edge_id = 'center_ew'
385
the_edge = self.sumo_net.getEdge(edge_id)
386
the_lane = the_edge.getLane(1) # 'center_ew_1'
387
388
# check lane shape - without junction included
389
390
result_lane_shape_without_junc = \
391
the_lane.getShape(includeJunctions=False)
392
393
self.assertTrue(len(result_lane_shape_without_junc) == 3)
394
395
result_start_point_wo = result_lane_shape_without_junc[0]
396
result_extra_point_wo = result_lane_shape_without_junc[1]
397
result_end_point_wo = result_lane_shape_without_junc[2]
398
399
# check first shape point coords
400
self.assertTrue(1000 < result_start_point_wo[0] < 1200) # x
401
self.assertTrue(100 < result_start_point_wo[1] < 110) # y
402
403
# check second shape point coords - extra point
404
self.assertTrue(result_extra_point_wo[0] == 1100) # x
405
self.assertTrue(125 < result_extra_point_wo[1] < 150) # y
406
407
# check third shape point coords
408
self.assertTrue(1000 < result_end_point_wo[0] < 1200) # x
409
self.assertTrue(100 < result_end_point_wo[1] < 110) # y
410
411
# check lane shape - with junction included
412
413
result_lane_shape_with_junc = \
414
the_lane.getShape(includeJunctions=True)
415
416
self.assertTrue(len(result_lane_shape_with_junc) == 5)
417
418
result_from_point_wi = result_lane_shape_with_junc[0]
419
result_start_point_wi = result_lane_shape_with_junc[1]
420
result_extra_point_wi = result_lane_shape_with_junc[2]
421
result_end_point_wi = result_lane_shape_with_junc[3]
422
result_to_point_wi = result_lane_shape_with_junc[4]
423
424
# check fromNode coords
425
self.assertEqual(result_from_point_wi,
426
(1200, 100))
427
428
# check first shape point coords
429
self.assertTrue(1000 < result_start_point_wi[0] < 1200) # x
430
self.assertTrue(100 < result_start_point_wi[1] < 110) # y
431
432
# check second shape point coords - extra point
433
self.assertTrue(result_extra_point_wi[0] == 1100) # x
434
self.assertTrue(125 < result_extra_point_wi[1] < 150) # y
435
436
# check third shape point coords
437
self.assertTrue(1000 < result_end_point_wi[0] < 1200) # x
438
self.assertTrue(100 < result_end_point_wi[1] < 110) # y
439
440
# check toNode coords
441
self.assertEqual(result_to_point_wi,
442
(1000, 100))
443
444
@unittest.skipIf(False, '')
445
def test_h003_lane_shape_3d(self):
446
"""
447
448
The edge is the we-center line of an H (both directions,
449
one lane per edge).
450
451
This edge is not a straight line but has shape points defined.
452
453
Junction shapes are engaged so the lanes of the edge
454
are somewhat shorter at the start and at the end.
455
456
Still the edge goes from from to to node, so the shape
457
should start and end with these coords.
458
459
3d version.
460
"""
461
462
edge_id = 'center_ew'
463
the_edge = self.sumo_net.getEdge(edge_id)
464
the_lane = the_edge.getLane(1) # 'center_ew_1'
465
466
# check lane shape - without junction included
467
468
result_lane_shape_without_junc = \
469
the_lane.getShape3D(includeJunctions=False)
470
471
self.assertTrue(len(result_lane_shape_without_junc) == 3)
472
473
result_start_point_wo = result_lane_shape_without_junc[0]
474
result_extra_point_wo = result_lane_shape_without_junc[1]
475
result_end_point_wo = result_lane_shape_without_junc[2]
476
477
# check first shape point coords
478
self.assertTrue(1000 < result_start_point_wo[0] < 1200) # x
479
self.assertTrue(100 < result_start_point_wo[1] < 110) # y
480
self.assertTrue(result_start_point_wo[2] == 10) # z
481
482
# check second shape point coords - extra point
483
self.assertTrue(result_extra_point_wo[0] == 1100) # x
484
self.assertTrue(125 < result_extra_point_wo[1] < 150) # y
485
self.assertTrue(result_extra_point_wo[2] == 10) # z
486
487
# check third shape point coords
488
self.assertTrue(1000 < result_end_point_wo[0] < 1200) # x
489
self.assertTrue(100 < result_end_point_wo[1] < 110) # y
490
self.assertTrue(result_end_point_wo[2] == 10) # z
491
492
# check lane shape - with junction included
493
494
result_lane_shape_with_junc = \
495
the_lane.getShape3D(includeJunctions=True)
496
497
self.assertTrue(len(result_lane_shape_with_junc) == 5)
498
499
result_from_point_wi = result_lane_shape_with_junc[0]
500
result_start_point_wi = result_lane_shape_with_junc[1]
501
result_extra_point_wi = result_lane_shape_with_junc[2]
502
result_end_point_wi = result_lane_shape_with_junc[3]
503
result_to_point_wi = result_lane_shape_with_junc[4]
504
505
# check fromNode coords
506
self.assertEqual(result_from_point_wi,
507
(1200, 100, 10))
508
509
# check first shape point coords
510
self.assertTrue(1000 < result_start_point_wi[0] < 1200) # x
511
self.assertTrue(100 < result_start_point_wi[1] < 110) # y
512
self.assertTrue(result_start_point_wi[2] == 10) # z
513
514
# check second shape point coords - extra point
515
self.assertTrue(result_extra_point_wi[0] == 1100) # x
516
self.assertTrue(125 < result_extra_point_wi[1] < 150) # y
517
self.assertTrue(result_extra_point_wi[2] == 10) # z
518
519
# check third shape point coords
520
self.assertTrue(1000 < result_end_point_wi[0] < 1200) # x
521
self.assertTrue(100 < result_end_point_wi[1] < 110) # y
522
self.assertTrue(result_end_point_wi[2] == 10) # z
523
524
# check toNode coords
525
self.assertEqual(result_to_point_wi,
526
(1000, 100, 10))
527
528
@unittest.skipIf(False, '')
529
def test_h004_lane_shape_2d(self):
530
"""Get an internal lane and its shape.
531
532
Shape should not be influenced by the included Junction parameter
533
534
Use left cross of the H for this test.
535
536
2d version.
537
"""
538
539
edge_id = ':left_center_3'
540
the_edge = self.sumo_net.getEdge(edge_id)
541
the_lane = the_edge.getLane(0) # ':left_center_3_0'
542
543
result_lane_shape_with_junc = \
544
the_lane.getShape(includeJunctions=True)
545
546
result_lane_shape_without_junc = \
547
the_lane.getShape(includeJunctions=False)
548
549
# there should be no difference between the two results
550
self.assertEqual(result_lane_shape_with_junc,
551
result_lane_shape_without_junc)
552
553
# there must be at least two shape points
554
self.assertTrue(len(result_lane_shape_without_junc) >= 2)
555
556
# each shape point should be somewhat close to the junction
557
# and on the same z-level
558
559
for shape_point in result_lane_shape_without_junc:
560
self.assertTrue(995 < shape_point[0] < 1005)
561
self.assertTrue(90 < shape_point[1] < 110)
562
563
@unittest.skipIf(False, '')
564
def test_h004_lane_shape_3d(self):
565
"""Get an internal lane and its shape.
566
567
Shape should not be influenced by the included Junction parameter
568
569
Use left cross of the H for this test.
570
571
3d version.
572
"""
573
574
edge_id = ':left_center_3'
575
the_edge = self.sumo_net.getEdge(edge_id)
576
the_lane = the_edge.getLane(0) # ':left_center_3_0'
577
578
result_lane_shape_with_junc = \
579
the_lane.getShape3D(includeJunctions=True)
580
581
result_lane_shape_without_junc = \
582
the_lane.getShape3D(includeJunctions=False)
583
584
# there should be no difference between the two results
585
self.assertEqual(result_lane_shape_with_junc,
586
result_lane_shape_without_junc)
587
588
# there must be at least two shape points
589
self.assertTrue(len(result_lane_shape_without_junc) >= 2)
590
591
# each shape point should be somewhat close to the junction
592
# and on the same z-level
593
594
for shape_point in result_lane_shape_without_junc:
595
self.assertTrue(995 < shape_point[0] < 1005)
596
self.assertTrue(90 < shape_point[1] < 110)
597
self.assertTrue(shape_point[2] == 10)
598
599
@unittest.skipIf(False, '')
600
def test_edge_001_lane_shape_2d(self):
601
"""
602
603
Both way edge is the straight line between two nodes
604
edge has no extra shape points - no intersections engaged.
605
Edge is not centered.
606
607
2d version.
608
"""
609
610
edge_id = 'straight_with_counter'
611
the_edge = self.sumo_net.getEdge(edge_id)
612
the_lane = the_edge.getLane(0) # 'straight_with_counter_0'
613
614
# check lane shape - without junction included
615
616
result_lane_shape_without_junc = \
617
the_lane.getShape(includeJunctions=False)
618
619
self.assertTrue(len(result_lane_shape_without_junc) == 2)
620
621
result_start_point_wo = result_lane_shape_without_junc[0]
622
result_end_point_wo = result_lane_shape_without_junc[1]
623
624
# check first shape point coords
625
self.assertTrue(100 <= result_start_point_wo[0] <= 200) # x
626
self.assertTrue(-10 <= result_start_point_wo[1] < 0) # y
627
628
# check second shape point coords
629
self.assertTrue(100 <= result_end_point_wo[0] <= 200) # x
630
self.assertTrue(-10 <= result_end_point_wo[1] < 0) # y
631
632
# check lane shape - with junction included
633
634
result_lane_shape_with_junc = \
635
the_lane.getShape(includeJunctions=True)
636
637
self.assertTrue(len(result_lane_shape_with_junc) == 4)
638
639
result_from_point_wi = result_lane_shape_with_junc[0]
640
result_start_point_wi = result_lane_shape_with_junc[1]
641
result_end_point_wi = result_lane_shape_with_junc[2]
642
result_to_point_wi = result_lane_shape_with_junc[3]
643
644
# check fromNode coords
645
self.assertEqual(result_from_point_wi,
646
(100, 0))
647
648
# check first shape point coords
649
self.assertTrue(100 <= result_start_point_wi[0] <= 200) # x
650
self.assertTrue(-10 <= result_start_point_wi[1] < 0) # y
651
652
# check second shape point coords
653
self.assertTrue(100 <= result_end_point_wi[0] <= 200) # x
654
self.assertTrue(-10 <= result_end_point_wi[1] < 0) # y
655
656
# check toNode coords
657
self.assertEqual(result_to_point_wi,
658
(200, 0))
659
660
@unittest.skipIf(False, '')
661
def test_edge_001_lane_shape_3d(self):
662
"""
663
664
Both way edge is the straight line between two nodes
665
edge has no extra shape points - no intersections engaged.
666
Edge is not centered.
667
668
3d version.
669
"""
670
671
edge_id = 'straight_with_counter'
672
the_edge = self.sumo_net.getEdge(edge_id)
673
the_lane = the_edge.getLane(0) # 'straight_with_counter_0'
674
675
# check lane shape - without junction included
676
677
result_lane_shape_without_junc = \
678
the_lane.getShape3D(includeJunctions=False)
679
680
self.assertTrue(len(result_lane_shape_without_junc) == 2)
681
682
result_start_point_wo = result_lane_shape_without_junc[0]
683
result_end_point_wo = result_lane_shape_without_junc[1]
684
685
# check first shape point coords
686
self.assertTrue(100 <= result_start_point_wo[0] <= 200) # x
687
self.assertTrue(-10 <= result_start_point_wo[1] < 0) # y
688
self.assertTrue(result_start_point_wo[2] == 0) # z
689
690
# check second shape point coords
691
self.assertTrue(100 <= result_end_point_wo[0] <= 200) # x
692
self.assertTrue(-10 <= result_end_point_wo[1] < 0) # y
693
self.assertTrue(result_end_point_wo[2] == 10) # z
694
695
# check lane shape - with junction included
696
697
result_lane_shape_with_junc = \
698
the_lane.getShape3D(includeJunctions=True)
699
700
self.assertTrue(len(result_lane_shape_with_junc) == 4)
701
702
result_from_point_wi = result_lane_shape_with_junc[0]
703
result_start_point_wi = result_lane_shape_with_junc[1]
704
result_end_point_wi = result_lane_shape_with_junc[2]
705
result_to_point_wi = result_lane_shape_with_junc[3]
706
707
# check fromNode coords
708
self.assertEqual(result_from_point_wi,
709
(100, 0, 0))
710
711
# check first shape point coords
712
self.assertTrue(100 <= result_start_point_wi[0] <= 200) # x
713
self.assertTrue(-10 <= result_start_point_wi[1] < 0) # y
714
self.assertTrue(result_start_point_wi[2] == 0) # z
715
716
# check second shape point coords
717
self.assertTrue(100 <= result_end_point_wi[0] <= 200) # x
718
self.assertTrue(-10 <= result_end_point_wi[1] < 0) # y
719
self.assertTrue(result_end_point_wi[2] == 10) # z
720
721
# check toNode coords
722
self.assertEqual(result_to_point_wi,
723
(200, 0, 10))
724
725
@unittest.skipIf(False, '')
726
def test_sloopy_edge_003_lane_shape_2d(self):
727
"""
728
729
Both way edge which is a sloopy line between two Nodes
730
since the edge has extra shape points
731
- no intersections engaged.
732
733
There was only one shape point defined in the edge.xml
734
The coord of the from and to node where not included
735
(since this is optional
736
- the counder direction does included them - see below)
737
738
2d version.
739
"""
740
741
edge_id = 'sloopy_we'
742
the_edge = self.sumo_net.getEdge(edge_id)
743
the_lane = the_edge.getLane(0) # 'sloopy_we_0'
744
745
# check lane shape - without junction included
746
747
result_lane_shape_without_junc = \
748
the_lane.getShape(includeJunctions=False)
749
750
self.assertTrue(len(result_lane_shape_without_junc) == 3)
751
752
result_start_point_wo = result_lane_shape_without_junc[0]
753
result_extra_point_wo = result_lane_shape_without_junc[1]
754
result_end_point_wo = result_lane_shape_without_junc[2]
755
756
# check first shape point coords
757
self.assertTrue(3000 <= result_start_point_wo[0] <= 3500) # x
758
self.assertTrue(190 <= result_start_point_wo[1] < 200) # y
759
760
# check second shape point coords - extra point
761
self.assertTrue(result_extra_point_wo[0] == 3250) # x
762
self.assertTrue(230 <= result_extra_point_wo[1] < 250) # y
763
764
# check third shape point coords
765
self.assertTrue(3000 <= result_end_point_wo[0] <= 3500) # x
766
self.assertTrue(190 <= result_end_point_wo[1] < 200) # y
767
768
# check lane shape - with junction included
769
770
result_lane_shape_with_junc = \
771
the_lane.getShape(includeJunctions=True)
772
773
self.assertEqual(len(result_lane_shape_with_junc), 5)
774
775
result_from_point_wi = result_lane_shape_with_junc[0]
776
result_start_point_wi = result_lane_shape_with_junc[1]
777
result_extra_point_wi = result_lane_shape_with_junc[2]
778
result_end_point_wi = result_lane_shape_with_junc[3]
779
result_to_point_wi = result_lane_shape_with_junc[4]
780
781
# check fromNode coords
782
self.assertEqual(result_from_point_wi,
783
(3000, 200))
784
785
# check first shape point coords
786
self.assertTrue(3000 <= result_start_point_wi[0] <= 3500) # x
787
self.assertTrue(190 <= result_start_point_wi[1] < 200) # y
788
789
# check second shape point coords - extra point
790
self.assertTrue(result_extra_point_wi[0] == 3250) # x
791
self.assertTrue(230 <= result_extra_point_wi[1] < 250) # y
792
793
# check third shape point coords
794
self.assertTrue(3000 <= result_end_point_wi[0] <= 3500) # x
795
self.assertTrue(190 <= result_end_point_wi[1] < 200) # y
796
797
# check toNode coords
798
self.assertEqual(result_to_point_wi,
799
(3500, 200))
800
801
@unittest.skipIf(False, '')
802
def test_sloopy_edge_003_lane_shape_3d(self):
803
"""
804
805
Both way edge which is a sloopy line between two Nodes
806
since the edge has extra shape points
807
- no intersections engaged.
808
809
There was only one shape point defined in the edge.xml
810
The coord of the from and to node where not included
811
(since this is optional
812
- the counder direction does included them - see below)
813
814
3d version.
815
"""
816
817
edge_id = 'sloopy_we'
818
the_edge = self.sumo_net.getEdge(edge_id)
819
the_lane = the_edge.getLane(0) # 'sloopy_we_0'
820
821
# check lane shape - without junction included
822
823
result_lane_shape_without_junc = \
824
the_lane.getShape3D(includeJunctions=False)
825
826
self.assertTrue(len(result_lane_shape_without_junc) == 3)
827
828
result_start_point_wo = result_lane_shape_without_junc[0]
829
result_extra_point_wo = result_lane_shape_without_junc[1]
830
result_end_point_wo = result_lane_shape_without_junc[2]
831
832
# check first shape point coords
833
self.assertTrue(3000 <= result_start_point_wo[0] <= 3500) # x
834
self.assertTrue(190 <= result_start_point_wo[1] < 200) # y
835
self.assertTrue(result_start_point_wo[2] == 10) # z
836
837
# check second shape point coords - extra point
838
self.assertTrue(result_extra_point_wo[0] == 3250) # x
839
self.assertTrue(230 <= result_extra_point_wo[1] < 250) # y
840
self.assertTrue(result_extra_point_wo[2] == 10) # z
841
842
# check third shape point coords
843
self.assertTrue(3000 <= result_end_point_wo[0] <= 3500) # x
844
self.assertTrue(190 <= result_end_point_wo[1] < 200) # y
845
self.assertTrue(result_end_point_wo[2] == 10) # z
846
847
# check lane shape - with junction included
848
849
result_lane_shape_with_junc = \
850
the_lane.getShape3D(includeJunctions=True)
851
852
self.assertEqual(len(result_lane_shape_with_junc), 5)
853
854
result_from_point_wi = result_lane_shape_with_junc[0]
855
result_start_point_wi = result_lane_shape_with_junc[1]
856
result_extra_point_wi = result_lane_shape_with_junc[2]
857
result_end_point_wi = result_lane_shape_with_junc[3]
858
result_to_point_wi = result_lane_shape_with_junc[4]
859
860
# check fromNode coords
861
self.assertEqual(result_from_point_wi,
862
(3000, 200, 10))
863
864
# check first shape point coords
865
self.assertTrue(3000 <= result_start_point_wi[0] <= 3500) # x
866
self.assertTrue(190 <= result_start_point_wi[1] < 200) # y
867
self.assertTrue(result_start_point_wi[2] == 10) # z
868
869
# check second shape point coords - extra point
870
self.assertTrue(result_extra_point_wi[0] == 3250) # x
871
self.assertTrue(230 <= result_extra_point_wi[1] < 250) # y
872
self.assertTrue(result_extra_point_wi[2] == 10) # z
873
874
# check third shape point coords
875
self.assertTrue(3000 <= result_end_point_wi[0] <= 3500) # x
876
self.assertTrue(190 <= result_end_point_wi[1] < 200) # y
877
self.assertTrue(result_end_point_wi[2] == 10) # z
878
879
# check toNode coords
880
self.assertEqual(result_to_point_wi,
881
(3500, 200, 10))
882
883
@unittest.skipIf(False, '')
884
def test_straight_edge_005_lane_shape_2d(self):
885
"""
886
887
Single way edge with spread type center - no shape points
888
- no intersections engaged.
889
890
Shape of edge and lane are identic.
891
892
No junctions are included.
893
894
2d version.
895
"""
896
897
edge_id = 'straight_no_counter'
898
the_edge = self.sumo_net.getEdge(edge_id)
899
the_lane = the_edge.getLane(0) # straight_no_counter_0
900
901
expected_result = \
902
[(100.0, 100.0), (200.0, 100.0)]
903
904
# check lane shape
905
906
result_lane_shape_with_junc = \
907
the_lane.getShape(includeJunctions=True)
908
909
result_lane_shape_without_junc = \
910
the_lane.getShape(includeJunctions=False)
911
912
self.assertEqual(result_lane_shape_with_junc,
913
expected_result)
914
915
self.assertEqual(result_lane_shape_without_junc,
916
expected_result)
917
918
@unittest.skipIf(False, '')
919
def test_straight_edge_005_lane_shape(self):
920
"""
921
922
Single way edge with spread type center - no shape points
923
- no intersections engaged.
924
925
Shape of edge and lane are identic.
926
927
No junctions are included.
928
929
3d version.
930
"""
931
932
edge_id = 'straight_no_counter'
933
the_edge = self.sumo_net.getEdge(edge_id)
934
the_lane = the_edge.getLane(0) # straight_no_counter_0
935
936
expected_result = \
937
[(100.0, 100.0, 10.0), (200.0, 100.0, 10.0)]
938
939
# check lane shape
940
941
result_lane_shape_with_junc = \
942
the_lane.getShape3D(includeJunctions=True)
943
944
result_lane_shape_without_junc = \
945
the_lane.getShape3D(includeJunctions=False)
946
947
self.assertEqual(result_lane_shape_with_junc,
948
expected_result)
949
950
self.assertEqual(result_lane_shape_without_junc,
951
expected_result)
952
953
954
class Test_ShapesConvertion(unittest.TestCase):
955
956
""" """
957
958
@unittest.skipIf(False, '')
959
def test_convertShape_empty_string(self):
960
"""Inspecting the sumolib's function convertShape()"""
961
962
self.assertEqual(sumolib.net.convertShape(''), [])
963
964
@unittest.skipIf(False, '')
965
def test_convertShape_string_2d_one_point(self):
966
"""Inspecting the sumolib's function convertShape() with one 2d point"""
967
968
self.assertEqual(sumolib.net.convertShape('10,11'), [(10, 11, 0)])
969
970
@unittest.skipIf(False, '')
971
def test_convertShape_string_2d_two_point(self):
972
"""Inspecting the sumolib's function convertShape() with two 2d points"""
973
974
self.assertEqual(sumolib.net.convertShape('10,11 12,13 '),
975
[(10, 11, 0), (12, 13, 0)])
976
977
@unittest.skipIf(False, '')
978
def test_convertShape_string_3d_one_point(self):
979
"""Inspecting the sumolib's function convertShape() with one 3d point"""
980
981
self.assertEqual(sumolib.net.convertShape('10,11,5'), [(10, 11, 5)])
982
983
@unittest.skipIf(False, '')
984
def test_convertShape_string_3d_two_point(self):
985
"""Inspecting the sumolib's function convertShape() with two 3d points"""
986
987
self.assertEqual(sumolib.net.convertShape('10,11,5 12,13,5'),
988
[(10, 11, 5), (12, 13, 5)])
989
990
991
if __name__ == '__main__':
992
unittest.main()
993
994