Registry / data / robust-segment-intersect

robust-segment-intersect

JSON →
library1.0.1jsnpmunverified

This library, `robust-segment-intersect`, provides an exact arithmetic predicate to rigorously determine if two closed 2D line segments intersect. It is designed to overcome floating-point inaccuracies common in geometric computations, ensuring reliable results even in degenerate cases where endpoints are collinear or nearly so. The current stable version is 1.0.1, last published in 2014. As an older package, it is considered abandoned, meaning active development and new features are unlikely, though it remains functional for its specific purpose. Its primary differentiator lies in its 'exact arithmetic' approach, which prioritizes correctness over raw speed for applications requiring absolute precision in geometric intersection tests, such as CAD, GIS, and advanced rendering algorithms. Users should be aware of its CommonJS module format and consider its age when integrating into modern projects.

npm install robust-segment-intersect
INSTALL
IMPORT
SIG · ROBUST-SEGMENT-INT
R
robust-segment-intersect
datajavascriptv1.0.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.

crosses
const crosses = require("robust-segment-intersect")
This package is published as a CommonJS module, primarily exporting a single function.
crosses
import crosses from "robust-segment-intersect"
import { crosses } from 'robust-segment-intersect'
For ESM environments, bundlers often handle CommonJS interop, making a default import viable. Named imports will fail as the module does not export named members.
intersect
const intersect = require("robust-segment-intersect"); intersect(a0, a1, b0, b1);
The `require` call directly returns the intersection function, which can be invoked immediately or assigned to any variable name.

Demonstrates how to import the `robust-segment-intersect` function and use it to check for intersection between two 2D line segments defined by their endpoints.

const crosses = require("robust-segment-intersect") const a0 = [-1, 0] const a1 = [ 1, 0] const b0 = [ 0,-1] const b1 = [ 0, 1] // Check if line segment [a0, a1] crosses segment [b0, b1] const doCross = crosses(a0, a1, b0, b1); console.log(`Segments intersect: ${doCross}`); // Expected: true const c0 = [0, 0]; const c1 = [1, 1]; const d0 = [0, 1]; const d1 = [1, 0]; const doCross2 = crosses(c0, c1, d0, d1); console.log(`Segments intersect: ${doCross2}`); // Expected: true (cross at [0.5, 0.5])
Debug
Known issues
breakingThis package is considered abandoned, with its last release (v1.0.1) in 2014. While functional, it receives no active development, bug fixes, or security updates. Users should evaluate its suitability for new projects carefully and be prepared for potential compatibility issues with newer JavaScript ecosystems.
fix
Consider mirroring the repository or migrating to a more actively maintained geometric library if long-term support or new features are required. For its specific functionality, it remains stable.
affects: >=1.0.1
gotchaThe package is published as CommonJS only. When used in an ESM-first environment (e.g., Node.js with 'type: module' or modern browser applications without proper bundling), direct named imports (`import { crosses } from 'robust-segment-intersect'`) will fail.
fix
For ESM, use a default import: `import crosses from 'robust-segment-intersect'`. If `require` is unavailable, ensure your build setup (e.g., Webpack, Rollup) correctly handles CommonJS module interoperability.
affects: >=1.0.1
gotchaThe function strictly expects all four segment endpoints (`a0, a1, b0, b1`) to be 2-element arrays representing 2D coordinates (e.g., `[x, y]`). Providing points in other formats (e.g., objects `{x:0, y:0}`, arrays of different lengths, or `null`/`undefined` values) will lead to incorrect results or runtime errors.
fix
Always pass points as `[x, y]` arrays. Validate input points before calling the function to ensure they conform to the expected `length 2` array structure.
affects: >=1.0.1
gotchaWhile robust, the exact arithmetic methods used can be computationally more intensive than approximate floating-point methods. For applications where absolute precision in degenerate cases is not critical and raw performance is paramount, alternative, less robust geometric libraries might offer better speed.
fix
Benchmarking is recommended if performance is a critical factor. For non-critical applications, the precision benefits typically outweigh the minor performance overhead.
affects: >=1.0.1
Errors
Common errors & fixes
TypeError: (0 , _robustSegmentIntersect.crosses) is not a function
Attempting to use a named import (`import { crosses } from 'robust-segment-intersect'`) in an ESM context for a CommonJS module that exports a single function as its default.
fix
Use a default import instead: `import crosses from 'robust-segment-intersect';` or stick to CommonJS `const crosses = require('robust-segment-intersect');`.
TypeError: Cannot read properties of undefined (reading '1')
One of the segment endpoint arguments (`a0, a1, b0, b1`) was `null`, `undefined`, or not a valid 2-element array (e.g., an empty array `[]` or a single-element array `[0]`).
fix
Ensure all four arguments passed to `robust-segment-intersect` are valid 2-element arrays, like `[x, y]`, representing the coordinates of the segment endpoints.
ReferenceError: require is not defined
Trying to use `require()` in an environment that does not support it natively (e.g., a pure ESM module in Node.js, or a browser environment without a bundler to transpile CommonJS).
fix
For browser usage, bundle your code with a tool like Webpack or Rollup that handles CommonJS modules. For Node.js ESM projects, use `import crosses from 'robust-segment-intersect';` instead of `require`.
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
14 hits · last 30 days
node
12
OpenAI (training)
2
Resources