Does this support multiple polygons?
See original GitHub issueI noticed that the input array was a relatively strange format (doubly nested array) and was curious if this meant that arrays of multiple polygons were supported? Is this implicitly supported because of the hole support?
// Input shape(s)
const polygon = [
[
[0,0], [1,0], [1, 1], [0,1], [0,0]
],
[
[2,2], [3,2], [3,3], [2,3], [2,2]
]
]
// Tests
const tests = [
[0.5, 0.5],
[0,0],
[0.5, 0],
[2, 0],
[2,2],
[2.5, 2.5],
[2.5, 2],
[2, 1]
];
// Verification
tests.forEach((test) => {
let isInside = inside(test, polygon);
isInside = isInside === true || isInside === 0;
console.log(isInside, test);
})
It also appears to work as expected if the two “shape” subarrays are combined (assuming both are closed properly)?
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Multiple polygon features (Polygon)—ArcGIS Pro
In a group template, the Multiple polygon features builder generates a polygon feature that is coincident with a polygon feature you create in...
Read more >Understanding difference between Polygon and Multipolygon ...
A Polygon is a planar Surface defined by 1 exterior boundary and 0 or ... If a shape has multiple rings, they can...
Read more >Group Multiple Polygons Into a Single Multi-Part Polygon
The options to group multiple polygons into a single multi-part polygon can then be found under the Advanced Feature Creation Options submenu.
Read more >Multipolygon support for elastic search - Elasticsearch
Although Elasticsearch allows to have polygons intersecting each other in a multi-polygon, it is actually a bad idea and in many other tools...
Read more >Plot one or more filled polygonal regions - MATLAB patch
Specifying only unique vertices and their connection matrix can reduce the size of the data when there are many polygons. Specify one vertex...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi @kendallroth
That’s a good question, I hadn’t actually thought about it!
The choice of doubly-nested arrays was to align to how geojson structures things (I mainly deal with mapping problems). Using your structure above is how we’d normally handle holes in geojson.
Below are some examples of geojson coordinate stucture
Note that using the geojson multipolygon approach currently this wouldn’t work with the library.
So I probably ought to be more explicit in describing the expected input format! Although it’s interesting that it works with your approach, although obviously your approach also means your multipolys can’t have holes.
Open to suggestions/thoughts at least around documenting expected behaviour 😃
I’ve update the readme to indicate that the input is in the geojson format.