pub use crate::prelude::DstvElement;
use crate::{dstv_element::ParseDstvError, get_f64_from_str, prelude::PartFace};
use std::str::FromStr;
#[derive(Debug)]
pub struct Hole {
pub diameter: f64,
pub depth: f64,
pub x_coord: f64,
pub y_coord: f64,
pub fl_code: PartFace,
}
impl DstvElement for Hole {
fn from_str(line: &str) -> Result<Self, ParseDstvError> {
let mut iter = line.split_whitespace();
let fl_code = PartFace::from_str(iter.next().ok_or(ParseDstvError::new("No Hole Found"))?)?;
let x_coord = get_f64_from_str(iter.next(), "x_coord")?;
let y_coord = get_f64_from_str(iter.next(), "y_coord")?;
let diameter = get_f64_from_str(iter.next(), "diameter")?;
let depth = get_f64_from_str(iter.next(), "depth").unwrap_or_default();
Ok(Self {
diameter,
depth,
x_coord,
y_coord,
fl_code,
})
}
fn to_svg(&self) -> String {
format!(
"<circle cx=\"{}\" cy=\"{}\" r=\"{}\" fill=\"white\" />",
self.x_coord,
self.y_coord,
self.diameter / 2.0
)
}
fn get_index(&self) -> usize {
2
}
fn get_facing(&self) -> &PartFace {
&self.fl_code
}
}