Bear Robotics' Servi navigation stack can use a distance transform to prefer paths that maintain clearance from obstacles. Given a binary occupancy grid, compute the distance from every free cell to its nearest obstacle using four-directional movement.
A cell containing 1 is an obstacle and has distance 0. A cell containing 0 is free, and its distance is the minimum number of up, down, left, or right moves needed to reach any obstacle. Return a new grid of integer distances without modifying the input.
Implement distance_transform(grid).
grid, a non-empty rectangular list of lists containing only 0 and 1.def distance_transform(grid):