src/geometry.cpp

changeset 123
e3fe3617b631
parent 122
b54b350dff5d
child 168
24590af32ad6
--- 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 <glm/gtc/matrix_transform.hpp>
 #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<glm::vec3>& polygon)
+bool geom::isConvex(const std::vector<glm::vec3>& 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;
+		});
 }

mercurial