Boxart.Routing.Pathfinder (Boxart v0.3.2)

Copy Markdown View Source

A* pathfinder on the grid coordinate system.

Uses Manhattan distance with corner penalty as heuristic. 4-directional movement only (no diagonals). Previously-routed edges are soft obstacles (cost +2).

Summary

Functions

Manhattan distance with +1 corner penalty when not axis-aligned.

Remove collinear intermediate points, keeping only corners.

Types

coord()

@type coord() :: {col :: integer(), row :: integer()}

free_fn()

@type free_fn() :: (integer(), integer() -> boolean())

Functions

find_path(start_col, start_row, end_col, end_row, free_fn, opts \\ [])

@spec find_path(integer(), integer(), integer(), integer(), free_fn(), keyword()) ::
  [coord()] | nil

Find a path from start to end using A*.

Options

  • :soft_obstacles - MapSet of {col, row} cells occupied by previously-routed edges. Traversable at +2 cost.
  • :max_iterations - maximum iterations before giving up (default: 5000)

Returns a list of {col, row} waypoints, or nil if no path found.

heuristic(c1, r1, c2, r2)

@spec heuristic(integer(), integer(), integer(), integer()) :: float()

Manhattan distance with +1 corner penalty when not axis-aligned.

simplify_path(path)

@spec simplify_path([coord()]) :: [coord()]

Remove collinear intermediate points, keeping only corners.