random_icon_lib/svg/
mod.rs1pub mod index;
2pub mod shape_data;
3#[cfg(test)]
4mod tests;
5
6use std::io::{self, Write};
7
8use crate::fields::Fields;
9
10impl Fields {
11 pub fn write_as_svg<T: Write>(self, target: T) -> Result<(), io::Error> {
12 let mut document = svg::Document::new()
13 .set("viewBox", (-50, -50, 100, 100))
14 .set("fill", "black");
15
16 for (field_shape, degrees, orientation) in self.active_field_shapes_with_rotation() {
17 let mut transform_string = format!("rotate({}, 0, 0)", degrees);
18 if orientation == Orientation::Mirrored {
19 transform_string.push_str(" scale(-1,1)");
20 }
21 let path_element = svg::node::element::Path::new()
22 .set("d", field_shape.field_border_path_data().path_data)
23 .set("transform", transform_string);
24
25 document = document.add(path_element)
26 }
27 svg::write(target, &document)
28 }
29}
30
31pub enum FieldShape {
32 SectorInner,
33 SectorInnerMid,
34 SectorOuterMid,
35 SectorOuter,
36 SectorDividerInner,
37 SectorDividerMid,
38 SectorDividerOuter,
39 CenterField,
40}
41
42#[derive(Debug, Clone, Copy, PartialEq, Eq)]
43enum Orientation {
44 Original,
45 Mirrored,
46}
47
48pub struct FieldBorder {
49 path_data: svg::node::element::path::Data,
50}