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 {
let attributes =
vec![("points", format!("{},{} {},{} {},{}", self.a.x, self.a.y, self.b.x, self.b.y, self.c.x, self.c.y))];
SVG::new("polygon", attributes, vec![])
}
}
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.x)),
("y", format!("{}", self.y)),
("width", format!("{}", self.w)),
("height", format!("{}", self.h)),
];
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.points_set.points.iter().map(|p| format!("{},{}", p.x, p.y)).collect::<Vec<_>>().join(" ");
let attributes = vec![("points", points)];
SVG::new("polygon", attributes, vec![])
}
}