shape_svg/renderer_2d/
polygon_like.rs

1use super::*;
2
3
4impl<T> ToSVG for Point<T>
5where
6    T: Display,
7{
8    type Element = svg::node::element::Circle;
9
10    fn to_svg(&self) -> Self::Element {
11        svg::node::element::Circle::new().set("cx", self.x.to_string()).set("cy", self.y.to_string()).set("r", 1)
12    }
13}
14
15impl<T> ToSVG for Triangle<T>
16where
17    T: Display,
18{
19    type Element = svg::node::element::Polygon;
20
21    fn to_svg(&self) -> Self::Element {
22        let mut points = String::new();
23        points.push_str(&format!("{},{} ", self.a.x, self.a.y));
24        points.push_str(&format!("{},{} ", self.b.x, self.b.y));
25        points.push_str(&format!("{},{} ", self.c.x, self.c.y));
26        svg::node::element::Polygon::new().set("points", points)
27    }
28}
29
30impl<T> ToSVG for Square<T>
31where
32    T: Display,
33{
34    type Element = svg::node::element::Rectangle;
35
36    fn to_svg(&self) -> Self::Element {
37        svg::node::element::Rectangle::new()
38            .set("x", self.x.to_string())
39            .set("y", self.y.to_string())
40            .set("width", self.s.to_string())
41            .set("height", self.s.to_string())
42    }
43}
44
45impl<T> ToSVG for Rectangle<T>
46where
47    T: Display + Clone + Sub<Output = T>,
48{
49    type Element = svg::node::element::Rectangle;
50
51    fn to_svg(&self) -> Self::Element {
52        svg::node::element::Rectangle::new()
53            .set("x", self.min.x.to_string())
54            .set("y", self.min.y.to_string())
55            .set("width", self.width().to_string())
56            .set("height", self.height().to_string())
57    }
58}
59
60impl<T> ToSVG for Parallelogram<T>
61where
62    T: Display,
63{
64    type Element = svg::node::element::Polygon;
65
66    fn to_svg(&self) -> Self::Element {
67        todo!()
68    }
69}
70
71impl<T> ToSVG for Polyline<T> {
72    type Element = svg::node::element::Polyline;
73
74    fn to_svg(&self) -> Self::Element {
75        todo!()
76    }
77}
78
79impl<T> ToSVG for RegularPolygon<T> {
80    type Element = svg::node::element::Polygon;
81
82    fn to_svg(&self) -> Self::Element {
83        todo!()
84    }
85}
86
87impl<T> ToSVG for Polygon<T>
88where
89    T: Display,
90{
91    type Element = svg::node::element::Polygon;
92
93    fn to_svg(&self) -> Self::Element {
94        let mut points = String::new();
95        for Point { x, y } in self.points_set.points.iter() {
96            points.push_str(&format!("{},{} ", x, y));
97        }
98        svg::node::element::Polygon::new().set("points", points)
99    }
100}