1 | # point-in-polygon
|
2 |
|
3 | Determine if a point is inside of a polygon.
|
4 |
|
5 | This module casts a semi-infinite ray from the inquiry point and counts intersections,
|
6 | based on
|
7 | [this algorithm](https://wrf.ecse.rpi.edu/Research/Short_Notes/pnpoly.html).
|
8 |
|
9 | # example
|
10 |
|
11 | ``` js
|
12 | var inside = require('point-in-polygon');
|
13 | var polygon = [ [ 1, 1 ], [ 1, 2 ], [ 2, 2 ], [ 2, 1 ] ];
|
14 |
|
15 | console.dir([
|
16 | inside([ 1.5, 1.5 ], polygon),
|
17 | inside([ 4.9, 1.2 ], polygon),
|
18 | inside([ 1.8, 1.1 ], polygon)
|
19 | ]);
|
20 | ```
|
21 |
|
22 | output:
|
23 |
|
24 | ```
|
25 | [ true, false, true ]
|
26 | ```
|
27 |
|
28 | # methods
|
29 |
|
30 | ``` js
|
31 | var inside = require('point-in-polygon')
|
32 | ```
|
33 |
|
34 | ## inside(point, polygon)
|
35 |
|
36 | Return whether `point` is contained in `polygon`.
|
37 |
|
38 | `point` should be a 2-item array of coordinates.
|
39 |
|
40 | `polygon` should be an array of 2-item arrays of coordinates.
|
41 |
|
42 | # install
|
43 |
|
44 | ```
|
45 | npm install point-in-polygon
|
46 | ```
|
47 |
|
48 | # license
|
49 |
|
50 | MIT
|