refactor

Fri, 27 Aug 2021 14:38:56 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Fri, 27 Aug 2021 14:38:56 +0300
changeset 123
e3fe3617b631
parent 122
b54b350dff5d
child 124
f9f308c8e0c5

refactor

src/functional.h file | annotate | diff | comparison | revisions
src/geometry.cpp file | annotate | diff | comparison | revisions
src/geometry.h file | annotate | diff | comparison | revisions
src/tools/drawtool.cpp file | annotate | diff | comparison | revisions
--- 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<typename T, typename Fn>
 bool all(T&& container, Fn&& f)
 {
--- 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;
+		});
 }
--- 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<glm::vec3>& polygon);
+	bool isConvex(const std::vector<glm::vec3>& polygon);
 	struct ScalingExtract
 	{
 		glm::vec3 scaling;
--- 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);
 	}
 }
 

mercurial