From 6f2233d13a1524ea184c30af066fd65278dcc610 Mon Sep 17 00:00:00 2001 From: "Andrii Doroshenko (Xrayez)" Date: Thu, 27 Jun 2019 00:20:22 +0300 Subject: [PATCH] Bind is_point_in_polygon in Geometry singleton --- core/bind/core_bind.cpp | 6 ++++++ core/bind/core_bind.h | 1 + doc/classes/Geometry.xml | 11 +++++++++++ 3 files changed, 18 insertions(+) diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp index 8a898f3b53a..b6591a49013 100644 --- a/core/bind/core_bind.cpp +++ b/core/bind/core_bind.cpp @@ -1524,6 +1524,11 @@ bool _Geometry::is_polygon_clockwise(const Vector &p_polygon) { return Geometry::is_polygon_clockwise(p_polygon); } +bool _Geometry::is_point_in_polygon(const Point2 &p_point, const Vector &p_polygon) { + + return Geometry::is_point_in_polygon(p_point, p_polygon); +} + Vector _Geometry::triangulate_polygon(const Vector &p_polygon) { return Geometry::triangulate_polygon(p_polygon); @@ -1706,6 +1711,7 @@ void _Geometry::_bind_methods() { ClassDB::bind_method(D_METHOD("point_is_inside_triangle", "point", "a", "b", "c"), &_Geometry::point_is_inside_triangle); ClassDB::bind_method(D_METHOD("is_polygon_clockwise", "polygon"), &_Geometry::is_polygon_clockwise); + ClassDB::bind_method(D_METHOD("is_point_in_polygon", "point", "polygon"), &_Geometry::is_point_in_polygon); ClassDB::bind_method(D_METHOD("triangulate_polygon", "polygon"), &_Geometry::triangulate_polygon); ClassDB::bind_method(D_METHOD("triangulate_delaunay_2d", "points"), &_Geometry::triangulate_delaunay_2d); ClassDB::bind_method(D_METHOD("convex_hull_2d", "points"), &_Geometry::convex_hull_2d); diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h index 7d0c158f51f..2885e7c0e03 100644 --- a/core/bind/core_bind.h +++ b/core/bind/core_bind.h @@ -408,6 +408,7 @@ public: int get_uv84_normal_bit(const Vector3 &p_vector); bool is_polygon_clockwise(const Vector &p_polygon); + bool is_point_in_polygon(const Point2 &p_point, const Vector &p_polygon); Vector triangulate_polygon(const Vector &p_polygon); Vector triangulate_delaunay_2d(const Vector &p_points); Vector convex_hull_2d(const Vector &p_points); diff --git a/doc/classes/Geometry.xml b/doc/classes/Geometry.xml index e2ba3fb7b06..6fb4341b3c7 100644 --- a/doc/classes/Geometry.xml +++ b/doc/classes/Geometry.xml @@ -216,6 +216,17 @@ Intersects [code]polyline[/code] with [code]polygon[/code] and returns an array of intersected polylines. This performs [code]OPERATION_INTERSECTION[/code] between the polyline and the polygon. This operation can be thought of as chopping a line with a closed shape. + + + + + + + + + Returns [code]true[/code] if [code]point[/code] is inside [code]polygon[/code] or if it's located exactly [i]on[/i] polygon's boundary, otherwise returns [code]false[/code]. + +