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-haoVerified import paths — ran on the pinned version, not inferred.
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.
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]]`.
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.
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.
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.
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]]`.
No dependency data recorded yet.