PathFinding.js icon indicating copy to clipboard operation
PathFinding.js copied to clipboard

Bug with matrix

Open popov-kirill opened this issue 9 years ago • 3 comments

This code return error (Mozilla Firefox and Chrome)

var matrix = [
        [0, 0, 0, 1, 0],
        [1, 0, 0, 0, 1],
        [0, 0, 1, 0, 0]
];

var grid = new PF.Grid(matrix);

var finder = new PF.AStarFinder({
  allowDiagonal: true
});

var path = finder.findPath(1, 2, 4, 2, grid);

TypeError: this.nodes[e] is undefined ...s},r.prototype.getNodeAt=function(t,e){return this.nodes[e][t]},r.prototype.isWa... pathfin....min.js (string 1, 4329)

popov-kirill avatar Aug 24 '16 08:08 popov-kirill

Example in codepen http://codepen.io/kirillpopov/pen/dXBbxL

popov-kirill avatar Aug 24 '16 08:08 popov-kirill

Thats not an error the 1st dimension in the matrix is height, the 2nd dimension is width.

Langerz82 avatar Sep 25 '16 00:09 Langerz82

After this very vague response, i have debugged the issue to the new method of the Grid.

var grid = new PF.Grid(matrix);

it should actually be

var grid = new PF.Grid(width,height,grid);

AndreiLSN avatar Dec 29 '16 19:12 AndreiLSN