1919} ) ( function ( ) {
2020
2121function pathTo ( node ) {
22- var curr = node ,
23- path = [ ] ;
22+ var curr = node ;
23+ var path = [ ] ;
2424 while ( curr . parent ) {
2525 path . unshift ( curr ) ;
2626 curr = curr . parent ;
@@ -49,11 +49,11 @@ var astar = {
4949 search : function ( graph , start , end , options ) {
5050 graph . cleanDirty ( ) ;
5151 options = options || { } ;
52- var heuristic = options . heuristic || astar . heuristics . manhattan ,
53- closest = options . closest || false ;
52+ var heuristic = options . heuristic || astar . heuristics . manhattan ;
53+ var closest = options . closest || false ;
5454
55- var openHeap = getHeap ( ) ,
56- closestNode = start ; // set the start node to be the closest if required
55+ var openHeap = getHeap ( ) ;
56+ var closestNode = start ; // set the start node to be the closest if required
5757
5858 start . h = heuristic ( start , end ) ;
5959 graph . markDirty ( start ) ;
@@ -86,8 +86,8 @@ var astar = {
8686
8787 // The g score is the shortest distance from start to current node.
8888 // We need to check if the path we have arrived at this neighbor is the shortest one we have seen yet.
89- var gScore = currentNode . g + neighbor . getCost ( currentNode ) ,
90- beenVisited = neighbor . visited ;
89+ var gScore = currentNode . g + neighbor . getCost ( currentNode ) ;
90+ var beenVisited = neighbor . visited ;
9191
9292 if ( ! beenVisited || gScore < neighbor . g ) {
9393
@@ -192,10 +192,10 @@ Graph.prototype.markDirty = function(node) {
192192} ;
193193
194194Graph . prototype . neighbors = function ( node ) {
195- var ret = [ ] ,
196- x = node . x ,
197- y = node . y ,
198- grid = this . grid ;
195+ var ret = [ ] ;
196+ var x = node . x ;
197+ var y = node . y ;
198+ var grid = this . grid ;
199199
200200 // West
201201 if ( grid [ x - 1 ] && grid [ x - 1 ] [ y ] ) {
@@ -243,13 +243,12 @@ Graph.prototype.neighbors = function(node) {
243243} ;
244244
245245Graph . prototype . toString = function ( ) {
246- var graphString = [ ] ,
247- nodes = this . grid , // when using grid
248- rowDebug , row , y , l ;
249- for ( var x = 0 , len = nodes . length ; x < len ; x ++ ) {
250- rowDebug = [ ] ;
251- row = nodes [ x ] ;
252- for ( y = 0 , l = row . length ; y < l ; y ++ ) {
246+ var graphString = [ ] ;
247+ var nodes = this . grid ;
248+ for ( var x = 0 ; x < nodes . length ; x ++ ) {
249+ var rowDebug = [ ] ;
250+ var row = nodes [ x ] ;
251+ for ( var y = 0 ; y < row . length ; y ++ ) {
253252 rowDebug . push ( row [ y ] . weight ) ;
254253 }
255254 graphString . push ( rowDebug . join ( " " ) ) ;
@@ -337,8 +336,8 @@ BinaryHeap.prototype = {
337336 while ( n > 0 ) {
338337
339338 // Compute the parent element's index, and fetch it.
340- var parentN = ( ( n + 1 ) >> 1 ) - 1 ,
341- parent = this . content [ parentN ] ;
339+ var parentN = ( ( n + 1 ) >> 1 ) - 1 ;
340+ var parent = this . content [ parentN ] ;
342341 // Swap the elements if the parent is greater.
343342 if ( this . scoreFunction ( element ) < this . scoreFunction ( parent ) ) {
344343 this . content [ parentN ] = element ;
@@ -354,17 +353,17 @@ BinaryHeap.prototype = {
354353 } ,
355354 bubbleUp : function ( n ) {
356355 // Look up the target element and its score.
357- var length = this . content . length ,
358- element = this . content [ n ] ,
359- elemScore = this . scoreFunction ( element ) ;
356+ var length = this . content . length ;
357+ var element = this . content [ n ] ;
358+ var elemScore = this . scoreFunction ( element ) ;
360359
361360 while ( true ) {
362361 // Compute the indices of the child elements.
363- var child2N = ( n + 1 ) << 1 ,
364- child1N = child2N - 1 ;
362+ var child2N = ( n + 1 ) << 1 ;
363+ var child1N = child2N - 1 ;
365364 // This is used to store the new position of the element, if any.
366- var swap = null ,
367- child1Score ;
365+ var swap = null ;
366+ var child1Score ;
368367 // If the first child exists (is inside the array)...
369368 if ( child1N < length ) {
370369 // Look it up and compute its score.
@@ -379,8 +378,8 @@ BinaryHeap.prototype = {
379378
380379 // Do the same checks for the other child.
381380 if ( child2N < length ) {
382- var child2 = this . content [ child2N ] ,
383- child2Score = this . scoreFunction ( child2 ) ;
381+ var child2 = this . content [ child2N ] ;
382+ var child2Score = this . scoreFunction ( child2 ) ;
384383 if ( child2Score < ( swap === null ? elemScore : child1Score ) ) {
385384 swap = child2N ;
386385 }
0 commit comments