# line-intersect

> Line vs line, point vs line in 2D space

Latest version **3.0.0** (published 2021-02-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install line-intersect
pnpm add line-intersect
yarn add line-intersect
bun add line-intersect
```

## Health

**Score 30/100 (F)** — status: abandoned.

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

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.0 |
| Published | 2021-02-04 |
| First published | 2014-10-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 11.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 25 |
| Author | Paul Salaets |
| Maintainers | psalaets |
| Keywords | line, segment, intersect, 2d |

## Links

- npm: https://www.npmjs.com/package/line-intersect
- Repository: https://github.com/psalaets/line-intersect
- Issues: https://github.com/psalaets/line-intersect/issues
- npm.io page: https://npm.io/package/line-intersect

## Alternatives

- [localforage](https://npm.io/package/localforage.md) — 6.2M weekly downloads
- [localforage-observable](https://npm.io/package/localforage-observable.md) — 30.8K weekly downloads
- [@y/y](https://npm.io/package/@y/y.md) — 30.1K weekly downloads
- [@metaobjectsdev/render](https://npm.io/package/@metaobjectsdev/render.md) — 3.5K weekly downloads
- [@ledgerhq/coin-algorand](https://npm.io/package/@ledgerhq/coin-algorand.md) — 1.1K weekly downloads

## Recent versions

- 3.0.0 (latest) — 2021-02-04
- 2.2.4 — 2020-07-13
- 2.2.3 — 2019-10-10
- 2.2.2 — 2019-10-08
- 2.2.1 — 2019-05-23
- 2.2.0 — 2018-12-05
- 2.1.1 — 2018-02-21
- 2.1.0 — 2018-02-21
- 2.0.0 — 2018-02-18
- 1.0.0 — 2014-10-29

## README

# line-intersect

Line vs line, point vs line in 2D space

Math is mostly from [here](https://web.archive.org/web/20060808212243/http://local.wasp.uwa.edu.au/~pbourke/geometry/lineline2d).

## Install

```bash
npm install line-intersect
```

## API

es modules

```js
import {
  checkIntersection,
  colinearPointWithinSegment
} from 'line-intersect';
```

commonjs modules

```js
const {
  checkIntersection,
  colinearPointWithinSegment
} = require('line-intersect');
```

### checkIntersection(x1, y1, x2, y2, x3, y3, x4, y4)

Given a line segment from (x1, y1) to (x2, y2) and line segment from (x3, y3) to (x4, y4), check if the line segments intersect.

#### Parameters

- x1, y1, x2, y2 - 1st line segment
- x3, y3, x4, y4 - 2nd line segment

All params are Numbers and are required.

#### Returns

A read-only Object that looks like

```js
{
  type: 'none' | 'parallel' | 'colinear'
}

// or

{
  type: 'intersecting',
  point: {
    x: number,
    y: number
  }
}
```

`point` is only exists when `type == 'intersecting'`

| `type` | What it means | Are the line segments touching? |
|-----------------|-----------------------------------------------------------------------|----|
| none          | Line segments are not intersecting                                  | No |
| parallel      | Line segments are not intersecting but they are parallel to eachother | No |
| colinear      | Line segments are on the same line and *may* be overlapping. Use `colinearPointWithinSegment()` to check | Maybe |
| intersecting  | Line segments intersect at exactly one point | Yes |

### colinearPointWithinSegment(px, py, x1, y1, x2, y2)

Given a point (px, py) that is on the same line as line segment (x1, y1) to (x2, y2), check if the point is within the line segment.

#### Parameters

- px, py - Point to check
- x1, y1, x2, y2 - Line segment

All params are Numbers and are required.

#### Returns

`true` if point is within the line segment, `false` otherwise.

## License

MIT

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