xaviergonz / js-angusj-clipper

Polygon and line clipping and offsetting library (Javascript) - a port of Angus Johnson's clipper

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Creating PolyTree

anlumo opened this issue · comments

There's a function polyTreeToPaths, but there is no reverse of this. However, most operations just use Paths, so I can't stay on PolyTrees. How can I create a PolyTree?

did you check openPathsFromPolyTree ?

There's a function polyTreeToPaths, but there is no reverse of this. However, most operations just use Paths, so I can't stay on PolyTrees. How can I create a PolyTree?

It seems like the answer doesn't match the question. Would it be possible to get a different answer to this question?

I would surmise from this conversation that you wouldn't ever want to create polyTreeToPaths.

It is possible to go from polyTree to paths since poly trees have more info than paths, but it is not possible to go back since that info would be missing. From the docs:

PolyTree is intended as a read-only data structure that should only be used to receive solutions from clipping and offsetting operations. It's an alternative to the Paths data structure which also receives these solutions. PolyTree's two major advantages over the Paths structure are: it properly represents the parent-child relationships of the returned polygons; it differentiates between open and closed paths. However, since PolyTree is a more complex structure than the Paths structure, and since it's more computationally expensive to process (the Execute method being roughly 5-10% slower), it should used only be when parent-child polygon relationships are needed, or when open paths are being 'clipped'.

So it is not that I don't want to, but that it can't be done

Can't that information be regenerated from the input? Like, check if a polygon is contained within another polygon to reconstruct the hierarchy?