Implement basic circle stamping (#53)

This commit is contained in:
T0mstone
2021-03-29 01:44:34 +02:00
committed by GitHub
parent c437f1bd22
commit 94f50377a3
10 changed files with 85 additions and 46 deletions

View File

@@ -1,7 +1,27 @@
#[cfg(test)]
mod tests {
#[test]
fn it_works() {
assert_eq!(2 + 2, 4);
pub use kurbo::{Circle, Point};
#[derive(Debug, Clone, PartialEq)]
pub enum SvgElement {
Circle(Circle),
}
impl SvgElement {
pub fn render(&self) -> String {
match self {
Self::Circle(c) => {
format!(r#"<circle cx="{}" cy="{}" r="{}" style="fill: #fff;" />"#, c.center.x, c.center.y, c.radius)
}
}
}
}
#[derive(Default, Debug, Clone, PartialEq)]
pub struct Document {
pub svg: Vec<SvgElement>,
}
impl Document {
pub fn render(&self) -> String {
self.svg.iter().map(|element| element.render()).collect::<Vec<_>>().join("\n")
}
}