@@ -45,8 +45,6 @@ var astar = {
45
45
// diagonal: boolean specifying whether diagonal moves are allowed
46
46
// closest: boolean specifying whether to return closest node if
47
47
// target is unreachable
48
- // closestHeuristic: heuristic function to use to determine closeness.
49
- // Will use main heuristic if not specified.
50
48
// }
51
49
search : function ( grid , start , end , options ) {
52
50
astar . init ( grid ) ;
@@ -57,14 +55,13 @@ var astar = {
57
55
var costDiagonal = options . costDiagonal || 1 ;
58
56
var costStraight = options . costStraight || 1 ;
59
57
var closest = options . closest || false ;
60
- var closestHeuristic = options . closestHeuristic || heuristic ;
61
58
62
59
var openHeap = astar . heap ( ) ;
63
60
64
61
// set the start node to be the closest if required
65
62
var closestNode = start ;
66
63
if ( closest ) {
67
- start . c = closestHeuristic ( start . pos , end . pos ) ;
64
+ start . h = start . h || heuristic ( start . pos , end . pos , costStraight , costDiagonal ) ;
68
65
}
69
66
70
67
function pathTo ( node ) {
@@ -119,12 +116,9 @@ var astar = {
119
116
neighbor . f = neighbor . g + neighbor . h ;
120
117
121
118
if ( closest ) {
122
- neighbor . c =
123
- ( closestHeuristic === heuristic ) ? neighbor . h : closestHeuristic ( neighbor . pos , end . pos ) ;
124
119
// If the neighbour is closer than the current closestNode or if it's equally close but has
125
120
// 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 ) ) {
128
122
closestNode = neighbor ;
129
123
}
130
124
}
0 commit comments