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
use svg_definitions::prelude::*;
pub fn circle(radius: i32) -> SVGElem {
SVGElem::new(Tag::Circle)
.set(Attr::R, radius)
.set(Attr::Stroke, "#000000")
.set(Attr::StrokeWidth, 1)
.set(Attr::Fill, "transparent")
.set(Attr::Cx, 0)
.set(Attr::Cy, 0)
}
pub fn rect(width: i32, height: i32) -> SVGElem {
SVGElem::new(Tag::Rect)
.set(Attr::Width, width)
.set(Attr::Height, height)
.set(Attr::Stroke, "#000000")
.set(Attr::StrokeWidth, 1)
.set(Attr::Fill, "transparent")
}
pub fn curve(
sx: i32,
sy: i32,
ex: i32,
ey: i32,
cx1: i32,
cy1: i32,
cx2: i32,
cy2: i32,
) -> SVGElem {
SVGElem::new(Tag::Path).set(
Attr::D,
PathData::new().move_to(as_point_2d((sx, sy))).curve_to(
as_point_2d((ex, ey)),
as_point_2d((cx1, cy1)),
as_point_2d((cx2, cy2)),
),
)
}
pub fn polygon(points: Vec<(i32, i32)>) -> SVGElem {
let mut path_string = PathData::new().move_to(as_point_2d(points[0]));
points[1..]
.iter()
.for_each(|point| path_string = path_string.clone().line_to(as_point_2d(*point)));
SVGElem::new(Tag::Path)
.set(Attr::D, path_string)
.set(Attr::StrokeWidth, 1)
.set(Attr::Stroke, "#000000")
}
pub fn set_loc(elem: SVGElem, x: i32, y: i32) -> SVGElem {
elem.set(Attr::X, x).set(Attr::Y, y)
}
pub fn set_circle_loc(elem: SVGElem, x: i32, y: i32) -> SVGElem {
elem.set(Attr::Cx, x).set(Attr::Cy, y)
}
fn as_point_2d(point: (i32, i32)) -> Point2D {
(point.0 as f32, point.1 as f32)
}