rowanwins/point-in-polygon-hao

False detection?

Closed this issue · 2 comments

Hi
I'm trying to test if the following point is inside my polygon:
`
const myPoly = [[[1234,2292],[1834,2292],[1834,1692],[1234,1692]]]

test('is inside myPoly', t => {
t.false(inside([430, 2205], myPoly))
});
`
The test always fails as the library returns

true
I tried visualizing the points and I think the test should return false.
grafik
Is there an error in my syntax or is the libary returning a wrong result?

Hi @peerjuettner

You need to make sure the first and last points in your polygon are the same.


const myPoly = [[[1234,2292],[1834,2292],[1834,1692],[1234,1692]]]
// becomes
const myPoly = [[[1234,2292],[1834,2292],[1834,1692],[1234,1692], [1234,2292]]]

I think I will write some handling in the library for this to either auto-fix or at least throw an error for it.

The input validation is now included in release v1.0.0