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
use super::*;
impl<T> ToSVG for Point<T>
where
T: Display + One + Clone,
{
fn to_svg(&self) -> SVG {
Circle::from(self).to_svg()
}
}
impl<T> ToSVG for Triangle<T>
where
T: Display + Clone,
{
fn to_svg(&self) -> SVG {
Polygon::from(self).to_svg()
}
}
impl<T> ToSVG for Square<T>
where
T: Display,
{
fn to_svg(&self) -> SVG {
let attributes = vec![
("x", format!("{}", self.anchor.x)),
("y", format!("{}", self.anchor.y)),
("width", format!("{}", self.side)),
("height", format!("{}", self.side)),
];
SVG::new("rect", attributes, vec![])
}
}
impl<T> ToSVG for Rectangle<T>
where
T: Display,
{
fn to_svg(&self) -> SVG {
let attributes = vec![
("x", format!("{}", self.anchor.x)),
("y", format!("{}", self.anchor.y)),
("width", format!("{}", self.side.0)),
("height", format!("{}", self.side.1)),
];
SVG::new("rect", attributes, vec![])
}
}
impl<T> ToSVG for Parallelogram<T>
where
T: Display,
{
fn to_svg(&self) -> SVG {
todo!()
}
}
impl<T> ToSVG for Polyline<T> {
fn to_svg(&self) -> SVG {
todo!()
}
}
impl<T> ToSVG for RegularPolygon<T> {
fn to_svg(&self) -> SVG {
todo!()
}
}
impl<T> ToSVG for Polygon<T>
where
T: Display,
{
fn to_svg(&self) -> SVG {
let points = self.vertex.iter().map(|p| format!("{},{}", p.x, p.y)).collect::<Vec<_>>().join(" ");
let attributes = vec![("points", points)];
SVG::new("polygon", attributes, vec![])
}
}