Checking if point is inside irregular polygon?

I'm using Javascript (https://github.com/substack/point-in-polygon) to test if a point is inside polygon, however I think it's adapted from https://www.ecse.rpi.edu/~wrf/Research/Short_Notes/pnpoly.html

Following are the list of points,

``````let points = [
[ 42.34624, -71.06024 ],
[ 42.33558, -71.06616 ],
[ 42.32632, -71.05835 ],
[ 42.32987, -71.05428 ],
[ 42.34732, -71.05432 ],
[ 42.34618, -71.05973 ],
[ 42.34624, -71.06024 ]
];
let testPoint = [
[42.33288, -71.05804]

];`

let isInside = pp(testPoint, points);
expect(isInside).to.equal(true); // always fails
``````

I'm not sure why it fails though. Is it because the algorithm doesn't cope with this "type" of polygon? Any hints please? Please point me to any alternatives to this approach as well.

• I am using Angular 2 and I also want to use point-in-polygon but somehow I am not begin able to use it because it does not have a typescript definition nor an Angular 2 module. Can you tell me how you can import the JavaScript to your Angular 2 project? Nov 30, 2016 at 16:34
• If you have another question, please ask it. Nov 30, 2016 at 16:35
• why? is this one not good enough? :( Nov 30, 2016 at 16:36
• The problem is that you have put it as an answer, which it is not. Nov 30, 2016 at 16:37
• I know but i have no reputation to comment... Nov 30, 2016 at 16:37

• Thanks, I've not implemented my own algorithm. I've tried using existing libraries - `import pp from 'robust-point-in-polygon'`; and `import pp from 'point-in-polygon'` for doing the test, they both come up saying point is outside the polygon.... Apr 20, 2016 at 10:43