# robust-predicates

> Fast robust predicates for computational geometry

Latest version **3.0.3** (published 2026-03-22) · Unlicense license · 0 weekly downloads

## Install

```sh
npm install robust-predicates
pnpm add robust-predicates
yarn add robust-predicates
bun add robust-predicates
```

## Health

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

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

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 3.0.3 |
| Published | 2026-03-22 |
| First published | 2019-09-01 |
| Weekly downloads | 0 |
| License | Unlicense |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 286.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 341 |
| Author | Vladimir Agafonkin |
| Maintainers | mourner |
| Keywords | computational geometry, robust arithmetic |

## Links

- npm: https://www.npmjs.com/package/robust-predicates
- Repository: https://github.com/mourner/robust-predicates
- Homepage: https://github.com/mourner/robust-predicates#readme
- Issues: https://github.com/mourner/robust-predicates/issues
- npm.io page: https://npm.io/package/robust-predicates

## Recent versions

- 3.0.3 (latest) — 2026-03-22
- 3.0.2 — 2023-05-25
- 3.0.1 — 2021-04-05
- 3.0.0 — 2021-02-08
- 2.0.4 — 2019-09-10
- 2.0.3 — 2019-09-04
- 2.0.2 — 2019-09-03
- 2.0.1 — 2019-09-02
- 2.0.0 — 2019-09-02
- 1.1.0 — 2019-09-01
- 1.0.0 — 2019-09-01
- 0.1.0 — 2019-09-01

## README

# robust-predicates

Fast robust predicates for computational geometry in JavaScript. Provides reliable 2D and 3D point orientation tests (`orient2d`, `orient3d`, `incircle`, `insphere`) that are not susceptible to floating point errors (without sacrificing performance). A modern port of [Jonathan R Shewchuk's C code](https://www.cs.cmu.edu/~quake/robust.html), an industry standard since 1996.

<a href="https://observablehq.com/@mourner/non-robust-arithmetic-as-art"><img width="600" height="200" src="predicates.png" /></a>

_Figure: non-robust vs robust `orient2d` test for points within a tiny range (2<sup>-42</sup>)._

[![Build Status](https://github.com/mourner/robust-predicates/actions/workflows/node.yml/badge.svg)](https://github.com/mourner/robust-predicates/actions/workflows/node.yml)
[![Simply Awesome](https://img.shields.io/badge/simply-awesome-brightgreen.svg)](https://github.com/mourner/projects)
[![Browser Build](https://img.shields.io/bundlephobia/minzip/robust-predicates)](https://unpkg.com/robust-predicates)

## [Demo](https://observablehq.com/@mourner/non-robust-arithmetic-as-art)

## API

Note: unlike J. Shewchuk's original code, all the functions in this library assume `y` axis is oriented _downwards_ &darr;, so the semantics are different.

### `orient2d(ax,ay, bx,by, cx,cy)`

- Returns a *positive* value if the points `a`, `b`, and `c` occur in _counterclockwise_ order (`c` lies to the left of the directed line defined by points `a` and `b`).
- Returns a *negative* value if they occur in _clockwise_ order (`c` lies to the right of the directed line `ab`).
- Returns *zero* if they are _collinear_.

The result is also an approximation of twice the signed area of the triangle defined by the three points.

### `incircle(ax,ay, bx,by, cx,cy, dx,dy)`

- Returns a _positive_ value if the point `d` lies _outside_ the circle passing through `a`, `b`, and `c`.
- Returns a _negative_ value if it lies _inside_.
- Returns _zero_ if the four points are _cocircular_.

The points `a`, `b`, and `c` must be in _counterclockwise_ order, or the sign of the result will be reversed.

### `orient3d(ax,ay,az, bx,by,bz, cx,cy,cz, dx,dy,dz)`

- Returns a _positive_ value if the point `d` lies _above_ the plane passing through `a`, `b`, and `c`, meaning that `a`, `b`, and `c` appear in counterclockwise order when viewed from `d`.
- Returns a _negative_ value if `d` lies _below_ the plane.
- Returns _zero_ if the points are _coplanar_.

The result is also an approximation of six times the signed volume of the tetrahedron defined by the four points.

### `insphere(ax,ay,az, bx,by,bz, cx,cy,cz, dx,dy,dz, ex,ey,ez)`

- Returns a _positive_ value if the point `e` lies _outside_ the sphere passing through `a`, `b`, `c`, and `d`.
- Returns a _negative_ value if it lies _inside_.
- Returns _zero_ if the five points are _cospherical_.

The points `a`, `b`, `c`, and `d` must be ordered so that they have a _positive orientation_
(as defined by `orient3d`), or the sign of the result will be reversed.

### `orient2dfast`, `orient3dfast`, `incirclefast`, `inspherefast`

Simple, approximate, non-robust versions of predicates above. Use when robustness isn't needed.

## Example

```js
import {orient2d} from 'robust-predicates';

const ccw = orient2d(ax, ay, bx, by, cx, cy) > 0;
````

## Install

Install with `npm install robust-predicates` or `yarn add robust-predicates`, or use one of the browser builds:

- [predicates.min.js](https://unpkg.com/robust-predicates/umd/predicates.min.js) (all predicates)
- [orient2d.min.js](https://unpkg.com/robust-predicates/umd/orient2d.min.js) (`orient2d`, `orient2dfast`)
- [orient3d.min.js](https://unpkg.com/robust-predicates/umd/orient3d.min.js) (`orient3d`, `orient3dfast`)
- [incircle.min.js](https://unpkg.com/robust-predicates/umd/incircle.min.js) (`incircle`, `incirclefast`)
- [insphere.min.js](https://unpkg.com/robust-predicates/umd/insphere.min.js) (`insphere`, `inspherefast`)

## Thanks

This project is just a port — all the brilliant, hard work was done by [Jonathan Richard Shewchuk](https://people.eecs.berkeley.edu/~jrs/).

The port was also inspired by [Mikola Lysenko](https://twitter.com/MikolaLysenko)'s excellent [Robust Arithmetic Notes](https://github.com/mikolalysenko/robust-arithmetic-notes) and related projects like [robust-orientation](https://github.com/mikolalysenko/robust-orientation) and [robust-in-sphere](https://github.com/mikolalysenko/robust-in-sphere).

## License

Since the original code is in the public domain, this project follows the same choice. See [Unlicense](https://unlicense.org).

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