Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mikolalysenko/robust-point-in-polygon
Exactly test if a point is inside, outside or on the boundary of a polygon
https://github.com/mikolalysenko/robust-point-in-polygon
Last synced: 4 days ago
JSON representation
Exactly test if a point is inside, outside or on the boundary of a polygon
- Host: GitHub
- URL: https://github.com/mikolalysenko/robust-point-in-polygon
- Owner: mikolalysenko
- License: mit
- Created: 2014-03-28T20:26:00.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2023-02-03T06:19:40.000Z (almost 2 years ago)
- Last Synced: 2024-12-16T22:35:35.048Z (8 days ago)
- Language: JavaScript
- Size: 135 KB
- Stars: 245
- Watchers: 9
- Forks: 28
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
robust-point-in-polygon
=======================
Exactly determines if a point is contained in a 2D polygon.# Example
```javascript
var classifyPoint = require("robust-point-in-polygon")
var polygon = [ [ 1, 1 ], [ 1, 2 ], [ 2, 2 ], [ 2, 1 ] ]console.log(
classifyPoint(polygon, [1.5, 1.5]),
classifyPoint(polygon, [1, 2]),
classifyPoint(polygom, [100000, 10000]))
```Output:
```
-1 0 1
```# Install
```
npm install robust-point-in-polygon
```# API
### `require("robust-point-in-polygon")(loop, point)`
Tests if a point is contained in the interior of a simple polygon* `loop` is an array of vertices for the polygon
* `point` is a 2D point which is classified against the polygon**Returns** An integer which determines the position of `point` relative to `polygon`. This has the following interpretation:
* `-1` if `point` is contained inside `loop`
* `0` if `point` is on the boundary of `loop`
* `1` if `point` is outside `loop`# Credits
(c) 2014 Mikola Lysenko. MIT License