Skip to content

Commit

Permalink
use options parameter instead of parameter list. Issue bgrins#12 and …
Browse files Browse the repository at this point in the history
…Issue bgrins#16
  • Loading branch information
bgrins committed Mar 1, 2014
1 parent 11cb0e1 commit 983f094
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
19 changes: 14 additions & 5 deletions astar.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,21 @@ var astar = {
return node.f;
});
},
search: function(grid, start, end, diagonal, heuristic, costStraight, costDiagonal) {
costDiagonal = costDiagonal || 1;
costStraight = costStraight || 1;

// astar.search
// supported options:
// {
// heuristic: heuristic function to use
// diagonal: boolean specifying whether diagonal moves are allowed
// }
search: function(grid, start, end, options) {
astar.init(grid);
heuristic = heuristic || astar.manhattan;
diagonal = !!diagonal;

options = options || {};
var heuristic = options.heuristic || astar.manhattan;
var diagonal = !!options.diagonal;
var costDiagonal = options.costDiagonal || 1;
var costStraight = options.costStraight || 1;

var openHeap = astar.heap();

Expand Down
4 changes: 3 additions & 1 deletion demo/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,9 @@ GraphSearch.prototype.cellClicked = function($end) {
var start = this.nodeFromElement($start);

var sTime = new Date();
var path = this.search(this.graph.nodes, start, end, this.opts.diagonal);
var path = this.search(this.graph.nodes, start, end, {
diagonal: this.opts.diagonal
});
var fTime = new Date();

if(!path || path.length == 0) {
Expand Down

0 comments on commit 983f094

Please sign in to comment.