Fast robust predicates for computational geometry in JavaScript
Installations
npm install robust-predicates
Developer
mourner
Developer Guide
Module System
ESM
Min. Node Version
Typescript Support
Yes
Node Version
18.16.0
NPM Version
9.6.4
Statistics
304 Stars
92 Commits
17 Forks
12 Watching
2 Branches
4 Contributors
Updated on 20 Nov 2024
Bundle Size
24.13 kB
Minified
7.48 kB
Minified + Gzipped
Languages
JavaScript (100%)
Total Downloads
Cumulative downloads
Total Downloads
262,709,791
Last day
3.7%
770,177
Compared to previous day
Last week
4.3%
3,871,075
Compared to previous week
Last month
11.8%
15,941,401
Compared to previous month
Last year
87.3%
139,722,236
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
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, an industry standard since 1996.
Figure: non-robust vs robust orient2d
test for points within a tiny range (2-42).
Demo
API
Note: unlike J. Shewchuk's original code, all the functions in this library assume y
axis is oriented downwards ↓, so the semantics are different.
orient2d(ax,ay, bx,by, cx,cy)
- Returns a positive value if the points
a
,b
, andc
occur in counterclockwise order (c
lies to the left of the directed line defined by pointsa
andb
). - Returns a negative value if they occur in clockwise order (
c
lies to the right of the directed lineab
). - 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 througha
,b
, andc
. - 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 througha
,b
, andc
, meaning thata
,b
, andc
appear in counterclockwise order when viewed fromd
. - 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 througha
,b
,c
, andd
. - 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
1import {orient2d} from 'robust-predicates'; 2 3const 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 (all predicates)
- orient2d.min.js (
orient2d
,orient2dfast
) - orient3d.min.js (
orient3d
,orient3dfast
) - incircle.min.js (
incircle
,incirclefast
) - insphere.min.js (
insphere
,inspherefast
)
Thanks
This project is just a port — all the brilliant, hard work was done by Jonathan Richard Shewchuk.
The port was also inspired by Mikola Lysenko's excellent Robust Arithmetic Notes and related projects like robust-orientation and robust-in-sphere.
License
Since the original code is in the public domain, this project follows the same choice. See Unlicense.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: The Unlicense: LICENSE:0
Reason
2 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-gcx4-mw62-g8wm
Reason
Found 1/30 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/node.yml:1
- Info: no jobLevel write permissions found
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/node.yml:7: update your workflow using https://app.stepsecurity.io/secureworkflow/mourner/robust-predicates/node.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/node.yml:8: update your workflow using https://app.stepsecurity.io/secureworkflow/mourner/robust-predicates/node.yml/main?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/node.yml:14
- Info: 0 out of 2 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 1 npmCommand dependencies pinned
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'main'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 1 are checked with a SAST tool
Score
3.2
/10
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to robust-predicates
check-types
A little library for asserting types and values, with zero dependencies.
robust-orientation
Exactly computes the orientation of a tuple of points
@mui/x-charts-vendor
Vendored dependencies for MUI X Charts
robust-sum
Evaluates the sum of two nonoverlapping increasing sequences of floats