Permalink
Browse files

Fix #26. Address #25. Bump version to 0.2.0.

  • Loading branch information...
prettymuchbryce committed Apr 25, 2015
1 parent f7127ce commit 397ec7d0dc6ef884c33ea17f17f0e2660ce89f50
Showing with 328 additions and 142 deletions.
  1. +3 −1 .gitignore
  2. +0 −1 bin/easystar-0.1.13.min.js
  3. +99 −44 bin/{easystar-0.1.13.js → easystar-0.2.0.js}
  4. +1 −0 bin/easystar-0.2.0.min.js
  5. +2 −2 bower.json
  6. +7 −3 package.json
  7. +99 −44 src/easystar.js
  8. +117 −47 test/easystartest.js
View
@@ -1,4 +1,6 @@
.DS_Store
node_modules/
coverage/
.log
.log
docs/
coverage/

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -220,6 +220,7 @@ EasyStar.js = function() {
var pointsToAvoid = {};
var collisionGrid;
var costMap = {};
var allowCornerCutting = true;
var iterationsSoFar;
var instances = [];
var iterationsPerCalculation = Number.MAX_VALUE;
@@ -319,6 +320,20 @@ EasyStar.js = function() {
delete pointsToAvoid[x + "_" + y];
};
/**
* Enables corner cutting in diagonal movement.
**/
this.enableCornerCutting = function() {
allowCornerCutting = true;
};
/**
* Disables corner cutting in diagonal movement.
**/
this.disableCornerCutting = function() {
allowCornerCutting = false;
};
/**
* Stop avoiding all additional points on the grid.
**/
@@ -356,7 +371,9 @@ EasyStar.js = function() {
//Start and end are the same tile.
if (startX===endX && startY===endY) {
callback([]);
setTimeout(function() {
callback([]);
});
return;
}
@@ -371,7 +388,9 @@ EasyStar.js = function() {
}
if (isAcceptable === false) {
callback(null);
setTimeout(function() {
callback(null);
});
return;
}
@@ -385,16 +404,16 @@ EasyStar.js = function() {
instance.endX = endX;
instance.endY = endY;
instance.callback = callback;
instance.openList.insert(coordinateToNode(instance, instance.startX,
instance.startY, null, STRAIGHT_COST));
instances.push(instance);
};
/**
* This method steps through the A* Algorithm in an attempt to
* find your path(s). It will search 4 tiles for every calculation.
* find your path(s). It will search 4-8 tiles (depending on diagonals) for every calculation.
* You can change the number of calculations done in a call by using
* easystar.setIteratonsPerCalculation().
**/
@@ -408,8 +427,11 @@ EasyStar.js = function() {
}
//Couldn't find a path.
if (instances[0].openList.length===0) {
instances[0].callback(null);
if (instances[0].openList.length === 0) {
var ic = instances[0];
setTimeout(function() {
ic.callback(null);
});
instances.shift();
continue;
}
@@ -451,35 +473,59 @@ EasyStar.js = function() {
}
if (diagonalsEnabled) {
if (searchNode.x > 0 && searchNode.y > 0) {
checkAdjacentNode(instances[0], searchNode, -1, -1, DIAGONAL_COST *
costMap[collisionGrid[searchNode.y-1][searchNode.x-1]]);
if (instances[0].isDoneCalculating===true) {
instances.shift();
continue;
if (allowCornerCutting ||
(isTileWalkable(collisionGrid, acceptableTiles, searchNode.x, searchNode.y-1) &&
isTileWalkable(collisionGrid, acceptableTiles, searchNode.x-1, searchNode.y))) {
checkAdjacentNode(instances[0], searchNode, -1, -1, DIAGONAL_COST *
costMap[collisionGrid[searchNode.y-1][searchNode.x-1]]);
if (instances[0].isDoneCalculating===true) {
instances.shift();
continue;
}
}
}
if (searchNode.x < collisionGrid[0].length-1 && searchNode.y < collisionGrid.length-1) {
checkAdjacentNode(instances[0], searchNode, 1, 1, DIAGONAL_COST *
costMap[collisionGrid[searchNode.y+1][searchNode.x+1]]);
if (instances[0].isDoneCalculating===true) {
instances.shift();
continue;
if (allowCornerCutting ||
(isTileWalkable(collisionGrid, acceptableTiles, searchNode.x, searchNode.y+1) &&
isTileWalkable(collisionGrid, acceptableTiles, searchNode.x+1, searchNode.y))) {
checkAdjacentNode(instances[0], searchNode, 1, 1, DIAGONAL_COST *
costMap[collisionGrid[searchNode.y+1][searchNode.x+1]]);
if (instances[0].isDoneCalculating===true) {
instances.shift();
continue;
}
}
}
if (searchNode.x < collisionGrid[0].length-1 && searchNode.y > 0) {
checkAdjacentNode(instances[0], searchNode, 1, -1, DIAGONAL_COST *
costMap[collisionGrid[searchNode.y-1][searchNode.x+1]]);
if (instances[0].isDoneCalculating===true) {
instances.shift();
continue;
if (allowCornerCutting ||
(isTileWalkable(collisionGrid, acceptableTiles, searchNode.x, searchNode.y-1) &&
isTileWalkable(collisionGrid, acceptableTiles, searchNode.x+1, searchNode.y))) {
checkAdjacentNode(instances[0], searchNode, 1, -1, DIAGONAL_COST *
costMap[collisionGrid[searchNode.y-1][searchNode.x+1]]);
if (instances[0].isDoneCalculating===true) {
instances.shift();
continue;
}
}
}
if (searchNode.x > 0 && searchNode.y < collisionGrid.length-1) {
checkAdjacentNode(instances[0], searchNode, -1, 1, DIAGONAL_COST *
costMap[collisionGrid[searchNode.y+1][searchNode.x-1]]);
if (instances[0].isDoneCalculating===true) {
instances.shift();
continue;
if (allowCornerCutting ||
(isTileWalkable(collisionGrid, acceptableTiles, searchNode.x, searchNode.y+1) &&
isTileWalkable(collisionGrid, acceptableTiles, searchNode.x-1, searchNode.y))) {
checkAdjacentNode(instances[0], searchNode, -1, 1, DIAGONAL_COST *
costMap[collisionGrid[searchNode.y+1][searchNode.x-1]]);
if (instances[0].isDoneCalculating===true) {
instances.shift();
continue;
}
}
}
}
@@ -492,7 +538,7 @@ EasyStar.js = function() {
var adjacentCoordinateX = searchNode.x+x;
var adjacentCoordinateY = searchNode.y+y;
if (pointsToAvoid[adjacentCoordinateX + "_" + adjacentCoordinateY] === undefined) {
if (pointsToAvoid[adjacentCoordinateX + "_" + adjacentCoordinateY] === undefined) {
if (instance.endX === adjacentCoordinateX && instance.endY === adjacentCoordinateY) {
instance.isDoneCalculating = true;
var path = [];
@@ -508,29 +554,38 @@ EasyStar.js = function() {
parent = parent.parent;
}
path.reverse();
instance.callback(path);
var ic = instance;
var ip = path;
setTimeout(function() {
ic.callback(ip);
});
}
for (var i = 0; i < acceptableTiles.length; i++) {
if (collisionGrid[adjacentCoordinateY][adjacentCoordinateX] === acceptableTiles[i]) {
var node = coordinateToNode(instance, adjacentCoordinateX,
adjacentCoordinateY, searchNode, cost);
if (node.list === undefined) {
node.list = EasyStar.Node.OPEN_LIST;
instance.openList.insert(node);
} else if (node.list === EasyStar.Node.OPEN_LIST) {
if (searchNode.costSoFar + cost < node.costSoFar) {
node.costSoFar = searchNode.costSoFar + cost;
node.parent = searchNode;
}
if (isTileWalkable(collisionGrid, acceptableTiles, adjacentCoordinateX, adjacentCoordinateY)) {
var node = coordinateToNode(instance, adjacentCoordinateX,
adjacentCoordinateY, searchNode, cost);
if (node.list === undefined) {
node.list = EasyStar.Node.OPEN_LIST;
instance.openList.insert(node);
} else if (node.list === EasyStar.Node.OPEN_LIST) {
if (searchNode.costSoFar + cost < node.costSoFar) {
node.costSoFar = searchNode.costSoFar + cost;
node.parent = searchNode;
}
break;
}
}
}
};
var isTileWalkable = function(collisionGrid, acceptableTiles, x, y) {
for (var i = 0; i < acceptableTiles.length; i++) {
if (collisionGrid[y][x] === acceptableTiles[i]) {
return true;
}
}
return false;
};
//Helpers

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -1,9 +1,9 @@
{
"name": "easystarjs",
"version": "0.1.13",
"version": "0.2.0",
"homepage": "https://github.com/prettymuchbryce/easystarjs",
"description": "Asynchronous A* Pathfinding API",
"main": "./bin/easystar-0.1.13.min.js",
"main": "./bin/easystar-0.2.0.min.js",
"keywords": [
"A*",
"pathfinding",
View
@@ -1,7 +1,7 @@
{
"name": "easystarjs",
"version": "0.1.13",
"main": "./bin/easystar-0.1.13",
"version": "0.2.0",
"main": "./bin/easystar-0.2.0",
"description": "Asynchronous A* Pathfinding API",
"keywords": [
"A*",
@@ -10,6 +10,10 @@
"easystar"
],
"homepage": "http://www.easystarjs.com",
"repository": {
"type": "git",
"url": "git://github.com/prettymuchbryce/easystarjs.git"
},
"license": "MIT",
"author": {
"name": "Bryce Neal",
@@ -23,7 +27,7 @@
"gulp-uglify": "^0.3.0",
"karma": "^0.12.16",
"karma-coverage": "^0.2.4",
"karma-jasmine": "^0.1.5",
"karma-jasmine": "^0.3.5",
"karma-phantomjs-launcher": "^0.1.4"
},
"dependencies": {}
Oops, something went wrong.

0 comments on commit 397ec7d

Please sign in to comment.