velipso/polybooljs

How to separate poly to several polys

Closed this issue · 6 comments

After some bool operations, I may get a poly which actual is a combination of several separated polys, like this:

image

this blue poly difference the red poly and get the green poly.

How could I separate the green poly to two polys? Is there a simple solution to this question, or I need to solve it by other algorithm?

The result's regions is a list of polygons, so simply index into it.

What if the result contains holes? like this:

image

I want to separate them to A and B.

Hmm, that's a good question.

But I think it's outside the scope of this library.

You might be able to use some of the logic that's in geojson.js to figure out the different roots:

https://github.com/voidqk/polybooljs/blob/master/lib/geojson.js#L52

There's a comment describing a similar issue.

So the index of each polygon does not tell anything about their spatial relationship, right?

correct

I get it.