Skip to content

mapbox/lineclip

lineclip Simply Awesome

A very fast JavaScript library for clipping polylines and polygons by a bounding box.

import {clipPolyline} from 'lineclip';

clipPolyline(
    [[-10, 10], [10, 10], [10, -10]], // line
    [0, 0, 20, 20]); // bbox
// returns [[[0, 10], [10, 10], [10, 0]]]

API

clipPolyline(points, bbox[, result])

  • points — an array of [x, y] points
  • bbox — a bounding box as [xmin, ymin, xmax, ymax]
  • result — an array to append the results to

Returns an array of clipped lines.

lineclip is an alias to lineclip.polyline.

clipPolygon(points, bbox)

Returns a clipped polygon.

About

A very fast JavaScript polyline and polygon clipping library

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

No packages published

Contributors 6