Mon, 10 Apr 2023 14:25:19 +0300
Winding is now an enum class winding_e
src/geometry.cpp | file | annotate | diff | comparison | revisions | |
src/geometry.h | file | annotate | diff | comparison | revisions | |
src/gl/partrenderer.h | file | annotate | diff | comparison | revisions | |
src/layers/edittools.cpp | file | annotate | diff | comparison | revisions | |
src/polygoncache.cpp | file | annotate | diff | comparison | revisions |
--- a/src/geometry.cpp Mon Apr 10 14:21:17 2023 +0300 +++ b/src/geometry.cpp Mon Apr 10 14:25:19 2023 +0300 @@ -244,7 +244,7 @@ * @param polygon * @return winding */ -Winding winding(const QPolygonF &polygon) +winding_e calculate_polygon_winding(const QPolygonF &polygon) { // based on https://stackoverflow.com/a/1165943 double sum = 0.0; @@ -254,7 +254,7 @@ const QPointF& p2 = polygon[(i + 1) % polygon.size()]; sum += (p2.x() - p1.x()) * (p2.y() + p1.y()); } - return (sum < 0) ? Winding::Anticlockwise : Winding::Clockwise; + return (sum < 0) ? winding_e::anticlockwise : winding_e::clockwise; } /**
--- a/src/geometry.h Mon Apr 10 14:21:17 2023 +0300 +++ b/src/geometry.h Mon Apr 10 14:25:19 2023 +0300 @@ -3,30 +3,12 @@ #include <glm/glm.hpp> #include <optional> -enum Winding -{ - NoWinding, - Anticlockwise, - Clockwise, -}; - -//! \brief XOR operator for winding -constexpr Winding operator^(Winding one, Winding other) +enum class winding_e { - if (one == NoWinding or other == NoWinding) { - return NoWinding; - } - else { - const int xored = static_cast<int>(one) ^ static_cast<int>(other); - return static_cast<Winding>(xored); - } -} - -constexpr Winding& operator^=(Winding& one, Winding other) -{ - one = one ^ other; - return one; -} + none, + anticlockwise, + clockwise +}; struct Plane { @@ -141,7 +123,7 @@ enum class convexity_e { concave, convex }; convexity_e quadrilateral_convexity(const Quadrilateral& quad); convexity_e polygon_convexity(const std::vector<glm::vec3>& polygon); -Winding winding(const QPolygonF& polygon); +winding_e calculate_polygon_winding(const QPolygonF& polygon); struct unscaled_matrix { glm::vec3 scaling;
--- a/src/gl/partrenderer.h Mon Apr 10 14:21:17 2023 +0300 +++ b/src/gl/partrenderer.h Mon Apr 10 14:25:19 2023 +0300 @@ -113,11 +113,11 @@ return points2d; } -inline Winding worldPolygonWinding( +inline winding_e worldPolygonWinding( const std::vector<glm::vec3> &points, const PartRenderer* renderer) { - return winding(QPolygonF{convertWorldPointsToScreenPoints(points, renderer)}); + return calculate_polygon_winding(QPolygonF{convertWorldPointsToScreenPoints(points, renderer)}); } inline void drawWorldPoint(
--- a/src/layers/edittools.cpp Mon Apr 10 14:21:17 2023 +0300 +++ b/src/layers/edittools.cpp Mon Apr 10 14:25:19 2023 +0300 @@ -202,7 +202,7 @@ drawWorldPolyline(painter, points, renderer); } else { - if (worldPolygonWinding(points, this->renderer) == Winding::Clockwise) { + if (worldPolygonWinding(points, this->renderer) == winding_e::clockwise) { painter->setBrush(pens.greenPolygonBrush); } else {
--- a/src/polygoncache.cpp Mon Apr 10 14:21:17 2023 +0300 +++ b/src/polygoncache.cpp Mon Apr 10 14:25:19 2023 +0300 @@ -82,7 +82,7 @@ template<typename Fn, typename Fn2> static void collectPolygons( const ParsedLine& element, - Winding& winding, + winding_e& winding, GetPolygonsContext* context, Fn&& add, Fn2&& reserve) @@ -96,13 +96,13 @@ foundinvertnext = true; } else if (text == QStringLiteral("BFC CERTIFY CW")) { - winding = Clockwise; + winding = winding_e::clockwise; } else if (text == QStringLiteral("BFC CERTIFY CCW")) { - winding = Anticlockwise; + winding = winding_e::anticlockwise; } else if (text == QStringLiteral("BFC NOCERTIFY")) { - winding = NoWinding; + winding = winding_e::none; } }, [&](const LineType2& line2) { @@ -147,12 +147,12 @@ const QTextDocument* model, GetPolygonsContext* context) { - Winding winding = NoWinding; + winding_e winding = winding_e::none; std::vector<WithId<PolygonElement>> result; int i = 0; const auto add = [&result, &winding, &i](int lineno, const PolygonElement& poly){ result.push_back({poly, i}); - if (lineno != 1 and winding == Winding::Clockwise) { + if (lineno != 1 and winding == winding_e::clockwise) { gl::invert(result.back()); } };