lineclip
DefinitelyTyped icon, indicating that this package has TypeScript declarations provided by the separate @types/lineclip package

1.1.5 • Public • Published

lineclip

Build Status Coverage Status

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

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

API

lineclip.polyline(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.

lineclip.polygon(points, bbox)

Returns a clipped polygon.

Install

Install with NPM:

npm install lineclip

To build a browser-compatible version, clone the repository locally, then run:

npm install -g browserify
browserify -s lineclip index.js > lineclip.js

Changelog

1.1.5 (Sep 23, 2015)

  • Fixed a bug where polygon clip broke on out-of-bbox polygons.

1.1.4 (Sep 22, 2015)

  • Fixed a bug where last point was omitted if the last two points are in bbox.
  • Fixed a bug where a line outside of bbox would produce [[]] instead of [].

1.1.3 (Sep 12, 2015)

  • Fixed a polygon clipping race condition.

1.1.2 (Sep 11, 2015)

  • Fixed a bug that completely broke the clipping on many cases. Sorry!

1.1.1 (Sep 11, 2015)

  • Fixed a polyline clipping edge case.

1.1.0 (Sep 11, 2015)

  • Added Sutherland-Hodgeman polygon clipping (lineclip.polygon).

1.0.1 (Sep 11, 2015)

  • Minor code cleanup and optimizations.

1.0.0 (Sep 8, 2015)

  • Initial release.

Package Sidebar

Install

npm i lineclip

Weekly Downloads

103,295

Version

1.1.5

License

ISC

Last publish

Collaborators

  • mbx-npm-ci-production
  • mbx-npm-ci-staging
  • mbx-npm-advanced-actions-production
  • mbx-npm-advanced-actions-staging
  • mbx-npm-09-production
  • mbx-npm-08-production
  • mbx-npm-07-production
  • mbx-npm-06-production
  • mbx-npm-05-production
  • mbx-npm-04-production
  • mbx-npm-03-production
  • mbx-npm-02-production
  • mbx-npm-01-production
  • mbx-npm-02-staging
  • mapbox-npm-01
  • mapbox-npm-02
  • mapbox-npm-07
  • mapbox-npm-03
  • mapbox-npm-04
  • mapbox-npm-09
  • mapbox-npm-05
  • mapbox-npm-06
  • mapbox-npm-08
  • mapbox-npm-advanced-actions
  • mapbox-npm-ci
  • mapbox-npm
  • mapbox-admin
  • mapbox-machine-user