easyofd_core/model/
path_object.rs1#[derive(Debug, Clone)]
5pub struct PathObject {
6 pub x: f64,
8 pub y: f64,
10 pub stroke_color: u32,
12 pub stroke_width: f64,
14 pub fill_color: Option<u32>,
16 pub path_data: String,
18}
19
20impl PathObject {
21 #[must_use]
23 pub fn new(x: f64, y: f64, path_data: impl Into<String>) -> Self {
24 Self {
25 x,
26 y,
27 stroke_color: 0x000_000,
28 stroke_width: 0.35,
29 fill_color: None,
30 path_data: path_data.into(),
31 }
32 }
33
34 #[must_use]
36 pub fn hline(x1: f64, y: f64, x2: f64) -> Self {
37 Self::new(x1, y, format!("M{x1} {y}L{x2} {y}"))
38 }
39
40 #[must_use]
42 pub fn vline(x: f64, y1: f64, y2: f64) -> Self {
43 Self::new(x, y1, format!("M{x} {y1}L{x} {y2}"))
44 }
45
46 #[must_use]
48 #[allow(clippy::many_single_char_names)]
49 pub fn rect(x: f64, y: f64, w: f64, h: f64) -> Self {
50 let d = format!("M{x} {y}L{} {y}L{} {}L{x} {}Z", x + w, x + w, y + h, y + h);
51 Self::new(x, y, d)
52 }
53
54 #[must_use]
56 pub fn stroke_color(mut self, color: u32) -> Self {
57 self.stroke_color = color;
58 self
59 }
60
61 #[must_use]
63 pub fn stroke_width(mut self, width: f64) -> Self {
64 self.stroke_width = width;
65 self
66 }
67
68 #[must_use]
70 pub fn fill_color(mut self, color: u32) -> Self {
71 self.fill_color = Some(color);
72 self
73 }
74}