
Security News
MCP Community Begins Work on Official MCP Metaregistry
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.
robust-predicates
Advanced tools
The robust-predicates package provides robust geometric predicates that are used to perform orientation and incircle tests on 2D and 3D points. These predicates are designed to return exact results, which is crucial in computational geometry to avoid errors due to floating-point arithmetic.
Orientation tests
This feature allows you to determine the orientation of three points in 2D space. The function returns a positive value if the points are in counterclockwise order, zero if they are collinear, and a negative value if they are in clockwise order.
const rp = require('robust-predicates');
const result = rp.orient2d([0, 0], [1, 1], [1, 0]);
console.log(result); // Outputs a positive or negative value indicating the orientation
Incircle tests
This feature checks whether a point is inside, on the edge, or outside the circle defined by three other points in 2D space. The function returns a positive value if the point is inside, zero if on the circle, and a negative value if outside.
const rp = require('robust-predicates');
const result = rp.incircle([0, 0], [1, 0], [0, 1], [1, 1]);
console.log(result); // Outputs a positive, zero, or negative value based on the point's position relative to the circle
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).
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)
a
, b
, and c
occur in counterclockwise order (c
lies to the left of the directed line defined by points a
and b
).c
lies to the right of the directed line ab
).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)
d
lies outside the circle passing through a
, b
, and c
.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)
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
.d
lies below the plane.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)
e
lies outside the sphere passing through a
, b
, c
, and d
.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.
import {orient2d} from 'robust-predicates';
const ccw = orient2d(ax, ay, bx, by, cx, cy) > 0;
Install with npm install robust-predicates
or yarn add robust-predicates
, or use one of the browser builds:
orient2d
, orient2dfast
)orient3d
, orient3dfast
)incircle
, incirclefast
)insphere
, inspherefast
)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.
Since the original code is in the public domain, this project follows the same choice. See Unlicense.
FAQs
Fast robust predicates for computational geometry
The npm package robust-predicates receives a total of 2,765,129 weekly downloads. As such, robust-predicates popularity was classified as popular.
We found that robust-predicates demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.
Research
Security News
Socket uncovers an npm Trojan stealing crypto wallets and BullX credentials via obfuscated code and Telegram exfiltration.
Research
Security News
Malicious npm packages posing as developer tools target macOS Cursor IDE users, stealing credentials and modifying files to gain persistent backdoor access.