use std::borrow::Cow;
use uom::si::f64::Length;
use uom::si::length::meter;
#[derive(Debug, Clone, PartialEq)]
pub struct CornerLocal {
pub height: Length,
pub id: Option<u64>,
pub u: Length,
pub v: Length,
pub z: Length,
}
impl CornerLocal {
pub fn visit_attributes(
&self,
visitor: impl for<'b> FnOnce(
Cow<'b, [xml::attribute::Attribute<'b>]>,
) -> xml::writer::Result<()>,
) -> xml::writer::Result<()> {
visit_attributes_flatten!(
visitor,
"height" => Some(self.height.value.to_scientific_string()).as_deref(),
"id" => self.id.map(|v| v.to_string()).as_deref(),
"u" => Some(self.u.value.to_scientific_string()).as_deref(),
"v" => Some(self.v.value.to_scientific_string()).as_deref(),
"z" => Some(self.z.value.to_scientific_string()).as_deref(),
)
}
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 CornerLocal
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 {
height: read.attribute("height").map(Length::new::<meter>)?,
id: read.attribute_opt("id")?,
u: read.attribute("u").map(Length::new::<meter>)?,
v: read.attribute("v").map(Length::new::<meter>)?,
z: read.attribute("z").map(Length::new::<meter>)?,
})
}
}
#[cfg(feature = "fuzzing")]
impl arbitrary::Arbitrary<'_> for CornerLocal {
fn arbitrary(u: &mut arbitrary::Unstructured) -> arbitrary::Result<Self> {
use crate::fuzzing::NotNan;
Ok(Self {
height: Length::new::<meter>(u.not_nan_f64()?),
id: u.arbitrary()?,
u: Length::new::<meter>(u.not_nan_f64()?),
v: Length::new::<meter>(u.not_nan_f64()?),
z: Length::new::<meter>(u.not_nan_f64()?),
})
}
}