Compatibility with Prior Versions

ExPolygons

In Clipper Ver 5.1, the ExPolygons structure was replaced with the PolyTree class.

The PolyTreeToExPolygons() function below and its accompanying code may be useful if for some reason you are stuck with using ExPolygons.

Delphi ...

  type
    TExPolygon = record
      Outer: TPolygon;
      Holes: TPolygons;
    end;
    TExPolygons = array of TExPolygon;

  procedure AddOuterPolyNodeToExPolygons(PolyNode: TPolyNode; 
    var ExPolygons: TExPolygons);
  var
    I, J, Cnt: Integer;
  begin
    Cnt := Length(ExPolygons);
    SetLength(ExPolygons, Cnt + 1);
    ExPolygons[Cnt].Outer := PolyNode.Contour;
    SetLength(ExPolygons[Cnt].Holes, PolyNode.ChildCount);
    for I := 0 to PolyNode.ChildCount - 1 do
    begin
      ExPolygons[Cnt].Holes[I] := PolyNode.Childs[I].Contour;
      //Add outer polygons contained by (nested within) holes ...
      for J := 0 to PolyNode.Childs[I].ChildCount - 1 do
        AddOuterPolyNodeToExPolygons(PolyNode.Childs[I].Childs[J], ExPolygons);
    end;
  end;

  function PolyTreeToExPolygons(PolyTree: TPolyTree): TExPolygons;
  var
    I: Integer;
  begin
    Result := nil;
    for I := 0 to PolyTree.ChildCount - 1 do
      AddOuterPolyNodeToExPolygons(PolyTree.Childs[I], Result);
  end;
          


C++ ...

   struct ExPolygon {
    Polygon outer;
    Polygons holes;
  };

  typedef std::vector< ExPolygon > ExPolygons;

  void AddOuterPolyNodeToExPolygons(PolyNode& polynode, ExPolygons& expolygons)
  {  
    size_t cnt = expolygons.size();
    expolygons.resize(cnt + 1);
    expolygons[cnt].outer = polynode.Contour;
    expolygons[cnt].holes.resize(polynode.ChildCount());
    for (int i = 0; i < polynode.ChildCount(); ++i)
    {
      expolygons[cnt].holes[i] = polynode.Childs[i]->Contour;
      //Add outer polygons contained by (nested within) holes ...
      for (int j = 0; j < polynode.Childs[i]->ChildCount(); ++j)
        AddOuterPolyNodeToExPolygons(*polynode.Childs[i]->Childs[j], expolygons);
    }
  }

  void PolyTreeToExPolygons(PolyTree& polytree, ExPolygons& expolygons)
  {
    expolygons.clear();
    for (int i = 0; i < polytree.ChildCount(); ++i)
      AddOuterPolyNodeToExPolygons(*polytree.Childs[i], expolygons);
  }
          


C# ...

  using ExPolygons = List<ExPolygon>;	
  using Polygon = List<IntPoint>;
  using Polygons = List<List<IntPoint>>;

  public struct ExPolygon {
      public Polygon outer;
      public Polygons holes;
  }    

  void AddOuterPolyNodeToExPolygons(PolyNode polynode, ref ExPolygons expolygons)
  {  
    ExPolygon ep = new ExPolygon();
    ep.outer = new Polygon(polynode.Contour);
    ep.holes = new Polygons(polynode.ChildCount);
    foreach (PolyNode node in polynode.Childs)
    {
      ep.holes.Add(node.Contour);
      //Add outer polygons contained by (nested within) holes ...
      foreach (PolyNode n in node.Childs)
          AddOuterPolyNodeToExPolygons(n, ref expolygons);
    }
    expolygons.Add(ep);
  }

  void PolyTreeToExPolygons(PolyTree polytree, ref ExPolygons expolygons)
  {
      expolygons.Clear();
      foreach (PolyNode node in polytree.Childs)
        AddOuterPolyNodeToExPolygons(node, ref expolygons);
  }
          


 

See Also

PolyTree