Navigation · function

nearestPoly

The polygon a point is in, or the nearest within extent. -1 beyond it. The point and the extent are in metres, which the mesh's placement turns into its cells.

Explained in Navigation.

function nearestPoly(mesh: PolyMesh, x: number, z: number, extent: number): number
import { nearestPoly } from '@driftengine/nav';

Parameters

ParameterTypeDescription
meshPolyMesh
xnumber
znumber
extentnumber

In depth

-1 rather than the nearest whatever the distance, because an agent asked to walk to a place that is not on the mesh has to be told. Snapping across the map produces a path to somewhere nobody asked for, which is worse than no path at all.