#[derive(Debug, Clone)]
pub struct PathObject {
pub x: f64,
pub y: f64,
pub stroke_color: u32,
pub stroke_width: f64,
pub fill_color: Option<u32>,
pub path_data: String,
}
impl PathObject {
#[must_use]
pub fn new(x: f64, y: f64, path_data: impl Into<String>) -> Self {
Self {
x,
y,
stroke_color: 0x000_000,
stroke_width: 0.35,
fill_color: None,
path_data: path_data.into(),
}
}
#[must_use]
pub fn hline(x1: f64, y: f64, x2: f64) -> Self {
Self::new(x1, y, format!("M{x1} {y}L{x2} {y}"))
}
#[must_use]
pub fn vline(x: f64, y1: f64, y2: f64) -> Self {
Self::new(x, y1, format!("M{x} {y1}L{x} {y2}"))
}
#[must_use]
#[allow(clippy::many_single_char_names)]
pub fn rect(x: f64, y: f64, w: f64, h: f64) -> Self {
let d = format!("M{x} {y}L{} {y}L{} {}L{x} {}Z", x + w, x + w, y + h, y + h);
Self::new(x, y, d)
}
#[must_use]
pub fn stroke_color(mut self, color: u32) -> Self {
self.stroke_color = color;
self
}
#[must_use]
pub fn stroke_width(mut self, width: f64) -> Self {
self.stroke_width = width;
self
}
#[must_use]
pub fn fill_color(mut self, color: u32) -> Self {
self.fill_color = Some(color);
self
}
}