# HG changeset patch # User Teemu Piippo # Date 1630064336 -10800 # Node ID e3fe3617b631cbdbbcaec15e42bcea6ad8104928 # Parent b54b350dff5d79317a473dd81d817da90b52b2b2 refactor diff -r b54b350dff5d -r e3fe3617b631 src/functional.h --- a/src/functional.h Fri Aug 27 00:55:32 2021 +0300 +++ b/src/functional.h Fri Aug 27 14:38:56 2021 +0300 @@ -171,6 +171,7 @@ return false; } + template bool all(T&& container, Fn&& f) { diff -r b54b350dff5d -r e3fe3617b631 src/geometry.cpp --- a/src/geometry.cpp Fri Aug 27 00:55:32 2021 +0300 +++ b/src/geometry.cpp Fri Aug 27 14:38:56 2021 +0300 @@ -1,7 +1,7 @@ #include #include "geometry.h" +#include "main.h" #include "ring.h" -#include "maths.h" /** * @brief Computes line-plane intersection @@ -199,7 +199,7 @@ }; } -bool geom::convex(const std::vector& polygon) +bool geom::isConvex(const std::vector& polygon) { const int n = polygon.size(); auto polygonRing = iter::ring(polygon, n); @@ -209,13 +209,11 @@ { crosses[i] = glm::cross(polygonRing[i - 1] - polygonRing[i], polygonRing[i + 1] - polygonRing[i]); } - for (int i = 0; i < n - 1; i += 1) - { - const float dotp = glm::dot(crosses[0], crosses[i + 1]); - if (dotp < 0 or qFuzzyIsNull(dotp)) + return not std::any_of( + crosses.begin() + 1, + crosses.end(), + [&crosses](const glm::vec3& vector) { - return false; - } - } - return true; + return glm::dot(crosses[0], vector) < 1e-6; + }); } diff -r b54b350dff5d -r e3fe3617b631 src/geometry.h --- a/src/geometry.h Fri Aug 27 00:55:32 2021 +0300 +++ b/src/geometry.h Fri Aug 27 14:38:56 2021 +0300 @@ -93,7 +93,7 @@ LineSegment2D bottom(const QRectF& rectangle); LineSegment2D left(const QRectF& rectangle); LineSegment2D right(const QRectF& rectangle); - bool convex(const std::vector& polygon); + bool isConvex(const std::vector& polygon); struct ScalingExtract { glm::vec3 scaling; diff -r b54b350dff5d -r e3fe3617b631 src/tools/drawtool.cpp --- a/src/tools/drawtool.cpp Fri Aug 27 00:55:32 2021 +0300 +++ b/src/tools/drawtool.cpp Fri Aug 27 14:38:56 2021 +0300 @@ -86,7 +86,7 @@ this->previewPolygon.back() = this->previewPoint; if (this->previewPolygon.size() > 2) { - this->isconcave = not geom::convex(this->previewPolygon); + this->isconcave = not geom::isConvex(this->previewPolygon); } }