UNPKG

845 BMarkdownView Raw
1# point-in-polygon
2
3Determine if a point is inside of a polygon.
4
5This module casts a semi-infinite ray from the inquiry point and counts intersections,
6based on
7[this algorithm](https://wrf.ecse.rpi.edu/Research/Short_Notes/pnpoly.html).
8
9# example
10
11``` js
12var inside = require('point-in-polygon');
13var polygon = [ [ 1, 1 ], [ 1, 2 ], [ 2, 2 ], [ 2, 1 ] ];
14
15console.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
22output:
23
24```
25[ true, false, true ]
26```
27
28# methods
29
30``` js
31var inside = require('point-in-polygon')
32```
33
34## inside(point, polygon)
35
36Return 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```
45npm install point-in-polygon
46```
47
48# license
49
50MIT