Skip to main content

generatePath

Pathfinding function that computes a grid path between start and end cells.

TypePathFindingFunction
DefaultpathfindingAStarDiagonal (bezier/straight presets)

Built-in functions

ExportBehavior
pathfindingAStarDiagonalA* with diagonal moves (SmartBezierEdge, SmartStraightEdge)
pathfindingAStarNoDiagonalOrthogonal-only A* (custom edges)
pathfindingJumpPointNoDiagonalJump-point search, no diagonals (SmartStepEdge)
import {
getSmartEdge,
pathfindingJumpPointNoDiagonal,
} from "@tisoap/react-flow-smart-edge";

const result = getSmartEdge({
/* ... */
options: { generatePath: pathfindingJumpPointNoDiagonal },
});

Signature

type PathFindingFunction = (
grid: FlatGrid,
start: XYPosition,
end: XYPosition,
) => number[][];

The grid parameter is a FlatGrid: a flat typed-array obstacle grid where blocked is a Uint8Array indexed as y * width + x, with 1 = blocked and 0 = walkable. Helper functions are exported from the package: createFlatGrid, cloneFlatGrid, isInside, isWalkable, setBlocked, and blockCellRange. See the v5 migration guide for details on upgrading custom generatePath implementations from v4.

A custom generatePath only applies when you call getSmartEdge directly. Under SmartEdgeProvider, function options cannot cross to the routing worker, so edges resolve pathfinding from their preset; route with getSmartEdge to use your own pathfinder.

For reference: generatePath.ts source and flatGrid.ts type and helpers.