Skip to content

Commit 1f9224e

Browse files
committed
Code formatting
- Only use one var when possible - Define one var on each line (child1N) - Avoid comments on 2 lines for a few chars - Remove unecessary empty lines
1 parent abcc244 commit 1f9224e

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

astar.js

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,11 @@ var astar = {
5656
astar.init(graph);
5757

5858
options = options || {};
59-
var heuristic = options.heuristic || astar.heuristics.manhattan;
60-
var closest = options.closest || false;
59+
var heuristic = options.heuristic || astar.heuristics.manhattan,
60+
closest = options.closest || false;
6161

62-
var openHeap = astar.heap();
63-
64-
// set the start node to be the closest if required
65-
var closestNode = start;
62+
var openHeap = astar.heap(),
63+
closestNode = start; // set the start node to be the closest if required
6664

6765
start.h = heuristic(start, end);
6866

@@ -84,7 +82,7 @@ var astar = {
8482
// Find all neighbors for the current node.
8583
var neighbors = graph.neighbors(currentNode);
8684

87-
for(var i=0, il = neighbors.length; i < il; i++) {
85+
for(var i = 0, il = neighbors.length; i < il; ++i) {
8886
var neighbor = neighbors[i];
8987

9088
if(neighbor.closed || neighbor.isWall()) {
@@ -94,8 +92,8 @@ var astar = {
9492

9593
// The g score is the shortest distance from start to current node.
9694
// We need to check if the path we have arrived at this neighbor is the shortest one we have seen yet.
97-
var gScore = currentNode.g + neighbor.getCost(currentNode);
98-
var beenVisited = neighbor.visited;
95+
var gScore = currentNode.g + neighbor.getCost(currentNode),
96+
beenVisited = neighbor.visited;
9997

10098
if(!beenVisited || gScore < neighbor.g) {
10199

@@ -322,7 +320,6 @@ BinaryHeap.prototype = {
322320
// Update 'n' to continue at the new position.
323321
n = parentN;
324322
}
325-
326323
// Found a parent that is less, no need to sink any further.
327324
else {
328325
break;
@@ -337,11 +334,11 @@ BinaryHeap.prototype = {
337334

338335
while(true) {
339336
// Compute the indices of the child elements.
340-
var child2N = (n + 1) << 1, child1N = child2N - 1;
341-
// This is used to store the new position of the element,
342-
// if any.
343-
var swap = null;
344-
var child1Score;
337+
var child2N = (n + 1) << 1,
338+
child1N = child2N - 1;
339+
// This is used to store the new position of the element, if any.
340+
var swap = null,
341+
child1Score;
345342
// If the first child exists (is inside the array)...
346343
if (child1N < length) {
347344
// Look it up and compute its score.
@@ -369,7 +366,6 @@ BinaryHeap.prototype = {
369366
this.content[swap] = element;
370367
n = swap;
371368
}
372-
373369
// Otherwise, we are done.
374370
else {
375371
break;

0 commit comments

Comments
 (0)