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
use std::borrow::Cow;
use uom::si::f64::Length;
use uom::si::length::meter;
/// The width of a lane is defined along the t-coordinate. The width of a lane may change within a
/// lane section.
/// Lane width and lane border elements are mutually exclusive within the same lane group. If both
/// width and lane border elements are present for a lane section in the ASAM OpenDRIVE file, the
/// application must use the information from the `<width>` elements.
/// In ASAM OpenDRIVE, lane width is described by the `<width>` element within the `<lane>` element.
#[derive(Debug, Clone, PartialEq)]
pub struct Width {
/// Polynom parameter a, width at @s (ds=0)
// https://github.com/RReverser/serde-xml-rs/issues/137
pub a: f64,
/// Polynom parameter b
// https://github.com/RReverser/serde-xml-rs/issues/137
pub b: f64,
/// Polynom parameter c
// https://github.com/RReverser/serde-xml-rs/issues/137
pub c: f64,
/// Polynom parameter d
// https://github.com/RReverser/serde-xml-rs/issues/137
pub d: f64,
/// s-coordinate of start position of the `<width>` element, relative to the position of the
/// preceding `<laneSection>` element
// https://github.com/RReverser/serde-xml-rs/issues/137
pub s_offset: Length,
}
impl Width {
pub fn visit_attributes(
&self,
visitor: impl for<'b> FnOnce(
Cow<'b, [xml::attribute::Attribute<'b>]>,
) -> xml::writer::Result<()>,
) -> xml::writer::Result<()> {
visit_attributes!(
visitor,
"a" => &self.a.to_scientific_string(),
"b" => &self.b.to_scientific_string(),
"c" => &self.c.to_scientific_string(),
"d" => &self.d.to_scientific_string(),
"sOffset" => &self.s_offset.value.to_scientific_string(),
)
}
pub fn visit_children(
&self,
mut visitor: impl FnMut(xml::writer::XmlEvent) -> xml::writer::Result<()>,
) -> xml::writer::Result<()> {
visit_children!(visitor);
Ok(())
}
}
impl<'a, I> TryFrom<crate::parser::ReadContext<'a, I>> for Width
where
I: Iterator<Item = xml::reader::Result<xml::reader::XmlEvent>>,
{
type Error = Box<crate::parser::Error>;
fn try_from(mut read: crate::parser::ReadContext<'a, I>) -> Result<Self, Self::Error> {
read.expecting_no_child_elements_for(Self {
a: read.attribute("a")?,
b: read.attribute("b")?,
c: read.attribute("c")?,
d: read.attribute("d")?,
s_offset: read.attribute("sOffset").map(Length::new::<meter>)?,
})
}
}
#[cfg(feature = "fuzzing")]
impl arbitrary::Arbitrary<'_> for Width {
fn arbitrary(u: &mut arbitrary::Unstructured) -> arbitrary::Result<Self> {
use crate::fuzzing::NotNan;
Ok(Self {
a: u.not_nan_f64()?,
b: u.not_nan_f64()?,
c: u.not_nan_f64()?,
d: u.not_nan_f64()?,
s_offset: Length::new::<meter>(u.not_nan_f64()?),
})
}
}