{"library":"point-in-polygon-hao","title":"Point in Polygon (HAO Algorithm)","description":"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.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install point-in-polygon-hao"],"cli":null},"imports":["import inside from 'point-in-polygon-hao'","import { inside } from 'point-in-polygon-hao'","import type { Point, Polygon } from 'point-in-polygon-hao'"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import inside from 'point-in-polygon-hao';\n\nconst polygon = [\n  [\n    [1, 1],\n    [1, 2],\n    [2, 2],\n    [2, 1],\n    [1, 1]\n  ]\n];\n\nconst polygonWithHole = [\n  [\n    [0, 0], [10, 0], [10, 10], [0, 10], [0, 0]\n  ],\n  [\n    [2, 2], [2, 8], [8, 8], [8, 2], [2, 2]\n  ]\n];\n\nconsole.log('Point [1.5, 1.5] in simple polygon:', inside([1.5, 1.5], polygon));\n// Expected: true\n\nconsole.log('Point [1, 2] on simple polygon edge:', inside([1, 2], polygon));\n// Expected: 0\n\nconsole.log('Point [5, 5] in polygon with hole:', inside([5, 5], polygonWithHole));\n// Expected: false (due to hole)\n\nconsole.log('Point [0.5, 0.5] in polygon with hole (outside hole):', inside([0.5, 0.5], polygonWithHole));\n// Expected: true\n\n// Example of invalid polygon (unclosed ring) which would throw an error if not handled:\n// try {\n//   inside([0.5, 0.5], [[[0,0], [1,0], [1,1]]]);\n// } catch (e) {\n//   console.error('Error with unclosed polygon:', e.message);\n// }\n","lang":"typescript","description":"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}