diff -r 5d280bceb713 -r d891da20abca src/layers/edittools.cpp --- a/src/layers/edittools.cpp Tue Jun 28 22:18:11 2022 +0300 +++ b/src/layers/edittools.cpp Wed Jun 29 14:11:58 2022 +0300 @@ -141,7 +141,19 @@ painter->drawPolygon(QPolygonF{convertWorldPointsToScreenPoints(points, renderer)}); } -static std::vector> modelActionPoints(const ModelAction& action) +//! \brief Conversion function from PlainPolygonElement to ModelElement +ModelElement elementFromPolygonAndColor(const PlainPolygonElement& poly, ColorIndex color) +{ + // use std::visit with a templated lambda to resolve the type of poly. + return std::visit([color](const auto& resolvedPoly) -> ModelElement { + // unlike with normal templates we need to pry out the type out manually + using PolygonType = std::decay_t; + // add color and return as a model element. + return Colored{resolvedPoly, color}; + }, poly); +} + +static std::vector> polygonsToBeInserted(const ModelAction& action) { std::vector> result; if (const AppendToModel* append = std::get_if(&action)) { @@ -156,8 +168,10 @@ result.push_back({quad->p1, quad->p2, quad->p3, quad->p4}); } else if (const CircularPrimitive* circ = std::get_if>(&newElement)) { - rasterize(*circ, [&](const ModelElement& element){ - const auto& subpoints = modelActionPoints(AppendToModel{element}); + // rasterize the circle down to polygons, and append them to the result. + rasterize(*circ, [&](const PlainPolygonElement& poly, const ColorIndex color){ + AppendToModel append{elementFromPolygonAndColor(poly, color)}; + const auto& subpoints = polygonsToBeInserted(append); std::copy(subpoints.begin(), subpoints.end(), std::back_inserter(result)); }); } @@ -232,7 +246,7 @@ const Pens& pens = *reinterpret_cast(pensptr); painter->setPen(pens.polygonPen); for (const ModelAction& action : this->modelActions()) { - for (const std::vector& points : modelActionPoints(action)) { + for (const std::vector& points : polygonsToBeInserted(action)) { if (points.size() == 2) { drawWorldPolyline(painter, points, renderer); }