# lineclip

> A fast polyline and polygon clipping library.

Latest version **2.0.0** (published 2025-07-16) · ISC license · 0 weekly downloads

## Install

```sh
npm install lineclip
pnpm add lineclip
yarn add lineclip
bun add lineclip
```

## Health

**Score 48/100 (D)** — status: stable.

Positive: has types package; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2025-07-16 |
| First published | 2015-09-08 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | separate (@types/lineclip) |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 10.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 184 |
| Author | Vladimir Agafonkin |
| Maintainers | 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, mbx-npm-ci-staging, mbx-npm-ci-production, mbx-npm-01-production, mbx-npm-02-production, mbx-npm-03-production, mbx-npm-04-production, mbx-npm-05-production, mbx-npm-06-production, mbx-npm-07-production, mbx-npm-08-production, mbx-npm-09-production, mbx-npm-02-staging, mbx-npm-advanced-actions-staging, mbx-npm-advanced-actions-production |
| Keywords | algorithm, line, polyline, polygon, geometry, clip, geo, cohen-sutherland |

## Links

- npm: https://www.npmjs.com/package/lineclip
- Repository: https://github.com/mapbox/lineclip
- Homepage: https://github.com/mapbox/lineclip#readme
- Issues: https://github.com/mapbox/lineclip/issues
- npm.io page: https://npm.io/package/lineclip

## Alternatives

- [@salesforce/cli](https://npm.io/package/@salesforce/cli.md) — 389.7K weekly downloads
- [@mintlify/cli](https://npm.io/package/@mintlify/cli.md) — 208.9K weekly downloads
- [@grafana/e2e-selectors](https://npm.io/package/@grafana/e2e-selectors.md) — 128.7K weekly downloads
- [mintlify](https://npm.io/package/mintlify.md) — 112.0K weekly downloads
- [@intlayer/cli](https://npm.io/package/@intlayer/cli.md) — 22.8K weekly downloads

## Recent versions

- 2.0.0 (latest) — 2025-07-16
- 1.1.5 — 2015-09-23
- 1.1.4 — 2015-09-22
- 1.1.3 — 2015-09-11
- 1.1.2 — 2015-09-11
- 1.1.0 — 2015-09-11
- 1.0.1 — 2015-09-11
- 1.0.0 — 2015-09-08

## README

## lineclip

[![Build Status](https://travis-ci.org/mapbox/lineclip.svg?branch=master)](https://travis-ci.org/mapbox/lineclip)
[![Coverage Status](https://coveralls.io/repos/mapbox/lineclip/badge.svg?branch=master&service=github)](https://coveralls.io/github/mapbox/lineclip?branch=master)

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

- uses [Cohen-Sutherland algorithm](https://en.wikipedia.org/wiki/Cohen%E2%80%93Sutherland_algorithm) for line clipping
- uses [Sutherland-Hodgman algorithm](https://en.wikipedia.org/wiki/Sutherland%E2%80%93Hodgman_algorithm) for polygon clipping

```js
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.

### 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.

---
_Source: https://npm.io/package/lineclip · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
