pub fn smooth_path<G: NavGrid + ?Sized>(
grid: &G,
path: &mut Vec<UVec2>,
neighborhood: Neighborhood,
clearance: Vec2,
) -> Result<(), PathError>Expand description
Removes waypoints that a straight segment can skip, in place.
Keeps the first and last cells. A waypoint is skipped when the segment
between its neighbors has line_of_sight with clearance and costs no
more than the cells it replaces, measured as each cell’s cost times the
length of the segment inside it. A shortcut may still cross a costlier cell when it saves
more elsewhere, but it never makes the path more expensive. The path should
come from PathFinder with the same neighborhood.
Steps of a stale path that now cross blocked cells are kept unless a clear
shortcut replaces them; smoothing never adds a blocked segment.
Pass the following body’s half size in cell units as clearance
(GridLayout::clearance), so shortcuts
keep it off wall corners; with zero, segments are checked as
lines between cell centers and a wide body can catch on a corner. Errors
leave the path unchanged for cells outside the grid or an invalid
clearance (see line_of_sight), but may leave it partly simplified
for a cost that is not finite and positive.