PolyTreeD

Hierarchy

   |

PolyPathD


PolyTreeD is a read-only data structure that receives solutions from clipping operations. It's an alternative to the PathsD data structure which also receives solutions. However the principle advantage of PolyTreeD over PathsD 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 PolyTreeD object that's to receive a clipping solution is passed as a parameter to ClipperD.Execute. When the clipping operation finishes, this object will be populated with data representing the clipped solution.

A PolyTreeD object is a container for any number of PolyPathD child objects, each representing a single polygon contour. PolyTreeD's top level children will always be outer polygon contours. PolyPathD 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.

PolyTreeD is a specialised PolyPathD object that's simply as a container for other PolyPathD objects and its own polygon property will always be empty.

PolyTreeD will never contain open paths (unlike in Clipper1) since open paths can't contain (own) other paths. When clipping open paths, these will always be represented in solutions via a separate PathsD structure.

C++ Example:
  PathsD subject, clip;
  PolyTreeD solution_tree;
  
  //populate subject and clip
  subject.push_back(MakePathD(
    "100, 50, 10, 79, 65, 2, 65, 98, 10, 21"));
  clip.push_back(MakePathD(
    "98, 63, 4, 68, 77, 8, 52, 100, 19, 12"));

  //do the clipping
  ClipperD c;
  c.AddSubject(subject);
  c.AddClip(clip);
  c.Execute(ClipType::Intersection, 
    FillRule::NonZero, solution_tree);
  
  //do stuff with solution_tree
      

C# Example:
  PathsD subject = new PathsD();
  PathsD clip = new PathsD();
  PolyTreeD solution_tree = new PolyTreeD();

  subject.Add(Clipper.MakePath(new double[] 
    { 100.0, 50, 10, 79, 65, 2, 65, 98, 10, 21 }));
  clip.Add(Clipper.MakePath(new double[] 
    { 98.0, 63, 4, 68, 77, 8, 52, 100, 19, 12 }));

  ClipperD c = new ClipperD();
  c.AddSubject(subject);
  c.AddClip(clip);
  c.Execute(ClipType.Intersection, 
    FillRule.NonZero, solution_tree);
  
  //do stuff with solution_tree
      

The PolyTree64 structure is much more complex than the Paths64 structure and takes much longer to populate (with clipping operations taking roughly 10-50% longer). 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.

Reference

Functions Properties
In PolyPathD:
Clear Count
IsHole
Polygon

See Also

Overview, ClipperD.Execute, PolyTree64, PathsD