{"version":3,"sources":["../../index.ts","../../lib/javascript-astar.js"],"sourcesContent":["import {\n Polygon,\n Feature,\n FeatureCollection,\n LineString,\n Geometry,\n Point,\n} from \"geojson\";\nimport { bbox } from \"@turf/bbox\";\nimport { booleanPointInPolygon } from \"@turf/boolean-point-in-polygon\";\nimport { distance } from \"@turf/distance\";\nimport { transformScale as scale } from \"@turf/transform-scale\";\nimport { cleanCoords } from \"@turf/clean-coords\";\nimport { bboxPolygon } from \"@turf/bbox-polygon\";\nimport { getCoord, getGeom } from \"@turf/invariant\";\nimport {\n Coord,\n Units,\n point,\n isNumber,\n lineString,\n isObject,\n featureCollection,\n feature,\n} from \"@turf/helpers\";\nimport { Graph, GridNode, astar } from \"./lib/javascript-astar.js\";\n\n/**\n * Returns the shortest {@link LineString|path} from {@link Point|start} to {@link Point|end} without colliding with\n * any {@link Feature} in obstacles {@link FeatureCollection}<{@link Polygon}>\n *\n * @function\n * @param {Coord} start point\n * @param {Coord} end point\n * @param {Object} [options={}] optional parameters\n * @param {Polygon|Feature|FeatureCollection} [options.obstacles] areas which path cannot travel\n * @param {Units} [options.units='kilometers'] unit in which resolution & minimum distance will be expressed in; it can be degrees, radians, miles, kilometers, ...\n * @param {number} [options.resolution=100] distance between matrix points on which the path will be calculated\n * @returns {Feature} shortest path between start and end\n * @example\n * var start = [-5, -6];\n * var end = [9, -6];\n * var options = {\n * obstacles: turf.polygon([[[0, -7], [5, -7], [5, -3], [0, -3], [0, -7]]]).geometry\n * };\n *\n * var path = turf.shortestPath(start, end, options);\n *\n * //addToMap\n * var addToMap = [start, end, options.obstacles, path];\n */\nfunction shortestPath(\n start: Coord,\n end: Coord,\n options: {\n obstacles?: Polygon | Feature | FeatureCollection;\n units?: Units;\n resolution?: number;\n } = {}\n): Feature {\n // Optional parameters\n options = options || {};\n if (!isObject(options)) throw new Error(\"options is invalid\");\n let obstacles = options.obstacles || featureCollection([]);\n let resolution = options.resolution || 100;\n\n // validation\n if (!start) throw new Error(\"start is required\");\n if (!end) throw new Error(\"end is required\");\n if (resolution && (!isNumber(resolution) || resolution <= 0))\n throw new Error(\"options.resolution must be a number, greater than 0\");\n\n // Normalize Inputs\n const startCoord = getCoord(start);\n const endCoord = getCoord(end);\n start = point(startCoord);\n end = point(endCoord);\n\n // Handle obstacles\n if (obstacles.type === \"FeatureCollection\") {\n if (obstacles.features.length === 0) {\n return lineString([startCoord, endCoord]);\n }\n } else if (obstacles.type === \"Polygon\") {\n obstacles = featureCollection([feature(getGeom(obstacles))]);\n } else {\n throw new Error(\"invalid obstacles\");\n }\n\n // define path grid area\n const collection: FeatureCollection = obstacles;\n collection.features.push(start);\n collection.features.push(end);\n const box = bbox(scale(bboxPolygon(bbox(collection)), 1.15)); // extend 15%\n const [west, south, east, north] = box;\n\n const width = distance([west, south], [east, south], options);\n const division = width / resolution;\n\n collection.features.pop();\n collection.features.pop();\n\n const xFraction = division / distance([west, south], [east, south], options);\n const cellWidth = xFraction * (east - west);\n const yFraction = division / distance([west, south], [west, north], options);\n const cellHeight = yFraction * (north - south);\n\n const bboxHorizontalSide = east - west;\n const bboxVerticalSide = north - south;\n const columns = Math.floor(bboxHorizontalSide / cellWidth);\n const rows = Math.floor(bboxVerticalSide / cellHeight);\n // adjust origin of the grid\n const deltaX = (bboxHorizontalSide - columns * cellWidth) / 2;\n const deltaY = (bboxVerticalSide - rows * cellHeight) / 2;\n\n // loop through points only once to speed up process\n // define matrix grid for A-star algorithm\n const pointMatrix: string[][] = [];\n const matrix: number[][] = [];\n\n let closestToStart: GridNode;\n let closestToEnd: GridNode;\n let minDistStart = Infinity;\n let minDistEnd = Infinity;\n let currentY = north - deltaY;\n let r = 0;\n while (currentY >= south) {\n // var currentY = south + deltaY;\n const matrixRow = [];\n const pointMatrixRow = [];\n let currentX = west + deltaX;\n let c = 0;\n while (currentX <= east) {\n const pt = point([currentX, currentY]);\n const isInsideObstacle = isInside(pt, obstacles);\n // feed obstacles matrix\n matrixRow.push(isInsideObstacle ? 0 : 1); // with javascript-astar\n // matrixRow.push(isInsideObstacle ? 1 : 0); // with astar-andrea\n // map point's coords\n pointMatrixRow.push(currentX + \"|\" + currentY);\n // set closest points\n const distStart = distance(pt, start);\n // if (distStart < minDistStart) {\n if (!isInsideObstacle && distStart < minDistStart) {\n minDistStart = distStart;\n closestToStart = { x: c, y: r };\n }\n const distEnd = distance(pt, end);\n // if (distEnd < minDistEnd) {\n if (!isInsideObstacle && distEnd < minDistEnd) {\n minDistEnd = distEnd;\n closestToEnd = { x: c, y: r };\n }\n currentX += cellWidth;\n c++;\n }\n matrix.push(matrixRow);\n pointMatrix.push(pointMatrixRow);\n currentY -= cellHeight;\n r++;\n }\n\n // find path on matrix grid\n\n // javascript-astar ----------------------\n const graph = new Graph(matrix, { diagonal: true });\n const startOnMatrix = graph.grid[closestToStart!.y][closestToStart!.x];\n const endOnMatrix = graph.grid[closestToEnd!.y][closestToEnd!.x];\n const result: GridNode[] = astar.search(graph, startOnMatrix, endOnMatrix);\n\n const path = [startCoord];\n result.forEach(function (coord) {\n const coords = pointMatrix[coord.x][coord.y].split(\"|\");\n path.push([+coords[0], +coords[1]]); // make sure coords are numbers\n });\n path.push(endCoord);\n // ---------------------------------------\n\n // astar-andrea ------------------------\n // var result = aStar(matrix, [closestToStart.x, closestToStart.y], [closestToEnd.x, closestToEnd.y], 'DiagonalFree');\n // var path = [start.geometry.coordinates];\n // result.forEach(function (coord) {\n // var coords = pointMatrix[coord[1]][coord[0]].split('|');\n // path.push([+coords[0], +coords[1]]); // make sure coords are numbers\n // });\n // path.push(end.geometry.coordinates);\n // ---------------------------------------\n\n return cleanCoords(lineString(path));\n}\n\n/**\n * Checks if Point is inside any of the Polygons\n *\n * @private\n * @param {Feature} pt to check\n * @param {FeatureCollection} polygons features\n * @returns {boolean} if inside or not\n */\nfunction isInside(pt: Feature, polygons: FeatureCollection) {\n for (let i = 0; i < polygons.features.length; i++) {\n if (booleanPointInPolygon(pt, polygons.features[i])) {\n return true;\n }\n }\n return false;\n}\n\nexport { shortestPath };\nexport default shortestPath;\n","// javascript-astar 0.4.1\n// http://github.com/bgrins/javascript-astar\n// Freely distributable under the MIT License.\n// Implements the astar search algorithm in javascript using a Binary Heap.\n// Includes Binary Heap (with modifications) from Marijn Haverbeke.\n// http://eloquentjavascript.net/appendix2.html\n\nfunction pathTo(node) {\n var curr = node,\n path = [];\n while (curr.parent) {\n path.unshift(curr);\n curr = curr.parent;\n }\n return path;\n}\n\nfunction getHeap() {\n return new BinaryHeap(function (node) {\n return node.f;\n });\n}\n\n/**\n * Astar\n * @private\n */\nexport var astar = {\n /**\n * Perform an A* Search on a graph given a start and end node.\n *\n * @private\n * @memberof astar\n * @param {Graph} graph Graph\n * @param {GridNode} start Start\n * @param {GridNode} end End\n * @param {Object} [options] Options\n * @param {bool} [options.closest] Specifies whether to return the path to the closest node if the target is unreachable.\n * @param {Function} [options.heuristic] Heuristic function (see astar.heuristics).\n * @returns {Object} Search\n */\n search: function (graph, start, end, options) {\n graph.cleanDirty();\n options = options || {};\n var heuristic = options.heuristic || astar.heuristics.manhattan,\n closest = options.closest ?? false;\n\n var openHeap = getHeap(),\n closestNode = start; // set the start node to be the closest if required\n\n start.h = heuristic(start, end);\n\n openHeap.push(start);\n\n while (openHeap.size() > 0) {\n // Grab the lowest f(x) to process next. Heap keeps this sorted for us.\n var currentNode = openHeap.pop();\n\n // End case -- result has been found, return the traced path.\n if (currentNode === end) {\n return pathTo(currentNode);\n }\n\n // Normal case -- move currentNode from open to closed, process each of its neighbors.\n currentNode.closed = true;\n\n // Find all neighbors for the current node.\n var neighbors = graph.neighbors(currentNode);\n\n for (var i = 0, il = neighbors.length; i < il; ++i) {\n var neighbor = neighbors[i];\n\n if (neighbor.closed || neighbor.isWall()) {\n // Not a valid node to process, skip to next neighbor.\n continue;\n }\n\n // The g score is the shortest distance from start to current node.\n // We need to check if the path we have arrived at this neighbor is the shortest one we have seen yet.\n var gScore = currentNode.g + neighbor.getCost(currentNode),\n beenVisited = neighbor.visited;\n\n if (!beenVisited || gScore < neighbor.g) {\n // Found an optimal (so far) path to this node. Take score for node to see how good it is.\n neighbor.visited = true;\n neighbor.parent = currentNode;\n neighbor.h = neighbor.h || heuristic(neighbor, end);\n neighbor.g = gScore;\n neighbor.f = neighbor.g + neighbor.h;\n graph.markDirty(neighbor);\n if (closest) {\n // If the neighbour is closer than the current closestNode or if it's equally close but has\n // a cheaper path than the current closest node then it becomes the closest node\n if (\n neighbor.h < closestNode.h ||\n (neighbor.h === closestNode.h && neighbor.g < closestNode.g)\n ) {\n closestNode = neighbor;\n }\n }\n\n if (!beenVisited) {\n // Pushing to heap will put it in proper place based on the 'f' value.\n openHeap.push(neighbor);\n } else {\n // Already seen the node, but since it has been rescored we need to reorder it in the heap\n openHeap.rescoreElement(neighbor);\n }\n }\n }\n }\n\n if (closest) {\n return pathTo(closestNode);\n }\n\n // No result was found - empty array signifies failure to find path.\n return [];\n },\n // See list of heuristics: http://theory.stanford.edu/~amitp/GameProgramming/Heuristics.html\n heuristics: {\n manhattan: function (pos0, pos1) {\n var d1 = Math.abs(pos1.x - pos0.x);\n var d2 = Math.abs(pos1.y - pos0.y);\n return d1 + d2;\n },\n diagonal: function (pos0, pos1) {\n var D = 1;\n var D2 = Math.sqrt(2);\n var d1 = Math.abs(pos1.x - pos0.x);\n var d2 = Math.abs(pos1.y - pos0.y);\n return D * (d1 + d2) + (D2 - 2 * D) * Math.min(d1, d2);\n },\n },\n cleanNode: function (node) {\n node.f = 0;\n node.g = 0;\n node.h = 0;\n node.visited = false;\n node.closed = false;\n node.parent = null;\n },\n};\n\n/**\n * A graph memory structure\n *\n * @private\n * @param {Array} gridIn 2D array of input weights\n * @param {Object} [options] Options\n * @param {boolean} [options.diagonal] Specifies whether diagonal moves are allowed\n * @returns {void} Graph\n */\nexport function Graph(gridIn, options) {\n options = options || {};\n this.nodes = [];\n this.diagonal = !!options.diagonal;\n this.grid = [];\n for (var x = 0; x < gridIn.length; x++) {\n this.grid[x] = [];\n\n for (var y = 0, row = gridIn[x]; y < row.length; y++) {\n var node = new GridNode(x, y, row[y]);\n this.grid[x][y] = node;\n this.nodes.push(node);\n }\n }\n this.init();\n}\n\nGraph.prototype.init = function () {\n this.dirtyNodes = [];\n for (var i = 0; i < this.nodes.length; i++) {\n astar.cleanNode(this.nodes[i]);\n }\n};\n\nGraph.prototype.cleanDirty = function () {\n for (var i = 0; i < this.dirtyNodes.length; i++) {\n astar.cleanNode(this.dirtyNodes[i]);\n }\n this.dirtyNodes = [];\n};\n\nGraph.prototype.markDirty = function (node) {\n this.dirtyNodes.push(node);\n};\n\nGraph.prototype.neighbors = function (node) {\n var ret = [],\n x = node.x,\n y = node.y,\n grid = this.grid;\n\n // West\n if (grid[x - 1] && grid[x - 1][y]) {\n ret.push(grid[x - 1][y]);\n }\n\n // East\n if (grid[x + 1] && grid[x + 1][y]) {\n ret.push(grid[x + 1][y]);\n }\n\n // South\n if (grid[x] && grid[x][y - 1]) {\n ret.push(grid[x][y - 1]);\n }\n\n // North\n if (grid[x] && grid[x][y + 1]) {\n ret.push(grid[x][y + 1]);\n }\n\n if (this.diagonal) {\n // Southwest\n if (grid[x - 1] && grid[x - 1][y - 1]) {\n ret.push(grid[x - 1][y - 1]);\n }\n\n // Southeast\n if (grid[x + 1] && grid[x + 1][y - 1]) {\n ret.push(grid[x + 1][y - 1]);\n }\n\n // Northwest\n if (grid[x - 1] && grid[x - 1][y + 1]) {\n ret.push(grid[x - 1][y + 1]);\n }\n\n // Northeast\n if (grid[x + 1] && grid[x + 1][y + 1]) {\n ret.push(grid[x + 1][y + 1]);\n }\n }\n\n return ret;\n};\n\nGraph.prototype.toString = function () {\n var graphString = [],\n nodes = this.grid, // when using grid\n rowDebug,\n row,\n y,\n l;\n for (var x = 0, len = nodes.length; x < len; x++) {\n rowDebug = [];\n row = nodes[x];\n for (y = 0, l = row.length; y < l; y++) {\n rowDebug.push(row[y].weight);\n }\n graphString.push(rowDebug.join(\" \"));\n }\n return graphString.join(\"\\n\");\n};\n\nfunction GridNode(x, y, weight) {\n this.x = x;\n this.y = y;\n this.weight = weight;\n}\n\nGridNode.prototype.toString = function () {\n return \"[\" + this.x + \" \" + this.y + \"]\";\n};\n\nGridNode.prototype.getCost = function (fromNeighbor) {\n // Take diagonal weight into consideration.\n if (fromNeighbor && fromNeighbor.x !== this.x && fromNeighbor.y !== this.y) {\n return this.weight * 1.41421;\n }\n return this.weight;\n};\n\nGridNode.prototype.isWall = function () {\n return this.weight === 0;\n};\n\nfunction BinaryHeap(scoreFunction) {\n this.content = [];\n this.scoreFunction = scoreFunction;\n}\n\nBinaryHeap.prototype = {\n push: function (element) {\n // Add the new element to the end of the array.\n this.content.push(element);\n\n // Allow it to sink down.\n this.sinkDown(this.content.length - 1);\n },\n pop: function () {\n // Store the first element so we can return it later.\n var result = this.content[0];\n // Get the element at the end of the array.\n var end = this.content.pop();\n // If there are any elements left, put the end element at the\n // start, and let it bubble up.\n if (this.content.length > 0) {\n this.content[0] = end;\n this.bubbleUp(0);\n }\n return result;\n },\n remove: function (node) {\n var i = this.content.indexOf(node);\n\n // When it is found, the process seen in 'pop' is repeated\n // to fill up the hole.\n var end = this.content.pop();\n\n if (i !== this.content.length - 1) {\n this.content[i] = end;\n\n if (this.scoreFunction(end) < this.scoreFunction(node)) {\n this.sinkDown(i);\n } else {\n this.bubbleUp(i);\n }\n }\n },\n size: function () {\n return this.content.length;\n },\n rescoreElement: function (node) {\n this.sinkDown(this.content.indexOf(node));\n },\n sinkDown: function (n) {\n // Fetch the element that has to be sunk.\n var element = this.content[n];\n\n // When at 0, an element can not sink any further.\n while (n > 0) {\n // Compute the parent element's index, and fetch it.\n var parentN = ((n + 1) >> 1) - 1,\n parent = this.content[parentN];\n // Swap the elements if the parent is greater.\n if (this.scoreFunction(element) < this.scoreFunction(parent)) {\n this.content[parentN] = element;\n this.content[n] = parent;\n // Update 'n' to continue at the new position.\n n = parentN;\n // Found a parent that is less, no need to sink any further.\n } else {\n break;\n }\n }\n },\n bubbleUp: function (n) {\n // Look up the target element and its score.\n var length = this.content.length,\n element = this.content[n],\n elemScore = this.scoreFunction(element);\n\n while (true) {\n // Compute the indices of the child elements.\n var child2N = (n + 1) << 1,\n child1N = child2N - 1;\n // This is used to store the new position of the element, if any.\n var swap = null,\n child1Score;\n // If the first child exists (is inside the array)...\n if (child1N < length) {\n // Look it up and compute its score.\n var child1 = this.content[child1N];\n child1Score = this.scoreFunction(child1);\n\n // If the score is less than our element's, we need to swap.\n if (child1Score < elemScore) {\n swap = child1N;\n }\n }\n\n // Do the same checks for the other child.\n if (child2N < length) {\n var child2 = this.content[child2N],\n child2Score = this.scoreFunction(child2);\n if (child2Score < (swap === null ? elemScore : child1Score)) {\n swap = child2N;\n }\n }\n\n // If the element needs to be moved, swap it, and continue.\n if (swap !== null) {\n this.content[n] = this.content[swap];\n this.content[swap] = element;\n n = swap;\n // Otherwise, we are done.\n } else {\n break;\n }\n }\n },\n};\n"],"mappings":";AAQA,SAAS,YAAY;AACrB,SAAS,6BAA6B;AACtC,SAAS,gBAAgB;AACzB,SAAS,kBAAkB,aAAa;AACxC,SAAS,mBAAmB;AAC5B,SAAS,mBAAmB;AAC5B,SAAS,UAAU,eAAe;AAClC;AAAA,EAGE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;;;ACjBP,SAAS,OAAO,MAAM;AACpB,MAAI,OAAO,MACT,OAAO,CAAC;AACV,SAAO,KAAK,QAAQ;AAClB,SAAK,QAAQ,IAAI;AACjB,WAAO,KAAK;AAAA,EACd;AACA,SAAO;AACT;AAEA,SAAS,UAAU;AACjB,SAAO,IAAI,WAAW,SAAU,MAAM;AACpC,WAAO,KAAK;AAAA,EACd,CAAC;AACH;AAMO,IAAI,QAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAcjB,QAAQ,SAAU,OAAO,OAAO,KAAK,SAAS;AAzChD;AA0CI,UAAM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