Registry / data / point-in-big-polygon

point-in-big-polygon

JSON →
library2.0.1jsnpmunverified

point-in-big-polygon is a JavaScript library providing an industrial-strength solution for the point-in-polygon problem. It specializes in classifying a single point against a potentially large and complex 2D polygon with high precision. The library preprocesses the polygon in O(n log(n)) time to create an optimized classification function, which then determines if any given point is inside, on the boundary, or outside the polygon in O(log(n)) operations. All internal computations utilize exact arithmetic, guaranteeing robust and precise results even with degenerate cases or floating-point inaccuracies. The current stable version is 2.0.1, and while its last major update was around 2014, it remains a reliable tool for specialized geospatial or geometric computations in CommonJS environments, including Node.js and browsers via bundlers like Browserify. Its primary differentiation lies in its optimized performance and exactness for single, complex polygons.

npm install point-in-big-polygon
INSTALL
IMPORT
SIG · POINT-IN-BIG-POLYG
P
point-in-big-polygon
datajavascriptv2.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.

preprocessPolygon
const preprocessPolygon = require('point-in-big-polygon')
import preprocessPolygon from 'point-in-big-polygon'
This library is exclusively CommonJS; direct ES module imports are not supported. The main export is a constructor/factory function.
classifyPoint
const classifyPoint = preprocessPolygon(loops)
const classifyPoint = require('point-in-big-polygon').classifyPoint
The `classifyPoint` function is the *result* of calling the main `preprocessPolygon` export with your polygon loops, not a direct export from the module.

Classifies points against a polygon with a hole and renders the result as an ASCII image to the console, illustrating inside (-), boundary (o), and outside (+) regions using the `classifyPoint` function.

const preprocessPolygon = require('point-in-big-polygon') //Define the polygon loops (outer loop clockwise, inner loop counter-clockwise assumed for holes) const loops = [ [ [-10, -10], [-10, 10], [10, 10], [10, -10] ], // Outer square [ [-1, -1], [1, -1], [1, 1], [-1, 1] ] // Inner square (hole) ] //Preprocess the polygon to get a classification function const classifyPoint = preprocessPolygon(loops) //Render polygon test in ASCII to console const img = [] for(let y=-12; y<=12; y+=1) { let row = [] for(let x=-12; x<=12; x+=0.5) { const v = classifyPoint([x, y]) if(v < 0) { row.push('-') // Inside } else if(v === 0) { row.push('o') // On boundary } else { row.push('+') // Outside } } img.push(row.join('')) } console.log(img.join('\n'))
Debug
Known issues
gotchaInput polygon loops must be 'manifold', meaning they cannot have self-intersections, dangling edges, or degenerate segments. Providing non-manifold input may lead to incorrect classification results, infinite loops, or runtime errors.
fix
Ensure all polygon loops adhere to manifold geometry constraints. Use a geometry validation library or careful construction to prevent invalid polygons.
affects: >=1.0.0
gotchaThis library is optimized for classifying points against a *single* large and complex polygon. If you need to classify points against multiple distinct polygons or regions efficiently, consider using 'point-in-region' instead for better performance and API suitability.
fix
For scenarios involving many distinct polygons, evaluate 'point-in-region'. For a single polygon, ensure input loops are correctly structured and meet manifold requirements.
affects: >=1.0.0
gotchaThe `classifyPoint` function returns an integer: -1 for 'inside', 0 for 'on boundary', and +1 for 'outside'. Be mindful of this convention, as other point-in-polygon libraries might return booleans or different numeric codes.
fix
Explicitly check `if (v < 0)` for inside, `if (v === 0)` for on boundary, and `if (v > 0)` for outside when interpreting results.
affects: >=1.0.0
gotchaPoints and polygon vertices are expected as arrays of two numbers, e.g., `[x, y]`. Providing objects (like `{x: 1, y: 2}`) or other data structures will result in runtime errors.
fix
Always pass coordinates as `[x, y]` arrays for both polygon vertices and points to be classified.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: loops.forEach is not a function
The `loops` argument provided to the `preprocessPolygon` constructor is not an array, or not an array of arrays.
fix
Ensure `loops` is an array where each element is itself an array of `[x, y]` points representing a polygon loop. Example: `[[[0,0],[1,0],[1,1]], [[0.1,0.1],[0.9,0.1],[0.9,0.9]]]`
TypeError: Cannot read properties of undefined (reading '0') / Cannot read property 'length' of undefined
An input point or polygon vertex is not a valid 2-element array (e.g., `[x, y]`), or a loop itself is empty/malformed.
fix
Verify all points and vertices are correctly formatted as `[x, y]` arrays and that no loops are empty or contain fewer than 3 vertices.
RangeError: Maximum call stack size exceeded
The input polygon contains highly degenerate edges, self-intersections, or is extremely complex, stressing the exact arithmetic or spatial indexing algorithm.
fix
Simplify the polygon if possible, remove duplicate vertices, or pre-validate its manifold properties. For extreme cases where exactness is not strictly required, consider alternative approximate point-in-polygon algorithms.
Upgrade
Version history
2.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
point-in-big-polygon — npm install point-in-big-polygon · libregistry