Skip to content

Commit 983f094

Browse files
committed
use options parameter instead of parameter list. Issue bgrins#12 and Issue bgrins#16
1 parent 11cb0e1 commit 983f094

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

astar.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,21 @@ var astar = {
3737
return node.f;
3838
});
3939
},
40-
search: function(grid, start, end, diagonal, heuristic, costStraight, costDiagonal) {
41-
costDiagonal = costDiagonal || 1;
42-
costStraight = costStraight || 1;
40+
41+
// astar.search
42+
// supported options:
43+
// {
44+
// heuristic: heuristic function to use
45+
// diagonal: boolean specifying whether diagonal moves are allowed
46+
// }
47+
search: function(grid, start, end, options) {
4348
astar.init(grid);
44-
heuristic = heuristic || astar.manhattan;
45-
diagonal = !!diagonal;
49+
50+
options = options || {};
51+
var heuristic = options.heuristic || astar.manhattan;
52+
var diagonal = !!options.diagonal;
53+
var costDiagonal = options.costDiagonal || 1;
54+
var costStraight = options.costStraight || 1;
4655

4756
var openHeap = astar.heap();
4857

demo/demo.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,9 @@ GraphSearch.prototype.cellClicked = function($end) {
170170
var start = this.nodeFromElement($start);
171171

172172
var sTime = new Date();
173-
var path = this.search(this.graph.nodes, start, end, this.opts.diagonal);
173+
var path = this.search(this.graph.nodes, start, end, {
174+
diagonal: this.opts.diagonal
175+
});
174176
var fTime = new Date();
175177

176178
if(!path || path.length == 0) {

0 commit comments

Comments
 (0)