Skip to content

Commit

Permalink
1.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
pagoru committed May 9, 2021
1 parent f88412e commit a8eef05
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pathfinding.ts",
"version": "1.3.2",
"version": "1.4.0",
"description": "",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down
1 change: 0 additions & 1 deletion src/finders/jumpPoint_2.finder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {DirectionEnum} from "../objects/nodes/direction.enum";
export const findPath = (
startPoint: Point,
endPoint: Point,
maxJumpCost: number,
grid: Grid
): PointInterface[] => {

Expand Down
5 changes: 2 additions & 3 deletions src/objects/grid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class Grid {
case "directionNode":
this.nodes = this._matrix.map((arrY, y) =>
arrY.map((cost, x) => {
if (0 > cost) return null
if (cost === null) return null

const directionNode = new DirectionNode(new Point(x, y));

Expand All @@ -45,7 +45,7 @@ export class Grid {
const nodePoint = directionNode.point.copy(point.x, point.y);
const neighborCost = this.getMatrixCost(nodePoint);

return (neighborCost !== null && neighborCost > 0 && Math.abs(neighborCost - cost) <= maxJumpCost)
return (neighborCost !== null && Math.abs(neighborCost - cost) <= maxJumpCost)
? nodePoint : null;
}

Expand Down Expand Up @@ -117,7 +117,6 @@ export class Grid {
return findPathJPS_2(
new Point(startPoint.x, startPoint.y),
new Point(endPoint.x, endPoint.y),
maxJumpCost,
gridClone
);
}
Expand Down
15 changes: 12 additions & 3 deletions src/sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,17 @@ import {Grid} from "./objects/grid";
import {smallGrid} from "../__tests__/test-data/small-grid";
import {FinderEnum} from "./finders/finder.enum";

const grid = new Grid(smallGrid, "directionNode");
const a = [
[null, null, null, null, null],
[null, null, null, null, null],
[null, null, 0, 0, null],
[4, 2, 0, -2, -4],
[0, null, null, null, null]
] as number[][];


const grid = new Grid(a);

console.log(
grid.findPath({ x: 4, y: 2 }, { x: 4, y: 1 }, 5, FinderEnum.JUMP_POINT_2)
);
grid.findPath({ x: 0, y: 3 }, { x: 4, y: 3 }, 5)
);

0 comments on commit a8eef05

Please sign in to comment.