clipPolygon
Clips a polygon with a bounding box.
import {clipPolygon} from '@math.gl/polygon';
clipPolyline([-10, -10, 10, 10, 30, -10, -10, -10], [0, 0, 20, 20], {size: 2});
// returns [0, 0, 10, 10, 20, 0, 0, 0]
The clipping bounds are defined as an orthoganal rectangle on the XY plane. If a 3D polygon is supplied, it is clipped by the extuded volume from the bounding box.
Usage
clipPolygon(positions, bbox, [options]);
Arguments:
positions(Array|TypedArray) - a flat array of the vertex positions that define the polygon.bbox(Array) - the bounding box, in[minX, minY, maxX, maxY]options(Object, optional)size(Number) - the number of elements in each vertex. Size2will interpretpositionsas[x0, y0, x1, y1, ...]and size3will interpretpositionsas[x0, y0, z0, x1, y1, z1, ...]. Default2.startIndex(Number, optional) - the index inpositionsto start reading vertices. Default0.endIndex(Number, optional) - the index inpositionsto stop reading vertices. Defaultpositions.length.
Returns:
A positions array that describes the intersection of the original polygon and the bounding box. Uses the same vertex size as the input.
If the input polygon does not overlap with the bounding box, an empty array will be returned.