1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
use super::*;

impl<T> ToSVG for Point<T>
where
    T: Display,
{
    type Element = svg::node::element::Circle;

    fn to_svg(&self) -> Self::Element {
        svg::node::element::Circle::new().set("cx", self.x.to_string()).set("cy", self.y.to_string()).set("r", 1)
    }
}

impl<T> ToSVG for Triangle<T>
where
    T: Display,
{
    type Element = svg::node::element::Polygon;

    fn to_svg(&self) -> Self::Element {
        let mut points = String::new();
        points.push_str(&format!("{},{} ", self.a.x, self.a.y));
        points.push_str(&format!("{},{} ", self.b.x, self.b.y));
        points.push_str(&format!("{},{} ", self.c.x, self.c.y));
        svg::node::element::Polygon::new().set("points", points)
    }
}

impl<T> ToSVG for Square<T>
where
    T: Display,
{
    type Element = svg::node::element::Rectangle;

    fn to_svg(&self) -> Self::Element {
        svg::node::element::Rectangle::new()
            .set("x", self.x.to_string())
            .set("y", self.y.to_string())
            .set("width", self.s.to_string())
            .set("height", self.s.to_string())
    }
}

impl<T> ToSVG for Rectangle<T>
where
    T: Display,
{
    type Element = svg::node::element::Rectangle;

    fn to_svg(&self) -> Self::Element {
        svg::node::element::Rectangle::new()
            .set("x", self.x.to_string())
            .set("y", self.y.to_string())
            .set("width", self.w.to_string())
            .set("height", self.h.to_string())
    }
}

impl<T> ToSVG for Parallelogram<T>
where
    T: Display,
{
    type Element = svg::node::element::Polygon;

    fn to_svg(&self) -> Self::Element {
        todo!()
    }
}

impl<T> ToSVG for Polyline<T> {
    type Element = svg::node::element::Polyline;

    fn to_svg(&self) -> Self::Element {
        todo!()
    }
}

impl<T> ToSVG for RegularPolygon<T> {
    type Element = svg::node::element::Polygon;

    fn to_svg(&self) -> Self::Element {
        todo!()
    }
}

impl<T> ToSVG for Polygon<T>
where
    T: Display,
{
    type Element = svg::node::element::Polygon;

    fn to_svg(&self) -> Self::Element {
        let mut points = String::new();
        for Point { x, y } in self.points_set.points.iter() {
            points.push_str(&format!("{},{} ", x, y));
        }
        svg::node::element::Polygon::new().set("points", points)
    }
}