Registry / data / point-in-polygon-hao

point-in-polygon-hao

JSON →
library1.2.4jsnpmunverified

point-in-polygon-hao is a small, specialized JavaScript library designed to determine if a given point lies inside a polygon. It is currently stable at version 1.2.4 and receives updates as needed for bug fixes and performance improvements, such as the recent v1.2.4 release addressing an edge intersection regression. A key differentiator is its reliance on the 'Optimal Reliable Point-in-Polygon Test' algorithm, which enables robust handling of complex geometries, including polygons with holes and degenerate or self-intersecting polygons, without being susceptible to common floating-point errors. Unlike some alternatives, it explicitly returns `0` for points lying directly on a polygon edge. The library strictly adheres to the GeoJSON polygon format, requiring the first and last coordinates of a ring to be identical, and does not support MultiPolygon inputs.

npm install point-in-polygon-hao
INSTALL
IMPORT
SIG · POINT-IN-POLYGON-H
P
point-in-polygon-hao
datajavascriptv1.2.4
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.

inside
import inside from 'point-in-polygon-hao'
const inside = require('point-in-polygon-hao')
The library primarily uses a default export for its main 'inside' function. While CommonJS `require` might work in some environments, ESM `import` is the recommended and standard approach for modern JavaScript and TypeScript projects.
inside (named)
import { inside } from 'point-in-polygon-hao'
Although the primary export is default, some bundlers or environments might allow named import of 'inside' for convenience. However, the default import is the intended and more reliable way.
Point, Polygon
import type { Point, Polygon } from 'point-in-polygon-hao'
import { Point, Polygon } from 'point-in-polygon-hao'
Type imports should explicitly use `import type` to avoid bundling issues and clearly distinguish them from runtime values. These types define the GeoJSON-like array structures for points ([x, y]) and polygons (array of rings).

Demonstrates basic usage of the `inside` function for checking points against simple polygons and polygons with holes, including edge detection and the GeoJSON-like input format.

import inside from 'point-in-polygon-hao'; const polygon = [ [ [1, 1], [1, 2], [2, 2], [2, 1], [1, 1] ] ]; const polygonWithHole = [ [ [0, 0], [10, 0], [10, 10], [0, 10], [0, 0] ], [ [2, 2], [2, 8], [8, 8], [8, 2], [2, 2] ] ]; console.log('Point [1.5, 1.5] in simple polygon:', inside([1.5, 1.5], polygon)); // Expected: true console.log('Point [1, 2] on simple polygon edge:', inside([1, 2], polygon)); // Expected: 0 console.log('Point [5, 5] in polygon with hole:', inside([5, 5], polygonWithHole)); // Expected: false (due to hole) console.log('Point [0.5, 0.5] in polygon with hole (outside hole):', inside([0.5, 0.5], polygonWithHole)); // Expected: true // Example of invalid polygon (unclosed ring) which would throw an error if not handled: // try { // inside([0.5, 0.5], [[[0,0], [1,0], [1,1]]]); // } catch (e) { // console.error('Error with unclosed polygon:', e.message); // }
Debug
Known issues
breakingThe library strictly enforces the GeoJSON specification for polygon rings, requiring the first and last coordinates of each ring to be identical. Failure to close a ring will result in an error.
fix
Ensure all polygon rings (outer boundary and holes) are closed by repeating the initial coordinate at the end of the coordinate array, e.g., `[[x1,y1], [x2,y2], [x3,y3], [x1,y1]]`.
affects: >=1.0.0
gotchaThis library explicitly does not support GeoJSON MultiPolygon geometries. It expects a single polygon definition, which can include multiple rings for holes.
fix
If working with MultiPolygon data, you will need to iterate over each individual polygon within the MultiPolygon and apply the `inside` function separately. Consider preprocessing your GeoJSON to extract single polygons.
affects: >=1.0.0
gotchaThe `inside` function returns `0` when a point lies directly on the boundary (edge) of the polygon, `true` for inside, and `false` for outside. This tri-state return value might require explicit checks in applications expecting only boolean `true/false`.
fix
When consuming the result, perform checks like `result === true` for strictly inside, `result === 0` for on-edge, or `result !== false` to include both inside and on-edge points.
affects: >=1.0.0
gotchaWhile designed for robustness against floating-point errors, large-scale or extremely complex geometries might still encounter edge cases. Version 1.2.0 introduced `robust-predicates` to further mitigate these.
fix
For critical applications involving very high precision or complex scenarios, thorough testing with representative data is always recommended. Report any observed floating-point related issues to the maintainers with minimal reproducible examples.
affects: >=1.2.0
Errors
Common errors & fixes
Error: Input polygon ring is not closed. The first and last coordinate must be identical.
The input polygon array for a ring (either the outer boundary or a hole) does not have its first and last coordinates matching.
fix
Modify your polygon data to ensure each ring explicitly closes by repeating its starting coordinate at the end. For example, `[[0,0], [1,0], [1,1], [0,0]]`.
Upgrade
Version history
1.2.4latest on npm
Audit
Dependencies

No dependency data recorded yet.

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