cutPolylineByGrid
Subdivides a polyline by intersecting with a uniform grid.
import {cutPolylineByGrid} from '@math.gl/polygon';
cutPolylineByGrid([-10, -10, 10, 10, 30, -10], {size: 2, gridResolution: 10});
// returns [-10, -10, 0, 0, 10, 10, 20, 0, 30, -10]
Usage
cutPolylineByGrid(positions, [options]);
Arguments:
positions
(Array|TypedArray) - a flat array of the vertex positions that define the polyline.options
(Object, optional)size
(Number) - the number of elements in each vertex. Size2
will interpretpositions
as[x0, y0, x1, y1, ...]
and size3
will interpretpositions
as[x0, y0, z0, x1, y1, z1, ...]
. Default2
.startIndex
(Number, optional) - the index inpositions
to start reading vertices. Default0
.endIndex
(Number, optional) - the index inpositions
to stop reading vertices. Defaultpositions.length
.gridResolution
(Number, optional) - the grid size. Default10
.gridOffset
(Array, optional) - the grid offset in[x, y]
. Default[0, 0]
i.e. the grid starts from the coordinate origin.broken
(Boolean, optional) - iftrue
, the polyline is broken into multiple polylines at the subdivision points. Iffalse
, subdivision points are inserted into the original polyline. Defaultfalse
.
Returns:
A polyline or an array of polylines, depending on the broken
option. Each polyline is represented by a positions array that uses the same vertex size as the input.