diff --git a/package.json b/package.json index 032acdc..cd583e7 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/finders/jumpPoint_2.finder.ts b/src/finders/jumpPoint_2.finder.ts index ec77574..29bea8e 100644 --- a/src/finders/jumpPoint_2.finder.ts +++ b/src/finders/jumpPoint_2.finder.ts @@ -7,7 +7,6 @@ import {DirectionEnum} from "../objects/nodes/direction.enum"; export const findPath = ( startPoint: Point, endPoint: Point, - maxJumpCost: number, grid: Grid ): PointInterface[] => { diff --git a/src/objects/grid.ts b/src/objects/grid.ts index 681f0ce..79bd2fe 100644 --- a/src/objects/grid.ts +++ b/src/objects/grid.ts @@ -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)); @@ -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; } @@ -117,7 +117,6 @@ export class Grid { return findPathJPS_2( new Point(startPoint.x, startPoint.y), new Point(endPoint.x, endPoint.y), - maxJumpCost, gridClone ); } diff --git a/src/sandbox.ts b/src/sandbox.ts index 702e7f8..e086ba5 100644 --- a/src/sandbox.ts +++ b/src/sandbox.ts @@ -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) +); \ No newline at end of file