Skip to content

Commit

Permalink
Merge pull request #32249 from hbina/a_star_ignore_disabled
Browse files Browse the repository at this point in the history
Add option to consider disable points
  • Loading branch information
akien-mga authored Sep 27, 2019
2 parents d0e45e7 + 7b3790d commit 7a67ae0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions core/math/a_star.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,14 +257,14 @@ void AStar::reserve_space(int p_num_nodes) {
points.reserve(p_num_nodes);
}

int AStar::get_closest_point(const Vector3 &p_point) const {
int AStar::get_closest_point(const Vector3 &p_point, bool p_include_disabled) const {

int closest_id = -1;
real_t closest_dist = 1e20;

for (OAHashMap<int, Point *>::Iterator it = points.iter(); it.valid; it = points.next_iter(it)) {

if (!(*it.value)->enabled) continue; // Disabled points should not be considered.
if (!p_include_disabled && !(*it.value)->enabled) continue; // Disabled points should not be considered.

real_t d = p_point.distance_squared_to((*it.value)->pos);
if (closest_id < 0 || d < closest_dist) {
Expand Down Expand Up @@ -540,7 +540,7 @@ void AStar::_bind_methods() {
ClassDB::bind_method(D_METHOD("reserve_space", "num_nodes"), &AStar::reserve_space);
ClassDB::bind_method(D_METHOD("clear"), &AStar::clear);

ClassDB::bind_method(D_METHOD("get_closest_point", "to_position"), &AStar::get_closest_point);
ClassDB::bind_method(D_METHOD("get_closest_point", "to_position", "include_disabled"), &AStar::get_closest_point, DEFVAL(false));
ClassDB::bind_method(D_METHOD("get_closest_position_in_segment", "to_position"), &AStar::get_closest_position_in_segment);

ClassDB::bind_method(D_METHOD("get_point_path", "from_id", "to_id"), &AStar::get_point_path);
Expand Down Expand Up @@ -638,8 +638,8 @@ void AStar2D::reserve_space(int p_num_nodes) {
astar.reserve_space(p_num_nodes);
}

int AStar2D::get_closest_point(const Vector2 &p_point) const {
return astar.get_closest_point(Vector3(p_point.x, p_point.y, 0));
int AStar2D::get_closest_point(const Vector2 &p_point, bool p_include_disabled) const {
return astar.get_closest_point(Vector3(p_point.x, p_point.y, 0), p_include_disabled);
}

Vector2 AStar2D::get_closest_position_in_segment(const Vector2 &p_point) const {
Expand Down Expand Up @@ -693,7 +693,7 @@ void AStar2D::_bind_methods() {
ClassDB::bind_method(D_METHOD("reserve_space", "num_nodes"), &AStar2D::reserve_space);
ClassDB::bind_method(D_METHOD("clear"), &AStar2D::clear);

ClassDB::bind_method(D_METHOD("get_closest_point", "to_position"), &AStar2D::get_closest_point);
ClassDB::bind_method(D_METHOD("get_closest_point", "to_position", "include_disabled"), &AStar2D::get_closest_point, DEFVAL(false));
ClassDB::bind_method(D_METHOD("get_closest_position_in_segment", "to_position"), &AStar2D::get_closest_position_in_segment);

ClassDB::bind_method(D_METHOD("get_point_path", "from_id", "to_id"), &AStar2D::get_point_path);
Expand Down
4 changes: 2 additions & 2 deletions core/math/a_star.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class AStar : public Reference {
void reserve_space(int p_num_nodes);
void clear();

int get_closest_point(const Vector3 &p_point) const;
int get_closest_point(const Vector3 &p_point, bool p_include_disabled = false) const;
Vector3 get_closest_position_in_segment(const Vector3 &p_point) const;

PoolVector<Vector3> get_point_path(int p_from_id, int p_to_id);
Expand Down Expand Up @@ -183,7 +183,7 @@ class AStar2D : public Reference {
void reserve_space(int p_num_nodes);
void clear();

int get_closest_point(const Vector2 &p_point) const;
int get_closest_point(const Vector2 &p_point, bool p_include_disabled = false) const;
Vector2 get_closest_position_in_segment(const Vector2 &p_point) const;

PoolVector<Vector2> get_point_path(int p_from_id, int p_to_id);
Expand Down

0 comments on commit 7a67ae0

Please sign in to comment.