Skip to content

Commit

Permalink
Add SVG writer for voronoi diagrams
Browse files Browse the repository at this point in the history
  • Loading branch information
casperlamboo committed Nov 20, 2023
1 parent bcfd053 commit 8f4caaf
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions include/utils/SVG.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
#ifndef SVG_H
#define SVG_H

#include <concepts>

#include <boost/polygon/voronoi.hpp>
#include <stdio.h> // for file output

#include "AABB.h"
Expand Down Expand Up @@ -188,6 +191,34 @@ class SVG : NoCopy
*/
void writeCoordinateGrid(const coord_t grid_size = MM2INT(1), const Color color = Color::BLACK, const float stroke_width = 0.1, const float font_size = 10) const;

/*!
* Draws the provided Voronoi diagram.
*
* @tparam T numeric type
* @param voronoi The Voronoi diagram to draw.
* @param color The colour to draw the diagram with.
* @param stroke_width The width of the lines.
*/
template<std::floating_point T>
void writeVoronoiDiagram(const boost::polygon::voronoi_diagram<T>& voronoi_diagram, const Color color = Color::BLACK, const float stroke_width = 0.1) const {
for (const auto& edge: voronoi_diagram.edges())
{
if (!edge.is_finite())
{
continue;
}

const auto& v0 = edge.vertex0();
const auto& v1 = edge.vertex1();

if (v0 == nullptr || v1 == nullptr)
{
continue;
}

writeLine(Point(v0->x(), v0->y()), Point(v1->x(), v1->y()), color, stroke_width);
}
}
};

template<typename... Args>
Expand Down

0 comments on commit 8f4caaf

Please sign in to comment.