1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
//! What a load did with the parts of a file it could not read as written.
use std::fmt;
use crate::SpeedLimit;
/// One thing a load dropped, or read against a rule of the OpenDRIVE spec,
/// in [`Provenance::warnings`](crate::Provenance::warnings).
///
/// Each variant names where in the file it happened, and `Display` gives the
/// message. New kinds are not a breaking change. [`Warning::Ignored`] names
/// what the crate skips in a file.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[non_exhaustive]
pub enum Warning {
/// A feature of the file the crate ignores: an element it skips, such as
/// `<userData>`, or an attribute that changes a road or a junction and
/// means nothing to it yet, such as `transitionLength`. The warning
/// comes once per feature for each road, junction, or the rest of the
/// document, with the number of uses, so a map with 2,000 of them
/// raises one.
///
/// `docs/support.md` and "What the importer ignores" in the crate docs
/// list the features. A feature leaves the list once the crate reads it.
Ignored {
/// The `<road id>` it is on, or `(no id)` for a road without one.
/// Empty for a feature of a junction or of the document outside
/// both.
road_id: String,
/// The `<junction id>` it is on, or `(no id)` for a junction
/// without one. Empty for a feature of a road or of the document
/// outside both.
junction_id: String,
/// The feature, such as `<userData>` or `<vmsGroup>`.
feature: String,
/// How many times the file uses it there.
count: usize,
},
/// The file uses an element or attribute that a newer OpenDRIVE than its
/// header's `revMinor` introduced, such as a `<boundary>` in a file that
/// declares 1.6. The crate reads it all the same; the header is what is
/// wrong. The warning comes once per feature for each road, junction, or
/// the rest of the document, with the number of uses, as
/// [`Self::Ignored`] does. The crate knows what 1.8 and 1.9 introduced,
/// from the revision history of the 1.9 specification, so a file that
/// declares 1.9, no version, or one it can't read raises none.
NewerThanDeclared {
/// The `<road id>` it is on, or `(no id)` for a road without one.
/// Empty for a feature of a junction or of the rest of the document.
road_id: String,
/// The `<junction id>` it is on, or `(no id)` for a junction without
/// one. Empty for a feature of a road or of the rest of the document.
junction_id: String,
/// The feature: an element such as `<boundary>`, or an element and
/// one of its attributes, such as `<signal length>`.
feature: String,
/// The `revMinor` of the OpenDRIVE 1 that introduced it.
introduced: u32,
/// The `revMinor` the header declares.
declared: u32,
/// How many times the file uses it there.
count: usize,
},
/// A `<road>` baked nothing, and everything on it went with it.
RoadSkipped {
/// Its `<road id>`.
road_id: String,
/// What it lacked.
reason: RoadSkipReason,
},
/// A `<planView><geometry>` the crate can't bake: one missing its `s`,
/// `x`, `y`, `hdg` or `length`, one whose `length` isn't above 0, or one
/// of a shape it doesn't know, or over [`MAX_LENGTH`](crate::MAX_LENGTH).
/// The crate drops it, so the geometry before
/// it runs on over its stretch of road.
GeometryDropped {
/// The `<road id>` it is on.
road_id: String,
/// Its `s`, if it has one.
s: Option<f64>,
},
/// A road mark line the crate can't paint. Either it has too many
/// dashes: more than 100,000 on the line, or more than are left of
/// 1,000,000 for the whole load, as when a broken file gives dashes a
/// fraction of a millimetre long. Or its width or offset is so large its
/// paint lands out of range. The line keeps its pattern and paints
/// nothing.
RoadMarkLineDropped {
/// The `<road id>` it is on.
road_id: String,
/// Where its mark starts, in metres along the reference line.
s: f64,
/// The `<lane id>` whose outer border it runs along, or 0 for the
/// center line.
lane: i32,
},
/// An `<object>` that would make more than 100,000 copies or dashes: a
/// `<repeat>` with a `distance` that short for its `length`, or a dashed
/// `<marking>`. A broken file can give a distance a fraction of a
/// millimetre. Also a repeat whose outlines would bake to over 1,000,000
/// corners, and an object whose copies, corners or sections would take
/// the file's objects past what one load bakes. The crate leaves out the
/// repeat's copies, the object, or the marking's paint.
TooManyCopies {
/// The `<road id>` it is on. Empty for an object of a junction.
road_id: String,
/// The `<junction id>` for an object of a junction. Empty otherwise.
junction_id: String,
/// Its `<object id>`.
object_id: String,
},
/// A `<repeat>` whose cubic `t`, from `bT`, `cT` and `dT`, ends more
/// than a millimetre from its `tEnd`. The spec says the two agree. The
/// crate follows the cubic.
RepeatEndMismatch {
/// The `<road id>` it is on. Empty for an object of a junction.
road_id: String,
/// The `<junction id>` for an object of a junction. Empty otherwise.
junction_id: String,
/// Its `<object id>`.
object_id: String,
/// Its `tEnd`.
t_end: f64,
/// The `t` its cubic reaches at its end.
reached: f64,
},
/// An `<outline>` whose `<curveLocal>`s do not join: one ends more than
/// a centimetre from where the next starts. The spec says they join.
/// The crate joins the gap with a straight edge.
OutlineGap {
/// The `<road id>` it is on. Empty for an object of a junction.
road_id: String,
/// The `<junction id>` for an object of a junction. Empty otherwise.
junction_id: String,
/// Its `<object id>`.
object_id: String,
/// The widest gap, in metres.
gap: f64,
},
/// A junction with `<objects>` but no `<planView>` geometry the crate
/// can bake, so nothing to place them along. The crate drops them.
JunctionObjectsDropped {
/// Its `<junction id>`.
junction_id: String,
},
/// A `<curveLocal>` whose `hdg` leaves a gap to the next curve, where
/// going on at the heading the curve before it ends at closes it. The
/// spec says the curves join. The crate departs from the `hdg` and goes
/// on at that heading.
CurveHeadingIgnored {
/// The `<road id>` it is on. Empty for an object of a junction.
road_id: String,
/// The `<junction id>` for an object of a junction. Empty otherwise.
junction_id: String,
/// Its `<object id>`.
object_id: String,
},
/// An `<outline>` the crate cannot place: one with a `<cornerRoad>` off
/// the road or missing `s` or `t`, a `<cornerLocal>` or `<curveLocal>` on
/// an object whose origin is off the road, fewer than two corners, or an
/// unfilled hole no closed outline encloses. The crate drops it. An
/// object left with no outline keeps its box.
OutlineDropped {
/// The `<road id>` it is on. Empty for an object of a junction.
road_id: String,
/// The `<junction id>` for an object of a junction. Empty otherwise.
junction_id: String,
/// Its `<object id>`.
object_id: String,
},
/// A `<polyline>` of an object's `<skeleton>` the crate cannot place: one
/// with a vertex past either end of the road, a `<vertexLocal>` on an
/// object whose origin is off the road, or fewer than two vertices. The
/// crate drops it. An object left with no polyline and no outline keeps
/// its box.
SkeletonDropped {
/// The `<road id>` it is on. Empty for an object of a junction.
road_id: String,
/// The `<junction id>` for an object of a junction. Empty otherwise.
junction_id: String,
/// Its `<object id>`.
object_id: String,
},
/// An object's `<surface>` the crate cannot place: on an object with no
/// box, such as a cylinder, an outline or a continuous repeat. The spec
/// allows a surface on a box only. The crate drops it.
ObjectSurfaceDropped {
/// The `<road id>` it is on. Empty for an object of a junction.
road_id: String,
/// The `<junction id>` for an object of a junction. Empty otherwise.
junction_id: String,
/// Its `<object id>`.
object_id: String,
},
/// An object's `<surface>` CRG with `hideRoadSurfaceCRG` over a road or
/// junction CRG that replaces the road's height (`attached0`, `genuine`
/// or `global`). The spec forbids it. The crate keeps the road's CRG and
/// adds the object's to it, as if `hideRoadSurfaceCRG` were false.
CrgHideIgnored {
/// The `<road id>` the object is on. Empty for an object of a
/// junction.
road_id: String,
/// The `<junction id>` for an object of a junction. Empty otherwise.
junction_id: String,
/// Its `<object id>`.
object_id: String,
},
/// A `<lane>` under `<left>` or `<right>` whose `id` isn't a whole
/// number, or is 0, the center lane's. The crate can't tell which lane
/// it is, so it drops it.
LaneIdUnreadable {
/// The `<road id>` it is on.
road_id: String,
/// Its zero-based lane section.
section: usize,
/// Its `id`, as the file writes it. Empty if it has none.
id: String,
},
/// A `<lane>` under `<left>` with a negative `id`, or under `<right>`
/// with a positive one. The spec numbers left lanes up from 1 and right
/// lanes down from -1, so the two disagree on its side. The crate drops
/// it.
LaneOnWrongSide {
/// The `<road id>` it is on.
road_id: String,
/// Its zero-based lane section.
section: usize,
/// Its `<lane id>`.
lane: i32,
},
/// A `<junction>` whose `id` an earlier junction has. The spec makes
/// junction ids unique. The crate keeps the first and drops this one
/// whole, so roads that name the id link through the first.
JunctionIdRepeated {
/// The `<junction id>`.
junction_id: String,
},
/// A `<lane>` whose `id` an earlier lane of its lane section has. The
/// spec makes lane ids unique in a section. The crate keeps the first
/// and drops this one.
LaneIdRepeated {
/// The `<road id>` it is on.
road_id: String,
/// Its zero-based lane section.
section: usize,
/// Its `<lane id>`.
lane: i32,
},
/// A `<lane>` with no `<width>` or `<border>` the crate could read. It
/// has no extent, so it did not bake, and neither did its road marks. A
/// lane outside it stacks on the lane inside it.
LaneDropped {
/// The `<road id>` it is on.
road_id: String,
/// The zero-based lane-section index, as in
/// [`LaneProvenance::section`](crate::LaneProvenance::section).
section: usize,
/// Its `<lane id>`.
lane: i32,
},
/// A `<lane>` with `<border>`s, in a lane section that also has
/// `<width>`s, on it or on another lane. The spec makes the two
/// exclusive, and uses the widths where a section has both, so read
/// literally a lane with only borders there has no extent. The crate
/// reads each lane on its own: its widths if it has any, and its borders
/// if not.
WidthAndBorder {
/// The `<road id>` it is on.
road_id: String,
/// The zero-based lane-section index.
section: usize,
/// Its `<lane id>`.
lane: i32,
},
/// A `<lane>` that takes its extent from `<border>`s, on a road whose
/// `<laneOffset>` is not 0 in its lane section. The spec forbids the two
/// together. The crate measures the border from the reference line and
/// ignores the offset for it.
BorderWithLaneOffset {
/// The `<road id>` it is on.
road_id: String,
/// The zero-based lane-section index.
section: usize,
/// Its `<lane id>`.
lane: i32,
},
/// A `<lane>` whose `<border>` lies inside its inner neighbour's outer
/// border, which the spec forbids. The crate gives the lane 0 width
/// there. Checked at the lane's stations.
BorderCrossesInnerLane {
/// The `<road id>` it is on.
road_id: String,
/// The zero-based lane-section index.
section: usize,
/// Its `<lane id>`.
lane: i32,
/// The first station where it crosses, in metres along the
/// reference line.
s: f64,
},
/// A `<lateralProfile>` whose `<shape>`s start inside the road's right
/// edge. The spec says each profile covers the whole road. The crate
/// holds the first shape's value from its `t` out to the edge.
ShapeShortOfRoad {
/// The `<road id>` it is on.
road_id: String,
/// The profile's `s`.
s: f64,
},
/// A `<road>` whose `rule` is neither `RHT` nor `LHT`, the two values
/// the spec allows. The crate reads it as `RHT`, the spec's default.
UnknownTrafficRule {
/// Its `<road id>`.
road_id: String,
/// The value of its `rule`.
rule: String,
},
/// A `<lane>` whose `direction` is none of `standard`, `reversed` and
/// `both`, the values the spec allows. The crate reads it as
/// `standard`, the spec's default.
UnknownLaneDirection {
/// The `<road id>` it is on.
road_id: String,
/// The zero-based lane-section index.
section: usize,
/// Its `<lane id>`.
lane: i32,
/// The value of its `direction`.
direction: String,
},
/// A junction `<connection>` without an `incomingRoad`, or without the
/// road it leads into: a `connectingRoad`, or a `linkedRoad` in a
/// `type="direct"` junction, or in a `<junction>` without the `id` the
/// spec requires. The spec requires both roads. The crate drops the
/// connection, so no lane links across it.
ConnectionDropped {
/// Its `incomingRoad`, empty if it has none.
incoming_road_id: String,
/// The `<junction id>` it is in, empty if it has none.
junction_id: String,
/// Its `<connection id>`, empty if it has none.
connection_id: String,
},
/// A junction `<laneLink>` whose `from` or `to` isn't a whole number.
/// The crate drops it, so the lane it names doesn't link across the
/// junction there.
LaneLinkDropped {
/// Its connection's `incomingRoad`.
incoming_road_id: String,
/// The `<junction id>` it is in.
junction_id: String,
/// Its `<connection id>`, empty if it has none.
connection_id: String,
/// Its `from`, as the file writes it.
from: String,
/// Its `to`, as the file writes it.
to: String,
},
/// A road that a common junction's `<connection>` names as its
/// `incomingRoad`, whose own `<link>` names the junction at neither end.
/// The spec says it must name it at the end that meets it. The crate finds that end
/// from the connecting road's link back to the road, and links the road
/// into the junction there, so its lanes drive on through it.
JunctionLinkMissing {
/// The incoming road's `<road id>`.
road_id: String,
/// The `<junction id>`.
junction_id: String,
/// The end of the road the junction was added to.
end: RoadEnd,
},
/// A `<road>` whose `length` differs from where its `<planView>` ends,
/// by more than a centimetre. The spec says they are the same. The crate
/// bakes the road to its `length`, as libOpenDRIVE does, so it stops
/// short of its geometry's end, or runs its last geometry on past it.
RoadLengthMismatch {
/// Its `<road id>`.
road_id: String,
/// Its `length`, in metres.
length: f64,
/// Where its last `<geometry>` ends: its `s` plus its `length`.
plan_view: f64,
},
/// A lane link between lanes that don't meet: the lane's exit and its
/// successor's entry are more than 10 cm apart, measured across both
/// lanes from border to border. The crate keeps the link.
LinkGap {
/// The `<road id>` of the lane the link leaves.
road_id: String,
/// Its zero-based lane-section index.
section: usize,
/// Its `<lane id>`.
lane: i32,
/// The `<road id>` of the lane it leads into.
to_road_id: String,
/// That lane's zero-based lane-section index.
to_section: usize,
/// That lane's `<lane id>`.
to_lane: i32,
/// How far apart they are, in metres.
gap: f64,
},
/// A road `<neighbor>` naming no road the load baked, or whose `side` is
/// neither `left` nor `right`, or whose `direction` is neither `same`
/// nor `opposite`. The crate drops it.
NeighborDropped {
/// The `<road id>` whose `<link>` it is in.
road_id: String,
/// Its `elementId`, empty if it has none.
neighbor_id: String,
/// Its `side`, empty if it has none.
side: String,
/// Its `direction`, empty if it has none.
direction: String,
},
/// A junction `<priority>` whose `high` or `low` names no road the load
/// baked. The crate drops it.
PriorityDropped {
/// The `<junction id>` it is in.
junction_id: String,
/// Its `high`, empty if it has none.
high: String,
/// Its `low`, empty if it has none.
low: String,
/// The road of the two the load has, or `low` if it has neither.
road_id: String,
},
/// A railway `<switch>` or a platform `<segment>` the crate can't place:
/// one naming a road the load lacks, an `s` off that road, a segment
/// whose `sEnd` is before its `sStart`, a switch with no `position`, or
/// a `dir` or `side` the spec does not allow. The crate drops it. A
/// `position` it does not know is [`SwitchPosition::Unknown`](crate::SwitchPosition::Unknown).
RailwayDropped {
/// `switch` or `platform segment`.
element: String,
/// The switch's `id`, or the platform's.
id: String,
/// The road it is on, or names.
road_id: String,
},
/// A `<junction type="virtual">` with no `mainRoad`, one naming a road
/// the load lacks, or an `sStart` or `sEnd` missing or off that road. The
/// spec requires them. The crate keeps the junction's links, without a
/// main road.
VirtualJunctionWithoutMainRoad {
/// The `<junction id>`.
junction_id: String,
},
/// A virtual junction's link the crate can't place: one naming a road
/// the load lacks, an `elementS` off that road, or an `elementDir` other
/// than `+` or `-`. The crate drops it.
VirtualLinkDropped {
/// The `<junction id>`.
junction_id: String,
/// The road whose `<link>` it is, empty for a `type="virtual"`
/// connection.
road_id: String,
/// The connection's `id`, empty for a road's `<link>`.
connection_id: String,
},
/// A lane pair of a virtual junction's link that names a lane its road
/// doesn't have there. The crate keeps the link without that pair.
VirtualLaneDropped {
/// The `<junction id>`.
junction_id: String,
/// The road whose `<link>` gives the link, empty for a
/// `type="virtual"` connection.
road_id: String,
/// The connection's `id`, empty for a road's `<link>`.
connection_id: String,
/// The pair's first `<lane id>`: on the link's road, or a
/// `<laneLink>`'s `from`.
from: i32,
/// The pair's second `<lane id>`: on the road it meets, or a
/// `<laneLink>`'s `to`.
to: i32,
},
/// A `<junctionReference>` naming a junction the file does not have. The
/// crate leaves it out of the group.
JunctionReferenceDropped {
/// The `<junctionGroup id>`.
group_id: String,
/// The `junction` it names, empty if it has none.
junction_id: String,
},
/// A `<junctionGroup>` whose `type` is none the spec allows, or missing,
/// though the spec requires it. The crate reads it as `unknown`.
UnknownJunctionGroupType {
/// The `<junctionGroup id>`.
group_id: String,
/// Its `type`, empty if it has none.
kind: String,
},
/// A `<crossPath>` whose `crossingRoad`, `roadAtStart` or `roadAtEnd`
/// names no baked road, or whose lane links name a lane, or an `s`, those
/// roads don't have. The crate drops it.
CrossPathDropped {
/// The `<junction id>`.
junction_id: String,
/// Its `id`, empty if it has none.
cross_path_id: String,
/// The road it can't be placed on: its `crossingRoad`, or the
/// `roadAtStart` or `roadAtEnd` of the end that fails. Empty if the
/// file names none.
road_id: String,
},
/// A road with a `<crossSectionSurface>` and also `<shape>`s or a
/// `<superelevation>`, which the spec forbids. The crate adds them up.
CrossSectionWithShape {
/// Its `<road id>`.
road_id: String,
},
/// A cross-section `<strip>` the crate can't use: its `id` is not 1, 2,
/// -1 or -2, it repeats an `id` before it, or it is an outer strip with
/// no inner strip beside it, or one without a `<width>`. The spec needs
/// the inner strip's width to know where the outer one starts. The crate
/// drops it.
StripDropped {
/// The `<road id>` it is on.
road_id: String,
/// Its `id`, as the file writes it.
strip: String,
},
/// An outer cross-section `<strip>` whose `mode` is neither `independent`
/// nor `relative`. The crate reads it as `independent`. An inner strip's
/// `mode` means nothing, and is not read.
UnknownStripMode {
/// The `<road id>` it is on.
road_id: String,
/// The strip's `id`.
strip: i32,
/// Its `mode`.
mode: String,
},
/// An `<include>` the crate can't read in. The document goes on without
/// what it names.
IncludeDropped {
/// Its `file`, as the document writes it.
file: String,
/// Why.
problem: IncludeProblem,
},
/// A crossing's `<roadSection>` naming a road the load didn't bake, or
/// without an `sStart` and `sEnd` on that road. The crate drops it.
RoadSectionDropped {
/// The `<junction id>`.
junction_id: String,
/// Its `roadId`.
road_id: String,
},
/// A boundary `joint` segment with a `transitionLength`, in a junction
/// with an `<elevationGrid>`, without a `lane` segment on each side of it
/// to measure the zone along, or naming a road the load didn't bake. The
/// road meets the grid with no zone between them.
TransitionDropped {
/// The `<junction id>`.
junction_id: String,
/// The joint's `roadId`.
road_id: String,
},
/// A junction `<boundary>` `<segment>` naming no baked road, a lane its
/// road does not have, a `type` other than `lane` or `joint`, or an
/// `sStart`, `sEnd` or `contactPoint` off its road. The crate drops it,
/// so the boundary has a gap there.
BoundarySegmentDropped {
/// The `<junction id>`.
junction_id: String,
/// The segment's `roadId`, empty if it has none.
road_id: String,
},
/// A junction `<elevationGrid>` the crate can't place: its junction has
/// no `<planView>`, one that is not a single straight `<line>`, or no
/// `gridSpacing` above 0. The crate drops it.
ElevationGridDropped {
/// The `<junction id>`.
junction_id: String,
},
/// A junction `<boundary>` whose segments don't meet: one leaves off
/// more than 10 cm in plan from where the next begins, or the last from
/// where the first begins, as when it has one segment. The spec says they close the boundary. The crate joins
/// them straight.
BoundaryNotClosed {
/// The `<junction id>`.
junction_id: String,
/// The widest gap, in metres.
gap: f64,
},
/// A junction `<boundary>` whose segments run clockwise. The spec says
/// they run counter-clockwise. The crate turns the boundary round.
BoundaryClockwise {
/// The `<junction id>`.
junction_id: String,
},
/// A `<speed>` whose `max` or `unit` the crate can't read, or whose
/// limit is too large for an `f32`. The crate drops it, so the lane's limit there is its road's, or the lane's
/// `<speed>` before it.
SpeedLimitDropped {
/// The `<road id>` it is on.
road_id: String,
/// Where it starts, in metres along the reference line.
s: f64,
/// The `<lane id>` whose `<speed>` it is, or `None` for a road
/// `<type>`'s.
lane: Option<i32>,
/// Its `max`, as the file writes it.
max: String,
/// Its `unit`, as the file writes it. Empty if it has none.
unit: String,
},
/// A speed limit sign whose limit differs from the `<speed>` record, the
/// lane's or its road type's, on a lane where it applies. The sign's
/// limit holds there, as the spec says signals take priority.
SpeedLimitDisagrees {
/// The `<road id>` the sign is on.
road_id: String,
/// Where the sign stands, in metres along the reference line.
s: f64,
/// The `<lane id>` it applies to where they differ.
lane: i32,
/// The limit the sign sets.
sign: SpeedLimit,
/// The limit the record sets.
record: SpeedLimit,
},
/// A lane `<access>` whose `rule` is neither `allow` nor `deny`, so it
/// says nothing about who may use the lane. The lane is open to
/// everyone from its `sOffset` to the next `<access>`.
AccessDropped {
/// The `<road id>` it is on.
road_id: String,
/// Where it starts, in metres along the reference line.
s: f64,
/// The `<lane id>` whose `<access>` it is.
lane: i32,
/// Its `rule`, as the file writes it. Empty if it has none.
rule: String,
},
/// A lane `<visibility>` with a distance missing, not a number, below 0,
/// or too large for an `f32`. The lane has no visibility from its `sOffset` to the next
/// `<visibility>`.
VisibilityDropped {
/// The `<road id>` it is on.
road_id: String,
/// Where it starts, in metres along the reference line.
s: f64,
/// The `<lane id>` whose `<visibility>` it is.
lane: i32,
/// The first distance the crate can't read: `forward`, `back`,
/// `left` or `right`.
distance: String,
/// Its value, as the file writes it. Empty if it has none.
value: String,
},
/// A `<lane>` without `level="true"` outside one with it. The spec
/// says every lane outside a level lane is level too. The crate holds
/// it level.
LaneNotLevel {
/// The `<road id>` it is on.
road_id: String,
/// The zero-based lane-section index.
section: usize,
/// Its `<lane id>`.
lane: i32,
},
/// A road `<predecessor>` or `<successor>` naming a road without the
/// `contactPoint` the spec requires there. The crate joins the start of
/// that road, as libOpenDRIVE does.
ContactPointMissing {
/// The `<road id>` whose link it is.
road_id: String,
/// The end of the road the link leaves from.
end: RoadEnd,
},
/// A `<roadMark>` whose `sOffset` is the same as the next one's on its
/// lane, so the next one replaces it before it paints anything, or one
/// past the end of its lane section that no single-side section after
/// it carries on. The crate drops it. One right at the end of its
/// section goes without a warning, as exporters write them there.
RoadMarkDropped {
/// The `<road id>` it is on.
road_id: String,
/// The zero-based lane-section index.
section: usize,
/// The `<lane id>` whose mark it is.
lane: i32,
/// Its `sOffset`, in metres from the start of its lane section.
s_offset: f64,
},
/// A `<signal>` without a readable `s` or `t`, or off the ends of its
/// road. The crate drops it.
SignalDropped {
/// The `<road id>` it is on.
road_id: String,
/// Its `id`. Empty if it has none.
signal_id: String,
},
/// A signal's or a sign's `<dependency>` or `<reference>`, a
/// `<signalReference>`, a `<controller>`'s `<control>` or a
/// `<vmsGroup>`'s `<vmsBoardReference>` naming a signal, sign or object
/// the load didn't bake, or a junction's `<controller>` naming no
/// `<controller>`. Also a `<signalReference>` without a readable `s` or
/// `t`, or off the ends of its road. The crate drops it.
SignalLinkDropped {
/// The `<road id>` it is on. Empty for a `<control>` or a
/// `<vmsBoardReference>`.
road_id: String,
/// Its element: `dependency`, `reference`, `signalReference`,
/// `control` or `vmsBoardReference`.
element: String,
/// The id it names.
id: String,
},
/// A road or junction `<CRG>` the crate can't lay: one without a `file`,
/// a road one without a readable `sStart` or `sEnd`, with a `sEnd` not
/// past its `sStart` on the road, or with a `mode` the crate doesn't
/// know, a junction one whose `mode` is not `global`, the one mode it
/// may have, or one whose `purpose` is neither `elevation` nor
/// `friction`. Also a road one past
/// [`MAX_BAKED_LENGTH`](crate::MAX_BAKED_LENGTH). The crate drops it.
CrgDropped {
/// The `<road id>` it is on. Empty for one of a junction.
road_id: String,
/// The `<junction id>` for one of a junction. Empty otherwise.
junction_id: String,
/// Its `file`. Empty if it has none.
file: String,
},
/// An `<object>` without a readable `s` or `t`, or an
/// `<objectReference>` without one or naming no `<object>` in the file.
/// The crate drops it.
ObjectDropped {
/// The `<road id>` it is on. Empty for an object of a junction.
road_id: String,
/// The `<junction id>` for an object of a junction. Empty otherwise.
junction_id: String,
/// Its `id`, or for a reference, the id it names.
object_id: String,
},
/// An object's `<repeat>` without a readable `s`, `length` or
/// `distance`, or with a negative `length` or `distance`. The crate
/// drops the repeat. An object left with none stands at its own `s`.
RepeatDropped {
/// The `<road id>` it is on. Empty for an object of a junction.
road_id: String,
/// The `<junction id>` for an object of a junction. Empty otherwise.
junction_id: String,
/// Its `<object id>`.
object_id: String,
},
/// An object's `<marking>` the crate can't paint: one without a width
/// above 0, one whose `<cornerReference>`s name fewer than two corners
/// or a corner no outline has, or one with no corners whose `side` is
/// not `front`, `rear`, `left` or `right`. The crate drops it.
MarkingDropped {
/// The `<road id>` it is on. Empty for an object of a junction.
road_id: String,
/// The `<junction id>` for an object of a junction. Empty otherwise.
junction_id: String,
/// Its `<object id>`.
object_id: String,
},
/// A `<tunnel>` or `<bridge>` without a readable `s` or `length`, or
/// with a negative `length`. The crate drops it.
StructureDropped {
/// The `<road id>` it is on.
road_id: String,
/// Its `id`. Empty if it has none.
structure_id: String,
},
/// A `<laneSection>` that starts past the end of its road. The crate
/// drops it and its lanes. One under 1 mm long inside the road, which
/// exporters write where two sections meet, is dropped too, without a
/// warning, since links across it still join the sections either side.
LaneSectionDropped {
/// The `<road id>` it is on.
road_id: String,
/// The zero-based lane-section index, counted in order of `s`.
section: usize,
/// Where it starts, in metres along the reference line.
s: f64,
},
/// A profile record the crate can't place: an `<elevation>`,
/// `<superelevation>`, `<crossfall>`, `<laneOffset>` or road `<type>`
/// without a readable `s`, a `<shape>` without a readable `s` or `t`, or
/// a lane `<width>` or `<border>` without a readable `a`. The crate drops it,
/// so the record before it runs on.
RecordDropped {
/// The `<road id>` it is on.
road_id: String,
/// Its element, such as `elevation`.
record: String,
/// For a record of a lane, the zero-based lane-section index.
section: Option<usize>,
/// For a record of a lane, its `<lane id>`.
lane: Option<i32>,
/// Where it starts, its `s` or `sOffset`, if the crate can read it.
s: Option<f64>,
/// The attribute it lacks, such as `s` or `a`.
attribute: String,
},
/// A number of a profile record, such as an `<elevation>`'s `b`, that
/// the file writes but the crate can't read: not a number, or one that
/// is not finite, such as `NaN`. The crate reads it as 0, as it reads
/// one the file leaves out.
RecordValueUnreadable {
/// The `<road id>` it is on.
road_id: String,
/// Its element, such as `elevation`.
record: String,
/// For a record of a lane, the zero-based lane-section index.
section: Option<usize>,
/// For a record of a lane, its `<lane id>`.
lane: Option<i32>,
/// Where it starts, its `s` or `sOffset`, if the crate can read it.
s: Option<f64>,
/// The attribute, such as `b`.
attribute: String,
},
/// Records of one kind, such as a road's `<elevation>`s or a lane's
/// `<width>`s, that don't come in the ascending order of where they
/// start, as the spec requires. The crate sorts them.
RecordsOutOfOrder {
/// The `<road id>` they are on.
road_id: String,
/// Their element, such as `elevation`.
record: String,
/// For records of a lane, the zero-based lane-section index.
section: Option<usize>,
/// For records of a lane, its `<lane id>`.
lane: Option<i32>,
},
}
/// Why an `<include>` was left out.
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[non_exhaustive]
pub enum IncludeProblem {
/// It has no `file`.
NoFile,
/// The file couldn't be read, for the reason given, such as a document
/// read from a string, with no folder to read from.
Unreadable(String),
/// The file includes, at some depth, the file that includes it.
Cycle,
/// Includes nest more than 8 deep.
TooDeep,
/// Reading it would take the document past
/// [`MAX_INCLUDED_BYTES`](crate::MAX_INCLUDED_BYTES).
TooLarge,
/// The file isn't well-formed XML, or nests its elements more than 256
/// deep, its own includes read in.
NotXml,
/// The file's root isn't the element the `<include>` stands in.
WrongRoot,
}
impl fmt::Display for IncludeProblem {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::NoFile => f.write_str("it names no file"),
Self::Unreadable(why) => write!(f, "{why}"),
Self::Cycle => f.write_str("it includes itself"),
Self::TooDeep => f.write_str("includes nest more than 8 deep"),
Self::TooLarge => f.write_str("the includes read in more than 256 MiB"),
Self::NotXml => f.write_str("it isn't well-formed XML, or nests too deep"),
Self::WrongRoot => f.write_str("its root isn't the element the <include> is in"),
}
}
}
/// Why a `<road>` baked nothing.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[non_exhaustive]
pub enum RoadSkipReason {
/// It has no `length`, or one that is not a finite number above zero.
NoLength,
/// It has no `<planView>`.
NoPlanView,
/// Its `<planView>` has no `<geometry>` the crate can bake: each one is
/// missing a coordinate, carries one that is not a finite number, or has
/// a shape the crate does not know.
NoGeometry,
/// Its `length` is over [`MAX_LENGTH`](crate::MAX_LENGTH), 100 km.
TooLong,
/// Its lanes land outside the range an `f32` holds, from a number such
/// as an elevation or a lane width of `1e39`.
OutOfRange,
/// Its lanes would take the file past
/// [`MAX_BAKED_LENGTH`](crate::MAX_BAKED_LENGTH), 2,000 km of lanes.
MapTooLarge,
}
impl Warning {
/// Whether it only says the crate ignored part of the file, as
/// [`Warning::Ignored`] does, and the file broke no rule. A map that
/// loads clean can still raise these, so filter them out to find faults.
pub fn is_ignored(&self) -> bool {
matches!(self, Self::Ignored { .. })
}
/// The `<road id>` it happened on. Empty for a warning about a junction
/// as a whole, such as its boundary or its elevation grid.
pub fn road_id(&self) -> &str {
match self {
Self::RoadSkipped { road_id, .. }
| Self::GeometryDropped { road_id, .. }
| Self::LaneIdUnreadable { road_id, .. }
| Self::TooManyCopies { road_id, .. }
| Self::RepeatEndMismatch { road_id, .. }
| Self::OutlineGap { road_id, .. }
| Self::ObjectSurfaceDropped { road_id, .. }
| Self::SkeletonDropped { road_id, .. }
| Self::OutlineDropped { road_id, .. }
| Self::CurveHeadingIgnored { road_id, .. }
| Self::CrgHideIgnored { road_id, .. }
| Self::RoadMarkLineDropped { road_id, .. }
| Self::LaneDropped { road_id, .. }
| Self::WidthAndBorder { road_id, .. }
| Self::LaneOnWrongSide { road_id, .. }
| Self::LaneIdRepeated { road_id, .. }
| Self::BorderWithLaneOffset { road_id, .. }
| Self::BorderCrossesInnerLane { road_id, .. }
| Self::ShapeShortOfRoad { road_id, .. }
| Self::UnknownTrafficRule { road_id, .. }
| Self::UnknownLaneDirection { road_id, .. }
| Self::SpeedLimitDropped { road_id, .. }
| Self::SpeedLimitDisagrees { road_id, .. }
| Self::AccessDropped { road_id, .. }
| Self::VisibilityDropped { road_id, .. }
| Self::JunctionLinkMissing { road_id, .. }
| Self::RoadLengthMismatch { road_id, .. }
| Self::LinkGap { road_id, .. }
| Self::LaneNotLevel { road_id, .. }
| Self::RecordDropped { road_id, .. }
| Self::LaneSectionDropped { road_id, .. }
| Self::ObjectDropped { road_id, .. }
| Self::CrgDropped { road_id, .. }
| Self::SignalDropped { road_id, .. }
| Self::RoadMarkDropped { road_id, .. }
| Self::ContactPointMissing { road_id, .. }
| Self::SignalLinkDropped { road_id, .. }
| Self::RepeatDropped { road_id, .. }
| Self::MarkingDropped { road_id, .. }
| Self::StructureDropped { road_id, .. }
| Self::RecordValueUnreadable { road_id, .. }
| Self::RecordsOutOfOrder { road_id, .. }
| Self::PriorityDropped { road_id, .. }
| Self::NeighborDropped { road_id, .. }
| Self::BoundarySegmentDropped { road_id, .. }
| Self::CrossPathDropped { road_id, .. }
| Self::CrossSectionWithShape { road_id }
| Self::RailwayDropped { road_id, .. }
| Self::VirtualLinkDropped { road_id, .. }
| Self::VirtualLaneDropped { road_id, .. }
| Self::UnknownStripMode { road_id, .. }
| Self::StripDropped { road_id, .. }
| Self::Ignored { road_id, .. }
| Self::NewerThanDeclared { road_id, .. }
| Self::LaneLinkDropped {
incoming_road_id: road_id,
..
}
| Self::ConnectionDropped {
incoming_road_id: road_id,
..
} => road_id,
Self::TransitionDropped { .. }
| Self::IncludeDropped { .. }
| Self::RoadSectionDropped { .. }
| Self::JunctionReferenceDropped { .. }
| Self::VirtualJunctionWithoutMainRoad { .. }
| Self::UnknownJunctionGroupType { .. }
| Self::ElevationGridDropped { .. }
| Self::JunctionObjectsDropped { .. }
| Self::BoundaryNotClosed { .. }
| Self::BoundaryClockwise { .. }
| Self::JunctionIdRepeated { .. } => "",
}
}
}
impl fmt::Display for Warning {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::NewerThanDeclared {
road_id,
junction_id,
feature,
introduced,
declared,
count,
} => {
let place = if !road_id.is_empty() {
format!("road {road_id:?}")
} else if !junction_id.is_empty() {
format!("junction {junction_id:?}")
} else {
"the document".to_string()
};
let uses = if *count == 1 { "use" } else { "uses" };
write!(
f,
"{place} uses {feature} ({count} {uses}), which OpenDRIVE 1.{introduced} \
introduced, but the header declares 1.{declared}; read anyway"
)
}
Self::Ignored {
road_id,
junction_id,
feature,
count,
} => {
let place = if !road_id.is_empty() {
format!("road {road_id:?}")
} else if !junction_id.is_empty() {
format!("junction {junction_id:?}")
} else {
"the document".to_string()
};
let uses = if *count == 1 { "use" } else { "uses" };
write!(f, "{place}: {feature} ignored, {count} {uses}")
}
Self::RoadSkipped { road_id, reason } => {
write!(f, "road {road_id:?} skipped: {reason}")
}
Self::LaneDropped {
road_id,
section,
lane,
} => write!(
f,
"road {road_id:?}, lane section {section}: lane {lane} dropped, it has no usable <width> or <border>"
),
Self::LaneOnWrongSide {
road_id,
section,
lane,
} => write!(
f,
"road {road_id:?}, lane section {section}: lane {lane} is on the other side from its id, dropped"
),
Self::JunctionIdRepeated { junction_id } => {
write!(f, "junction {junction_id:?}: a second junction of that id, dropped")
}
Self::LaneIdRepeated {
road_id,
section,
lane,
} => write!(
f,
"road {road_id:?}, lane section {section}: a second lane {lane}, dropped"
),
Self::WidthAndBorder {
road_id,
section,
lane,
} => write!(
f,
"road {road_id:?}, lane section {section}: lane {lane} has <border>s in a section with <width>s"
),
Self::BorderWithLaneOffset {
road_id,
section,
lane,
} => write!(
f,
"road {road_id:?}, lane section {section}: lane {lane} has <border>s under a <laneOffset>, which they ignore"
),
Self::BorderCrossesInnerLane {
road_id,
section,
lane,
s,
} => write!(
f,
"road {road_id:?}, lane section {section}: lane {lane}'s <border> crosses inside the lane within it at s {s:.2} m"
),
Self::ShapeShortOfRoad { road_id, s } => write!(
f,
"road {road_id:?}: the <shape>s at s {s:.2} m start inside the road's right edge"
),
Self::UnknownTrafficRule { road_id, rule } => write!(
f,
"road {road_id:?}: rule {rule:?} is neither \"RHT\" nor \"LHT\", read as \"RHT\""
),
Self::ConnectionDropped {
incoming_road_id,
junction_id,
connection_id,
} => write!(
f,
"junction {junction_id:?}: connection {connection_id:?} from road {incoming_road_id:?} dropped, it lacks the road it comes from or leads into"
),
Self::SpeedLimitDropped {
road_id,
s,
lane,
max,
unit,
} => {
let whose = lane.map_or("its type's".to_string(), |l| format!("lane {l}'s"));
write!(
f,
"road {road_id:?}: {whose} <speed> at s {s:.2} m dropped, max {max:?} unit {unit:?} is not a speed"
)
}
Self::SpeedLimitDisagrees {
road_id,
s,
lane,
sign,
record,
} => write!(
f,
"road {road_id:?}: lane {lane}'s speed sign at s {s:.2} m sets {}, where a <speed> sets {}; the sign holds",
limit_text(*sign),
limit_text(*record)
),
Self::AccessDropped {
road_id,
s,
lane,
rule,
} => write!(
f,
"road {road_id:?}: lane {lane}'s <access> at s {s:.2} m dropped, rule {rule:?} is neither allow nor deny"
),
Self::GeometryDropped { road_id, s } => match s {
Some(s) => write!(f, "road {road_id:?}: <geometry> at s {s:.2} m dropped"),
None => write!(f, "road {road_id:?}: <geometry> without an s dropped"),
},
Self::RoadMarkLineDropped { road_id, s, lane } => write!(
f,
"road {road_id:?}: a line of the road mark on lane {lane} at s {s:.2} m can't be painted"
),
Self::TooManyCopies {
road_id,
junction_id,
object_id,
} => write!(
f,
"{}: object {object_id:?} would make over 100,000 copies or dashes, so they were left out",
place(road_id, junction_id)
),
Self::RepeatEndMismatch {
road_id,
junction_id,
object_id,
t_end,
reached,
} => write!(
f,
"{}: a repeat of object {object_id:?} has tEnd {t_end:.3}, but its cubic reaches {reached:.3}",
place(road_id, junction_id)
),
Self::OutlineGap {
road_id,
junction_id,
object_id,
gap,
} => write!(
f,
"{}: object {object_id:?} has an outline whose curves leave a gap of {gap:.3} m",
place(road_id, junction_id)
),
Self::JunctionObjectsDropped { junction_id } => write!(
f,
"junction {junction_id:?}: its objects have no reference line to stand along, so they were left out"
),
Self::CurveHeadingIgnored {
road_id,
junction_id,
object_id,
} => write!(
f,
"{}: object {object_id:?} has a <curveLocal> whose hdg leaves a gap, so it goes on from the curve before instead",
place(road_id, junction_id)
),
Self::OutlineDropped {
road_id,
junction_id,
object_id,
} => write!(
f,
"{}: object {object_id:?} has an <outline> it can't place, so it was left out",
place(road_id, junction_id)
),
Self::SkeletonDropped {
road_id,
junction_id,
object_id,
} => write!(
f,
"{}: object {object_id:?} has a <skeleton> polyline it can't place, so it was left out",
place(road_id, junction_id)
),
Self::ObjectSurfaceDropped {
road_id,
junction_id,
object_id,
} => write!(
f,
"{}: object {object_id:?} has a <surface> but is no box, the one shape the spec allows one on, so the surface was left out",
place(road_id, junction_id)
),
Self::CrgHideIgnored {
road_id,
junction_id,
object_id,
} => write!(
f,
"{}: object {object_id:?} hides a road CRG that replaces the road's height, which the spec forbids, so the road CRG stays",
place(road_id, junction_id)
),
Self::LaneIdUnreadable {
road_id,
section,
id,
} => write!(
f,
"road {road_id:?}: a lane in section {section} with id {id:?} dropped, the id isn't a whole number other than 0"
),
Self::LaneLinkDropped {
incoming_road_id,
junction_id,
connection_id,
from,
to,
} => write!(
f,
"junction {junction_id:?}: connection {connection_id:?} from road {incoming_road_id:?} dropped a <laneLink> from {from:?} to {to:?}, not whole numbers"
),
Self::VirtualLaneDropped {
junction_id,
road_id,
connection_id,
from,
to,
} => write!(
f,
"junction {junction_id:?}: link from road {road_id:?} connection {connection_id:?} dropped lane pair {from} to {to}, a lane it names isn't there"
),
Self::RoadLengthMismatch {
road_id,
length,
plan_view,
} => write!(
f,
"road {road_id:?}: length {length:.3} m, but its <planView> ends at {plan_view:.3} m"
),
Self::LinkGap {
road_id,
section,
lane,
to_road_id,
to_section,
to_lane,
gap,
} => write!(
f,
"road {road_id:?}, lane section {section}: lane {lane} links to road {to_road_id:?}, lane section {to_section}, lane {to_lane}, {gap:.2} m away"
),
Self::RailwayDropped {
element,
id,
road_id,
} => write!(f, "road {road_id:?}: {element} {id:?} dropped"),
Self::VirtualJunctionWithoutMainRoad { junction_id } => write!(
f,
"junction {junction_id:?}: virtual junction read without its main road, it lacks the road or where along it it runs"
),
Self::VirtualLinkDropped {
junction_id,
road_id,
connection_id,
} if road_id.is_empty() => write!(
f,
"junction {junction_id:?}: virtual connection {connection_id:?} dropped"
),
Self::VirtualLinkDropped {
junction_id,
road_id,
..
} => write!(
f,
"junction {junction_id:?}: road {road_id:?}'s link part way along a road dropped"
),
Self::JunctionReferenceDropped {
group_id,
junction_id,
} => write!(
f,
"junction group {group_id:?}: <junctionReference> to junction {junction_id:?} dropped, the file has no such junction"
),
Self::UnknownJunctionGroupType { group_id, kind } => write!(
f,
"junction group {group_id:?}: type {kind:?} read as unknown"
),
Self::CrossSectionWithShape { road_id } => write!(
f,
"road {road_id:?}: <crossSectionSurface> with <shape>s or a <superelevation>, heights added"
),
Self::StripDropped { road_id, strip } => write!(
f,
"road {road_id:?}: <strip> {strip:?} dropped, its id is not 1, 2, -1 or -2, repeats one before it, or it is an outer strip with no inner strip of a width beside it"
),
Self::UnknownStripMode {
road_id,
strip,
mode,
} => write!(
f,
"road {road_id:?}: <strip> {strip} has mode {mode:?}, read as independent"
),
Self::CrossPathDropped {
junction_id,
cross_path_id,
road_id,
} => write!(
f,
"junction {junction_id:?}: <crossPath> {cross_path_id:?} dropped, it can't be placed on road {road_id:?}"
),
Self::IncludeDropped { file, problem } => {
write!(f, "<include> of {file:?} left out: {problem}")
}
Self::RoadSectionDropped {
junction_id,
road_id,
} => write!(
f,
"junction {junction_id:?}: <roadSection> on road {road_id:?} can't be placed, dropped"
),
Self::TransitionDropped {
junction_id,
road_id,
} => write!(
f,
"junction {junction_id:?}: the joint of road {road_id:?} has a transitionLength but no lane segment each side, so no transition"
),
Self::ElevationGridDropped { junction_id } => write!(
f,
"junction {junction_id:?}: <elevationGrid> dropped, it needs one straight <planView> <line> and a gridSpacing above 0"
),
Self::BoundarySegmentDropped {
junction_id,
road_id,
} => write!(
f,
"junction {junction_id:?}: <boundary> segment on road {road_id:?} dropped"
),
Self::BoundaryNotClosed { junction_id, gap } => write!(
f,
"junction {junction_id:?}: <boundary> segments leave a {gap:.2} m gap, joined straight"
),
Self::BoundaryClockwise { junction_id } => write!(
f,
"junction {junction_id:?}: <boundary> runs clockwise, turned round"
),
Self::NeighborDropped {
road_id,
neighbor_id,
side,
direction,
} => write!(
f,
"road {road_id:?}: <neighbor> road {neighbor_id:?}, side {side:?}, direction {direction:?} dropped"
),
Self::PriorityDropped {
junction_id,
high,
low,
..
} => write!(
f,
"junction {junction_id:?}: <priority> of road {high:?} over road {low:?} dropped, the load has no such road"
),
Self::UnknownLaneDirection {
road_id,
section,
lane,
direction,
} => write!(
f,
"road {road_id:?}, lane section {section}: lane {lane} has direction {direction:?}, read as standard"
),
Self::JunctionLinkMissing {
road_id,
junction_id,
end,
} => write!(
f,
"road {road_id:?}: its <link> leaves out junction {junction_id:?} at its {end}, linked from the junction's connecting road"
),
Self::VisibilityDropped {
road_id,
s,
lane,
distance,
value,
} => write!(
f,
"road {road_id:?}: lane {lane}'s <visibility> at s {s:.2} m dropped, {distance} {value:?} is not a distance"
),
Self::LaneNotLevel {
road_id,
section,
lane,
} => write!(
f,
"road {road_id:?}, lane section {section}: lane {lane} is outside a level lane but not level, held level"
),
Self::ContactPointMissing { road_id, end } => write!(
f,
"road {road_id:?}: the link at its {end} names a road without a contactPoint, joined at that road's start"
),
Self::RoadMarkDropped {
road_id,
section,
lane,
s_offset,
} => write!(
f,
"road {road_id:?}, lane section {section}, lane {lane}: <roadMark> at sOffset {s_offset:.2} m paints nothing, dropped"
),
Self::SignalDropped { road_id, signal_id } => write!(
f,
"road {road_id:?}: signal {signal_id:?} has no readable s or t on the road, dropped"
),
Self::SignalLinkDropped {
road_id,
element,
id,
} => {
let at = match (road_id.is_empty(), element.as_str()) {
(false, _) => format!("road {road_id:?}"),
(true, "vmsBoardReference") => "a <vmsGroup>".to_string(),
(true, "controller") => "a junction".to_string(),
(true, _) => "a controller".to_string(),
};
write!(f, "{at}: <{element}> to {id:?} names nothing the load baked, dropped")
}
Self::CrgDropped {
road_id,
junction_id,
file,
} => write!(
f,
"{}: <CRG> {file:?} has no file, stretch, mode or purpose the crate can lay, dropped",
place(road_id, junction_id)
),
Self::ObjectDropped {
road_id,
junction_id,
object_id,
} => write!(
f,
"{}: object {object_id:?} has no readable s or t, or names no object, dropped",
place(road_id, junction_id)
),
Self::RepeatDropped {
road_id,
junction_id,
object_id,
} => write!(
f,
"{}: object {object_id:?} has a <repeat> it can't read, dropped",
place(road_id, junction_id)
),
Self::MarkingDropped {
road_id,
junction_id,
object_id,
} => write!(
f,
"{}: object {object_id:?} has a <marking> it can't paint, dropped",
place(road_id, junction_id)
),
Self::StructureDropped {
road_id,
structure_id,
} => write!(
f,
"road {road_id:?}: tunnel or bridge {structure_id:?} has no readable s or length, dropped"
),
Self::LaneSectionDropped {
road_id,
section,
s,
} => write!(
f,
"road {road_id:?}: lane section {section} at s {s:.3} m starts past the road's end, dropped"
),
Self::RecordDropped {
road_id,
record,
section,
lane,
s,
attribute,
} => write!(
f,
"{}: <{record}>{} dropped, it has no readable {attribute}",
record_place(road_id, *section, *lane),
at_s(*s)
),
Self::RecordValueUnreadable {
road_id,
record,
section,
lane,
s,
attribute,
} => write!(
f,
"{}: <{record}>{} has a {attribute} that is not a number, read as 0",
record_place(road_id, *section, *lane),
at_s(*s)
),
Self::RecordsOutOfOrder {
road_id,
record,
section,
lane,
} => write!(
f,
"{}: <{record}> records out of order, sorted",
record_place(road_id, *section, *lane)
),
}
}
}
/// One end of a road: where its `<predecessor>` or its `<successor>` joins
/// it.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum RoadEnd {
/// Where `s` is 0, and the `<predecessor>` joins.
Start,
/// Where `s` is the road's length, and the `<successor>` joins.
End,
}
impl fmt::Display for RoadEnd {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(match self {
Self::Start => "start",
Self::End => "end",
})
}
}
impl fmt::Display for RoadSkipReason {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(match self {
Self::NoLength => "no finite length above zero",
Self::NoPlanView => "no <planView>",
Self::NoGeometry => "no <geometry> it can bake",
Self::TooLong => "a length over 100 km",
Self::OutOfRange => "lanes too far out for an f32",
Self::MapTooLarge => "lanes past the 2,000 km one file may bake",
})
}
}
/// A speed limit in km/h, or `no limit`.
fn limit_text(limit: SpeedLimit) -> String {
match limit {
SpeedLimit::Max(v) => format!("{:.0} km/h", f64::from(v) * 3.6),
SpeedLimit::Unlimited => "no limit".into(),
}
}
/// Where a record is, for a warning: its road, and for a record of a lane,
/// its lane section and lane.
fn record_place(road_id: &str, section: Option<usize>, lane: Option<i32>) -> String {
match (section, lane) {
(Some(section), Some(lane)) => {
format!("road {road_id:?}, lane section {section}, lane {lane}")
}
_ => format!("road {road_id:?}"),
}
}
/// ` at s {s} m`, or nothing for a record whose start the crate can't read.
fn at_s(s: Option<f64>) -> String {
s.map_or_else(String::new, |s| format!(" at s {s:.2} m"))
}
/// Where an object is, for a warning: its road, or its junction.
fn place(road_id: &str, junction_id: &str) -> String {
if junction_id.is_empty() {
format!("road {road_id:?}")
} else {
format!("junction {junction_id:?}")
}
}