aboutsummaryrefslogtreecommitdiff
path: root/core/math/geometry.cpp
diff options
context:
space:
mode:
authorBernhard Liebl2017-12-27 09:28:02 +0100
committerBernhard Liebl2017-12-27 20:24:58 +0100
commit8505871a87b59b27acc0912a6dd815231c3b78b1 (patch)
tree31a4fdc7afe2cd3960380fa7695d508f54c043a2 /core/math/geometry.cpp
parent32d8b99bc31e3762ae0dc017a05567da2802a313 (diff)
downloadgodot-8505871a87b59b27acc0912a6dd815231c3b78b1.tar.gz
godot-8505871a87b59b27acc0912a6dd815231c3b78b1.tar.zst
godot-8505871a87b59b27acc0912a6dd815231c3b78b1.zip
More exact picking for canvas editor
Diffstat (limited to 'core/math/geometry.cpp')
-rw-r--r--core/math/geometry.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/core/math/geometry.cpp b/core/math/geometry.cpp
index 39bd34f03..e1f2f91eb 100644
--- a/core/math/geometry.cpp
+++ b/core/math/geometry.cpp
@@ -30,6 +30,17 @@
#include "geometry.h"
#include "print_string.h"
+bool Geometry::is_point_in_polygon(const Vector2 &p_point, const Vector<Vector2> &p_polygon) {
+
+ Vector<int> indices = Geometry::triangulate_polygon(p_polygon);
+ for (int j = 0; j + 3 <= indices.size(); j += 3) {
+ int i1 = indices[j], i2 = indices[j + 1], i3 = indices[j + 2];
+ if (Geometry::is_point_in_triangle(p_point, p_polygon[i1], p_polygon[i2], p_polygon[i3]))
+ return true;
+ }
+ return false;
+}
+
void Geometry::MeshData::optimize_vertices() {
Map<int, int> vtx_remap;