From 5963050a870bca0264103f31c3bcbb3aeae68c95 Mon Sep 17 00:00:00 2001 From: Brian Grinstead Date: Tue, 17 Jun 2014 18:59:24 -0500 Subject: [PATCH 1/2] Move Graph out of global scope and into astar.Graph --- astar.js | 6 +++--- demo/demo.js | 4 ++-- test/tests.js | 12 ++++++------ 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/astar.js b/astar.js index b1cd1c7..211d9aa 100644 --- a/astar.js +++ b/astar.js @@ -14,7 +14,6 @@ } else { var exports = definition(); window.astar = exports.astar; - window.Graph = exports.Graph; } })(function() { @@ -381,9 +380,10 @@ BinaryHeap.prototype = { } }; +astar.Graph = Graph; + return { - astar: astar, - Graph: Graph + astar: astar }; }); diff --git a/demo/demo.js b/demo/demo.js index 785841f..bcf3755 100644 --- a/demo/demo.js +++ b/demo/demo.js @@ -3,7 +3,7 @@ Set up the demo page for the A* Search */ -/* global Graph, astar, $ */ +/* global astar, $ */ var WALL = 0, performance = window.performance; @@ -126,7 +126,7 @@ GraphSearch.prototype.initialize = function() { nodes.push(nodeRow); } - this.graph = new Graph(nodes); + this.graph = new astar.Graph(nodes); // bind cell event, set start/wall positions this.$cells = $graph.find(".grid_item"); diff --git a/test/tests.js b/test/tests.js index 8780022..4a04c27 100644 --- a/test/tests.js +++ b/test/tests.js @@ -1,10 +1,10 @@ -/* global Graph, astar, ok, test, equal */ +/* global astar, ok, test, equal */ test( "Sanity Checks", function() { - ok (typeof Graph !== "undefined", "Graph exists"); ok (typeof astar !== "undefined", "Astar exists"); + ok (typeof astar.Graph !== "undefined", "Graph exists"); }); test( "Basic Horizontal", function() { @@ -56,7 +56,7 @@ test( "Pathfinding", function() { }); test( "Diagonal Pathfinding", function() { - var result1 = runSearch(new Graph([ + var result1 = runSearch(new astar.Graph([ [1,1,1,1], [0,1,1,0], [0,0,1,1] @@ -92,8 +92,8 @@ test( "Pathfinding to closest", function() { }); function runSearch(graph, start, end, options) { - if (!(graph instanceof Graph)) { - graph = new Graph(graph); + if (!(graph instanceof astar.Graph)) { + graph = new astar.Graph(graph); } start = graph.grid[start[0]][start[1]]; end = graph.grid[end[0]][end[1]]; @@ -207,7 +207,7 @@ test( "GPS Pathfinding", function() { // // https://gist.github.com/bgrins/581352 // function runBasic() { -// var graph = new Graph([ +// var graph = new astar.Graph([ // [1,1,1,1], // [0,1,1,0], // [0,0,1,1] From 6c470bf673fb236aa8a25dd84eb2310f1b13e6a6 Mon Sep 17 00:00:00 2001 From: Brian Grinstead Date: Tue, 17 Jun 2014 19:03:33 -0500 Subject: [PATCH 2/2] update docs --- README.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 010af45..06254ca 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ If you want just the A* search code (not the demo visualization), use code like