diff options
author | DmDerbin <dds9435@gmail.com> | 2017-11-02 22:42:58 +0300 |
---|---|---|
committer | DmDerbin <dds9435@gmail.com> | 2017-11-04 11:21:03 +0300 |
commit | 4c79e58e3fcb4fe1aa81bc5085a8b0f7e7f92673 (patch) | |
tree | b0990bb7004036ab78e8fcc612dca20e2667c19f | |
parent | c880302754352dce1e44bf00bf9b1ac20e71cd1d (diff) |
AStar: implementation of get_point_connections
-rw-r--r-- | core/math/a_star.cpp | 17 | ||||
-rw-r--r-- | core/math/a_star.h | 1 | ||||
-rw-r--r-- | doc/classes/AStar.xml | 22 |
3 files changed, 40 insertions, 0 deletions
diff --git a/core/math/a_star.cpp b/core/math/a_star.cpp index f43af49754..7e26761abf 100644 --- a/core/math/a_star.cpp +++ b/core/math/a_star.cpp @@ -159,6 +159,21 @@ Array AStar::get_points() { return point_list; } +PoolVector<int> AStar::get_point_connections(int p_id) { + + ERR_FAIL_COND_V(!points.has(p_id), PoolVector<int>()); + + PoolVector<int> point_list; + + Point *p = points[p_id]; + + for (int i = 0; i < p->neighbours.size(); i++) { + point_list.push_back(p->neighbours[i]->id); + } + + return point_list; +} + bool AStar::are_points_connected(int p_id, int p_with_id) const { Segment s(p_id, p_with_id); @@ -444,6 +459,8 @@ void AStar::_bind_methods() { ClassDB::bind_method(D_METHOD("has_point", "id"), &AStar::has_point); ClassDB::bind_method(D_METHOD("get_points"), &AStar::get_points); + ClassDB::bind_method(D_METHOD("get_point_connections"), &AStar::get_point_connections); + ClassDB::bind_method(D_METHOD("connect_points", "id", "to_id", "bidirectional"), &AStar::connect_points, DEFVAL(true)); ClassDB::bind_method(D_METHOD("disconnect_points", "id", "to_id"), &AStar::disconnect_points); ClassDB::bind_method(D_METHOD("are_points_connected", "id", "to_id"), &AStar::are_points_connected); diff --git a/core/math/a_star.h b/core/math/a_star.h index 23773e82e2..b7b7e54125 100644 --- a/core/math/a_star.h +++ b/core/math/a_star.h @@ -109,6 +109,7 @@ public: void set_point_weight_scale(int p_id, real_t p_weight_scale); void remove_point(int p_id); bool has_point(int p_id) const; + PoolVector<int> get_point_connections(int p_id); Array get_points(); void connect_points(int p_id, int p_with_id, bool bidirectional = true); diff --git a/doc/classes/AStar.xml b/doc/classes/AStar.xml index baeeddcd1a..10ca3035fb 100644 --- a/doc/classes/AStar.xml +++ b/doc/classes/AStar.xml @@ -243,6 +243,28 @@ Sets the [code]weight_scale[/code] for the point with the given id. </description> </method> + <method name="get_point_connections"> + <return type="PoolIntArray"> + </return> + <argument index="0" name="id" type="int"> + </argument> + <description> + Returns an array with the ids of the points that form the connect with the given point. + [codeblock] + var as = AStar.new() + + as.add_point(1, Vector3(0,0,0)) + as.add_point(2, Vector3(0,1,0)) + as.add_point(3, Vector3(1,1,0)) + as.add_point(4, Vector3(2,0,0)) + + as.connect_points(1, 2, true) + as.connect_points(1, 3, true) + + var neighbors = as.get_point_connections(1) # returns [2, 3] + [/codeblock] + </description> + </method> </methods> <constants> </constants> |