diff -r 000781318c36 -r b54b350dff5d src/geometry.cpp --- a/src/geometry.cpp Fri Jul 30 01:28:39 2021 +0300 +++ b/src/geometry.cpp Fri Aug 27 00:55:32 2021 +0300 @@ -1,5 +1,7 @@ #include #include "geometry.h" +#include "ring.h" +#include "maths.h" /** * @brief Computes line-plane intersection @@ -196,3 +198,24 @@ glm::vec2{rectangle.right(), rectangle.bottom()} }; } + +bool geom::convex(const std::vector& polygon) +{ + const int n = polygon.size(); + auto polygonRing = iter::ring(polygon, n); + std::vector crosses; + crosses.resize(n); + for (int i = 0; i < n; i += 1) + { + 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 false; + } + } + return true; +}