diff --git a/src/SVGRenderer.hpp b/src/SVGRenderer.hpp index 45af4dd..a7a564f 100644 --- a/src/SVGRenderer.hpp +++ b/src/SVGRenderer.hpp @@ -2,14 +2,20 @@ #include #include +#include #include "Renderer.hpp" namespace massivedynamic { class SVGRenderer : public Renderer { + private: + constexpr static float BORDER_WIDTH = 0.1f; public: - SVGRenderer(const std::vector& pixels, size_t sourceSize, size_t targetSize) : Renderer(pixels, sourceSize, targetSize) {} + SVGRenderer(const std::vector& pixels, size_t sourceSize, size_t targetSize) : Renderer(pixels, sourceSize, targetSize) { + if (this->targetSize == 0) + this->targetSize = sourceSize * (2 * SVGRenderer::BORDER_WIDTH); + } virtual void render(const std::string& filename) override { std::stringstream file; @@ -20,15 +26,15 @@ namespace massivedynamic { file << base; file << "viewBox=\"0 0 " << this->targetSize << " " << this->targetSize << "\" xml:space=\"preserve\">" << '\n'; file << " targetSize << "\" height=\"" << this->targetSize << "\" style=\"fill: white;\" />" << '\n'; - size_t pixelSize = this->targetSize / (this->sourceSize + 2); + float pixelSize = static_cast(this->targetSize) / static_cast(this->sourceSize + 2); for (size_t y = 0; y < this->sourceSize; y++) { for (size_t x = 0; x < this->sourceSize; x++) { if (!this->pixels.at(y * this->sourceSize + x)) continue; - size_t rectX = x * pixelSize + pixelSize; - size_t rectY = y * pixelSize + pixelSize; - file << " " << '\n'; + float rectX = x * pixelSize + pixelSize; + float rectY = y * pixelSize + pixelSize; + file << " " << '\n'; } }