summaryrefslogtreecommitdiff
path: root/svg.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'svg.cpp')
-rw-r--r--svg.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/svg.cpp b/svg.cpp
new file mode 100644
index 0000000..e855dab
--- /dev/null
+++ b/svg.cpp
@@ -0,0 +1,29 @@
+#include <sstream>
+#include "svg.h"
+
+
+Polygon::Polygon(std::vector<std::array<double, 2>> pts, std::string bg)
+ : pts{move(pts)}, bg{move(bg)}
+{}
+
+std::string Polygon::svg() const {
+ std::ostringstream ss;
+ ss << "<path d=\"";
+ for (size_t i = 0; i < pts.size(); i++) {
+ if (i == 0) ss << 'M'; else ss << 'L';
+ ss << pts[i][0] << ' ' << pts[i][1] << ' ';
+ }
+ ss << "Z\" stroke=\"black\" fill=\"" << bg << "\" stroke-width=\"0.03px\"/>";
+ return ss.str();
+}
+
+Text::Text(double x, double y, double rotation, std::string text)
+ : x{x}, y{y}, rotation{rotation}, text{move(text)}
+{}
+
+std::string Text::svg() const {
+ std::ostringstream ss;
+ ss << "<text x=\"" << x << "\" y=\"" << y - 0.04 << "\" transform=\"rotate(" << rotation << ")\" style=\"font-size:0.3px\" text-anchor=\"middle\" dominant-baseline=\"middle\">";
+ ss << text << "</text>";
+ return ss.str();
+}