summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2018-01-03 11:15:28 +0100
committerGitHub <noreply@github.com>2018-01-03 11:15:28 +0100
commit459ee51338ff9ffb8248a4351eee3b558438aa50 (patch)
treeb366aad4e6ee15907af75cb659f42b5ec79b6f58 /core
parent0b235a5efa9f6825e638d98d9eaadcc11423b3c3 (diff)
parent8505871a87b59b27acc0912a6dd815231c3b78b1 (diff)
Merge pull request #15093 from poke1024/canvas-editor-select
More exact picking for canvas editor
Diffstat (limited to 'core')
-rw-r--r--core/math/geometry.cpp11
-rw-r--r--core/math/geometry.h3
2 files changed, 14 insertions, 0 deletions
diff --git a/core/math/geometry.cpp b/core/math/geometry.cpp
index b2145eca85..a3b48320b1 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;
diff --git a/core/math/geometry.h b/core/math/geometry.h
index ac1a22289c..fefdd88794 100644
--- a/core/math/geometry.h
+++ b/core/math/geometry.h
@@ -512,6 +512,9 @@ public:
return true;
}
+
+ static bool is_point_in_polygon(const Vector2 &p_point, const Vector<Vector2> &p_polygon);
+
static Vector2 get_closest_point_to_segment_uncapped_2d(const Vector2 &p_point, const Vector2 *p_segment) {
Vector2 p = p_point - p_segment[0];