# HG changeset patch # User Teemu Piippo # Date 1681125919 -10800 # Node ID b2914aaeec1aab24be918e3757d1cf819f7d9954 # Parent 171d3f9638a982476a71a53d58a6411657ddcd57 Winding is now an enum class winding_e diff -r 171d3f9638a9 -r b2914aaeec1a src/geometry.cpp --- 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; } /** diff -r 171d3f9638a9 -r b2914aaeec1a src/geometry.h --- 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 #include -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(one) ^ static_cast(other); - return static_cast(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& polygon); -Winding winding(const QPolygonF& polygon); +winding_e calculate_polygon_winding(const QPolygonF& polygon); struct unscaled_matrix { glm::vec3 scaling; diff -r 171d3f9638a9 -r b2914aaeec1a src/gl/partrenderer.h --- 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 &points, const PartRenderer* renderer) { - return winding(QPolygonF{convertWorldPointsToScreenPoints(points, renderer)}); + return calculate_polygon_winding(QPolygonF{convertWorldPointsToScreenPoints(points, renderer)}); } inline void drawWorldPoint( diff -r 171d3f9638a9 -r b2914aaeec1a src/layers/edittools.cpp --- 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 { diff -r 171d3f9638a9 -r b2914aaeec1a src/polygoncache.cpp --- 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 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> 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()); } };