diff options
author | Yuri Rubinsky <chaosus89@gmail.com> | 2022-12-20 23:21:38 +0300 |
---|---|---|
committer | Yuri Rubinsky <chaosus89@gmail.com> | 2022-12-20 23:21:38 +0300 |
commit | 0bcbf8e00d2cc9febe1977aca560897553b141de (patch) | |
tree | 75bb4609d07e52655dfa53097cb97e84c856ae2d /core | |
parent | 2a04b18d37de6c6e621db5a9dfd1cd0da5ccb015 (diff) |
Add `get_point_position` method to `AStarGrid2D`
Diffstat (limited to 'core')
-rw-r--r-- | core/math/a_star_grid_2d.cpp | 7 | ||||
-rw-r--r-- | core/math/a_star_grid_2d.h | 1 |
2 files changed, 8 insertions, 0 deletions
diff --git a/core/math/a_star_grid_2d.cpp b/core/math/a_star_grid_2d.cpp index 8befda28e4..968102e323 100644 --- a/core/math/a_star_grid_2d.cpp +++ b/core/math/a_star_grid_2d.cpp @@ -463,6 +463,12 @@ void AStarGrid2D::clear() { size = Vector2i(); } +Vector2 AStarGrid2D::get_point_position(const Vector2i &p_id) const { + ERR_FAIL_COND_V_MSG(dirty, Vector2(), "Grid is not initialized. Call the update method."); + ERR_FAIL_COND_V_MSG(!is_in_boundsv(p_id), Vector2(), vformat("Can't get point's position. Point out of bounds (%s/%s, %s/%s).", p_id.x, size.width, p_id.y, size.height)); + return points[p_id.y][p_id.x].pos; +} + Vector<Vector2> AStarGrid2D::get_point_path(const Vector2i &p_from_id, const Vector2i &p_to_id) { ERR_FAIL_COND_V_MSG(dirty, Vector<Vector2>(), "Grid is not initialized. Call the update method."); ERR_FAIL_COND_V_MSG(!is_in_boundsv(p_from_id), Vector<Vector2>(), vformat("Can't get id path. Point out of bounds (%s/%s, %s/%s)", p_from_id.x, size.width, p_from_id.y, size.height)); @@ -580,6 +586,7 @@ void AStarGrid2D::_bind_methods() { ClassDB::bind_method(D_METHOD("get_point_weight_scale", "id"), &AStarGrid2D::get_point_weight_scale); ClassDB::bind_method(D_METHOD("clear"), &AStarGrid2D::clear); + ClassDB::bind_method(D_METHOD("get_point_position", "id"), &AStarGrid2D::get_point_position); ClassDB::bind_method(D_METHOD("get_point_path", "from_id", "to_id"), &AStarGrid2D::get_point_path); ClassDB::bind_method(D_METHOD("get_id_path", "from_id", "to_id"), &AStarGrid2D::get_id_path); diff --git a/core/math/a_star_grid_2d.h b/core/math/a_star_grid_2d.h index 2b81f47e12..3b39d46a20 100644 --- a/core/math/a_star_grid_2d.h +++ b/core/math/a_star_grid_2d.h @@ -172,6 +172,7 @@ public: void clear(); + Vector2 get_point_position(const Vector2i &p_id) const; Vector<Vector2> get_point_path(const Vector2i &p_from, const Vector2i &p_to); TypedArray<Vector2i> get_id_path(const Vector2i &p_from, const Vector2i &p_to); }; |