# path-intersection

> Computes the intersection between two SVG paths

Latest version **4.1.0** (published 2026-01-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install path-intersection
pnpm add path-intersection
yarn add path-intersection
bun add path-intersection
```

## Health

**Score 65/100 (B)** — status: stable.

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

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 4.1.0 |
| Published | 2026-01-21 |
| First published | 2017-12-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >= 14.20 |
| Dependencies | 0 |
| Unpacked size | 31.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 121 |
| Author | Nico Rehwaldt |
| Maintainers | bpmn-io-admin, nikku, barmac, philippfromme, maxtru, skaiir-camunda, vsgoulart, jarekdanielak, alekseymanetov, simon-steinruecken-camunda |
| Keywords | svg, path, path intersection |

## Links

- npm: https://www.npmjs.com/package/path-intersection
- Repository: https://github.com/bpmn-io/path-intersection
- Homepage: https://github.com/bpmn-io/path-intersection#readme
- Issues: https://github.com/bpmn-io/path-intersection/issues
- npm.io page: https://npm.io/package/path-intersection

## Alternatives

- [base64url](https://npm.io/package/base64url.md) — 6.1M weekly downloads
- [get-installed-path](https://npm.io/package/get-installed-path.md) — 502.9K weekly downloads
- [@uppy/url](https://npm.io/package/@uppy/url.md) — 185.8K weekly downloads
- [@d3fc/d3fc-shape](https://npm.io/package/@d3fc/d3fc-shape.md) — 16.2K weekly downloads
- [localizer](https://npm.io/package/localizer.md) — 226 weekly downloads

## Recent versions

- 4.1.0 (latest) — 2026-01-21
- 4.0.1 — 2025-11-25
- 4.0.0 — 2025-11-24
- 3.1.0 — 2024-03-11
- 3.0.0 — 2023-12-14
- 2.2.1 — 2021-03-15
- 2.2.0 — 2020-01-17
- 2.1.0 — 2019-12-15
- 2.0.2 — 2019-12-15
- 2.0.1 — 2019-12-12
- 2.0.0 — 2019-12-12
- 1.1.1 — 2018-06-10
- 1.1.0 — 2018-05-06
- 1.0.2 — 2017-12-13
- 1.0.1 — 2017-12-13
- … 1 more at https://npm.io/package/path-intersection/versions

## README

# path-intersection

[![CI](https://github.com/bpmn-io/path-intersection/workflows/CI/badge.svg)](https://github.com/bpmn-io/path-intersection/actions?query=workflow%3ACI)

Computes the intersection between two SVG paths.


## Examples

<img width="600" src="https://raw.githubusercontent.com/bpmn-io/path-intersection/master/resources/examples.png" alt="Intersection examples" />

Execute `npm run dev` and navigate to [`http://localhost:9876/debug.html`](http://localhost:9876/debug.html) to see more examples.


## Usage

```javascript
import intersect from 'path-intersection';

const path0 = 'M30,100L270,20';
const path1 = 'M150,150m0,-18a18,18,0,1,1,0,36a18,18,0,1,1,0,-36z';

const intersection = intersect(path0, path1);
// [ { x: ..., y: ..., segment1: ..., segment2: ... }, ... ]
```

Results are approximate, as we use [bezier clipping](https://math.stackexchange.com/questions/118937) to find intersections.


## Path Caching

Where performance matters, you can pre-parse paths and cache them:

```javascript
import intersect, { parsePath } from 'path-intersection';

// parse paths once
const path1 = parsePath('M0,0L100,100');
const path2 = parsePath('M0,100L100,0');

// they won't be re-parsed during intersection checking
const result1 = intersect(path1, path2);
const result2 = intersect(path2, path2);
```

For repeated calculations, this optimization can result in substantial performance improvements.


## Building the Project

```
# install dependencies
npm install

# build and test the library
npm run all
```


## Credits

The intersection logic provided by this library is derived from [`path.js`](https://github.com/adobe-webplatform/Snap.svg/blob/master/src/path.js), a part of [Snap.svg](https://github.com/adobe-webplatform/Snap.svg).


## License

Use under the terms of the [MIT license](http://opensource.org/licenses/MIT).

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