Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/finders/AStarFinder.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ function AStarFinder(opt) {
*/
AStarFinder.prototype.findPath = function(startX, startY, endX, endY, grid) {
var openList = new Heap(function(nodeA, nodeB) {
return nodeA.f - nodeB.f;
var MAX_DIFF = 0.000001;
var diff = nodeA.f - nodeB.f;
return abs(diff) < MAX_DIFF ? nodeA.h - nodeB.h : diff;
}),
startNode = grid.getNodeAt(startX, startY),
endNode = grid.getNodeAt(endX, endY),
Expand Down
4 changes: 3 additions & 1 deletion src/finders/BiAStarFinder.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ function BiAStarFinder(opt) {
*/
BiAStarFinder.prototype.findPath = function(startX, startY, endX, endY, grid) {
var cmp = function(nodeA, nodeB) {
return nodeA.f - nodeB.f;
var MAX_DIFF = 0.000001;
var diff = nodeA.f - nodeB.f;
return abs(diff) < MAX_DIFF ? nodeA.h - nodeB.h : diff;
},
startOpenList = new Heap(cmp),
endOpenList = new Heap(cmp),
Expand Down
7 changes: 5 additions & 2 deletions src/finders/JumpPointFinderBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@ function JumpPointFinderBase(opt) {
*/
JumpPointFinderBase.prototype.findPath = function(startX, startY, endX, endY, grid) {
var openList = this.openList = new Heap(function(nodeA, nodeB) {
return nodeA.f - nodeB.f;
var MAX_DIFF = 0.000001;
var diff = nodeA.f - nodeB.f;
return abs(diff) < MAX_DIFF ? nodeA.h - nodeB.h : diff;
}),
startNode = this.startNode = grid.getNodeAt(startX, startY),
endNode = this.endNode = grid.getNodeAt(endX, endY), node;
endNode = this.endNode = grid.getNodeAt(endX, endY), node,
abs = Math.abs;

this.grid = grid;

Expand Down