Skip to content

Commit f91fcfe

Browse files
committed
Merge pull request xtaci#21 from pierredavidbelanger/fix_empty_result_astar
Always returns start and end nodes when a path is found in astar it makes sense, thanks!
2 parents c061a91 + 8edf1e3 commit f91fcfe

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

include/astar.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ namespace alg {
100100

101101
if(cx == (int)x2 && cy==(int)y2) { // we reached (x2,y2)
102102
// reconstruct path & return
103+
as->num_nodes = 2;
103104
uint32_t tmp = x2*ncol+y2;
104105
while((tmp=came_from[tmp]) != x1*ncol+y1) {
105106
as->num_nodes++;
@@ -109,10 +110,14 @@ namespace alg {
109110

110111
tmp = x2*ncol+y2;
111112
int idx=0;
113+
as->path[idx++] = x2;
114+
as->path[idx++] = y2;
112115
while((tmp=came_from[tmp]) != x1*ncol+y1) {
113116
as->path[idx++] = tmp/ncol;
114117
as->path[idx++] = tmp%ncol;
115118
}
119+
as->path[idx++] = x1;
120+
as->path[idx++] = y1;
116121
return as;
117122
}
118123

0 commit comments

Comments
 (0)