PolyTree64 is a read-only data structure that receives solutions from clipping operations. It's an alternative to the Paths64 data structure which also receives solutions. However the principle advantage of PolyTree64 over Paths64 is that it also represents the parent-child relationships of the polygons in the solution (where a parent's Polygon will contain all its children Polygons).
The PolyTree64 object that's to receive a clipping solution is passed as a parameter to Clipper64.Execute. When the clipping operation finishes, this object will be populated with data representing the clipped solution.
A PolyTree64 object is a container for any number of PolyPath64 child objects, each representing a single polygon contour. Direct descendants of PolyTree64 will always be outer polygon contours. PolyPath64 children may in turn contain their own children to any level of nesting. Children of outer polygon contours will always represent holes, and children of holes will always represent nested outer polygon contours.
PolyTree64 is a specialised PolyPath64 object that's simply as a container for other PolyPath64 objects and its own polygon property will always be empty.
PolyTree64 will never contain open paths (unlike in Clipper1) since open paths can't contain paths. When clipping open paths, these will always be represented in solutions via a separate Paths64 structure.
// create a very simple "subject" consisting of // just 4 unnested polygons Paths64 subject; subject.Add(MakePath({10,10 40,10, 40,40, 10,40})); subject.Add(MakePath({60,10 90,10, 90,40, 60,40})); subject.Add(MakePath({10,60 40,60, 40,90, 10,90})); subject.Add(MakePath({60,60 90,60, 90,90, 60,90})); // union "subject" and put the result into a polytree; PolyTree64 polytree; Clipper64 c64; c64.AddSubject(subject); c64.Execute(ClipType.Union, FillRule.NonZero, polytree); // display polytree and its structure ...
Polytree 1:
+- Polygon
+- Polygon
+- Polygon
+- Polygon
// create "subject" consisting of multiple nested // polygon contours Paths64 subject; subject.Add(MakePath({0,0 100,0, 100,100, 0,100})); // add several holes (note reversed orientation) subject.Add(MakePath({10,10 10,30, 25,30, 25,10})); subject.Add(MakePath({40,10 40,30, 55,30, 55,10})); subject.Add(MakePath({70,10 70,30, 85,30, 85,10})); subject.Add(MakePath({10,40 10,90, 90,90, 90,40})); // add 2 nested outer polygons inside one of the holes subject.Add(MakePath({20,45 80,45, 80,75, 20,75})); subject.Add(MakePath({20,80 80,80, 80,85, 20,85})); // and holes inside one of these nested polygons subject.Add(MakePath({30,50, 30,70, 45,70, 45,50})); subject.Add(MakePath({55,50, 55,70, 70,70, 70,50})); // union "subject" and put the result into a polytree; PolyTree64 polytree; Clipper64 c64; c64.AddSubject(subject); c64.Execute(ClipType.Union, FillRule.NonZero, polytree); // display polytree and its structure ...
Polytree 2:
+- Polygon with 4 holes.
+- Hole with 2 nested polygons.
| +- Polygon
| +- Polygon with 2 holes.
| +- Hole
| +- Hole
+- Hole
+- Hole
+- Hole
Note: Since the PolyTree64's structure is much more complex than Paths64's structure, it'll take quite a bit longer to populate, so clipping operations will be roughly 10% slower. Because of this, it's better to use the Paths64 structure in clipping operations unless the parent-child relationships of the returned polygons is important.
Methods | Properties |
---|---|
In PolyPath64: | |
Clear | Child |
Count | |
IsHole | |
Level | |
Polygon |
Overview, Clipper64.Execute, PolyTreeD, Paths64
Copyright © 2010-2024 Angus Johnson - Clipper2 1.3.0 - Help file built on 14 Jan 2024