Registry / data / robust-in-sphere

robust-in-sphere

JSON →
library1.2.1jsnpmunverified

robust-in-sphere is a JavaScript library providing an exact arithmetic test to determine if a collection of `n+2` points in `n`-dimensional space are cospherical, or if the last point is contained within the sphere defined by the preceding `n+1` points. This library focuses on robust predicates to avoid floating-point errors, a common issue in computational geometry, drawing inspiration from Jonathan Shewchuk's seminal work. Currently at version 1.2.1, it was last published in 2014, suggesting a stable but not actively developed state. Its primary differentiator is the use of exact arithmetic for geometric predicates, ensuring reliability over speed for critical calculations. While not as fast as some alternatives, its exactness is crucial for applications requiring high precision in geometric computations.

npm install robust-in-sphere
INSTALL
IMPORT
SIG · ROBUST-IN-SPHERE
R
robust-in-sphere
datajavascriptv1.2.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

inSphere
const inSphere = require('robust-in-sphere')
import inSphere from 'robust-in-sphere'
This package is CommonJS-only, designed for Node.js environments prior to widespread ESM adoption. Direct ES module imports will not work.
inSphere[k]
const inSphere = require('robust-in-sphere'); const result = inSphere[4](p1, p2, p3, p4);
import { inSphere[4] } from 'robust-in-sphere'
The library exports specialized versions of `inSphere` for up to 6 points (e.g., `inSphere[4]` for 4 points) directly off the main `inSphere` function. These offer a performance optimization by avoiding an extra dispatch.

This quickstart demonstrates how to use `robust-in-sphere` to test point-in-sphere and cosphericity conditions for 2D and 3D points, illustrating the expected return values.

const inSphere = require("robust-in-sphere"); // Example for 2D (n=2), requiring n+2 = 4 points. // Tests if the last point ([0, -1]) is inside the circle defined by the first three points. // Returns <0 if inside, >0 if outside, 0 if cospherical. const result2D = inSphere( [0, 1], [1, 0], [-1, 0], [0, -1] ); console.log(`Result for 2D points: ${result2D}`); // Should be <0 as [0,-1] is inside the circle through [0,1], [1,0], [-1,0] // Example for 3D (n=3), requiring n+2 = 5 points. // Using a specialized version for 5 points (inSphere[5]) if available, or generic. // Points for a sphere centered at origin with radius 1. const p1 = [1, 0, 0]; const p2 = [0, 1, 0]; const p3 = [-1, 0, 0]; const p4 = [0, -1, 0]; const p5 = [0, 0, 0.5]; // Point inside the sphere const p6 = [0, 0, 2]; // Point outside the sphere const result3DInside = inSphere(p1, p2, p3, p4, p5); console.log(`Result for 3D point inside: ${result3DInside}`); // Should be <0 const result3DOutside = inSphere(p1, p2, p3, p4, p6); console.log(`Result for 3D point outside: ${result3DOutside}`); // Should be >0 const result3DCospherical = inSphere(p1, p2, p3, p4, [0,0,1]); console.log(`Result for 3D points cospherical: ${result3DCospherical}`); // Should be 0
Debug
Known issues
gotchaThe function `inSphere` expects `n+2` points for `n`-dimensional space. For example, for 2D points (n=2, forming a circle), you must provide 4 points. For 3D points (n=3, forming a sphere), you must provide 5 points. Providing an incorrect number of points will lead to incorrect results or runtime errors.
fix
Ensure the number of points passed to `inSphere` strictly adheres to the `n+2` rule for `n`-dimensional inputs.
affects: >=1.0.0
gotchaThis library is an older CommonJS module. Attempting to import it using ES module syntax (`import ... from 'robust-in-sphere'`) in an ES module context will result in a runtime error because `require` is not defined.
fix
Use `const inSphere = require('robust-in-sphere')` for all imports. If using with modern ES Modules, consider using a compatibility layer or a bundler that handles CJS modules, or rewrite the import to `import inSphere = require('robust-in-sphere')` in TypeScript.
affects: >=1.0.0
deprecatedThe package has not been updated since 2014, indicating it is likely abandoned. While it may still function for its intended purpose, it may not receive bug fixes, security updates, or compatibility improvements with newer JavaScript runtimes or build tools. Consider `robust-predicates` as a modern alternative.
fix
Evaluate migration to a more actively maintained library like `robust-predicates`, which is a modern port inspired by Mikola Lysenko's work and Shewchuk's robust predicates.
affects: >=1.0.0
Errors
Common errors & fixes
ReferenceError: require is not defined
Attempting to use `require` in an ES module context (e.g., a file with `"type": "module"` in `package.json` or a `.mjs` file).
fix
Change the file to CommonJS (`.js` without `"type": "module"`) or use a bundler that transpiles CommonJS modules into ES modules. Alternatively, migrate to an ES module-compatible library if available.
TypeError: inSphere is not a function
Incorrectly importing the `inSphere` function using ES module syntax (e.g., `import { inSphere } from 'robust-in-sphere'`) when the package only provides a default CommonJS export.
fix
Use the correct CommonJS import syntax: `const inSphere = require('robust-in-sphere')`.
The number of points provided is insufficient for the expected dimension.
Passing fewer than `n+2` points for an `n`-dimensional test. For example, passing 3 points for a 2D (circle) test, which requires 4 points.
fix
Always provide `n+2` points for an `n`-dimensional test. If you are testing cosphericity of 3D points, ensure 5 points are provided. If testing a point against a circle defined by two points in 2D, provide 4 points (the two defining points + the test point + an extra one to make it n+2 for n=2).
Upgrade
Version history
1.2.1latest on npm
Audit
Dependencies
robust-comparerequiredUsed for robust floating-point comparisons in geometric predicates.
robust-determinantrequiredUsed for calculating robust determinants, essential for cosphericity and in-sphere tests.
Agent activity
3 hits · last 30 days
node
2
OpenAI (training)
1
Resources
robust-in-sphere — npm install robust-in-sphere · libregistry