Skip to content

Commit 67850cc

Browse files
author
MannyC
committed
remove closestHeuristic
1 parent ec6f0bb commit 67850cc

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

astar.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ var astar = {
4545
// diagonal: boolean specifying whether diagonal moves are allowed
4646
// closest: boolean specifying whether to return closest node if
4747
// target is unreachable
48-
// closestHeuristic: heuristic function to use to determine closeness.
49-
// Will use main heuristic if not specified.
5048
// }
5149
search: function(grid, start, end, options) {
5250
astar.init(grid);
@@ -57,14 +55,13 @@ var astar = {
5755
var costDiagonal = options.costDiagonal || 1;
5856
var costStraight = options.costStraight || 1;
5957
var closest = options.closest || false;
60-
var closestHeuristic = options.closestHeuristic || heuristic;
6158

6259
var openHeap = astar.heap();
6360

6461
// set the start node to be the closest if required
6562
var closestNode = start;
6663
if(closest){
67-
start.c = closestHeuristic(start.pos, end.pos);
64+
start.h = start.h || heuristic(start.pos, end.pos, costStraight, costDiagonal);
6865
}
6966

7067
function pathTo( node ){
@@ -119,12 +116,9 @@ var astar = {
119116
neighbor.f = neighbor.g + neighbor.h;
120117

121118
if( closest ){
122-
neighbor.c =
123-
(closestHeuristic === heuristic) ? neighbor.h : closestHeuristic(neighbor.pos, end.pos);
124119
// If the neighbour is closer than the current closestNode or if it's equally close but has
125120
// a cheaper path than the current closest node then it becomes the closest node
126-
if(neighbor.c < closestNode.c || (neighbor.c === closestNode.c && neighbor.g < closestNode.g)){
127-
121+
if(neighbor.h < closestNode.h || (neighbor.h === closestNode.h && neighbor.g < closestNode.g)){
128122
closestNode = neighbor;
129123
}
130124
}

0 commit comments

Comments
 (0)