Clipper2: Handle nested poly/hole/poly returns

In Clipper1, we had a flat tree structure on returns.  Clipper2 nests
these, so we need to properly handle the nesting structure when
importing the polygons
This commit is contained in:
Seth Hillbrand 2022-10-21 16:13:01 -07:00
parent 34742b386d
commit 4cdf0bd6c9
2 changed files with 27 additions and 14 deletions

View File

@ -1394,6 +1394,9 @@ private:
void importTree( Clipper2Lib::Paths64& paths,
const std::vector<CLIPPER_Z_VALUE>& aZValueBuffer,
const std::vector<SHAPE_ARC>& aArcBuffe );
void importPolyPath( Clipper2Lib::PolyPath64* aPolyPath,
const std::vector<CLIPPER_Z_VALUE>& aZValueBuffer,
const std::vector<SHAPE_ARC>& aArcBuffer );
void inflate1( int aAmount, int aCircleSegCount, CORNER_STRATEGY aCornerStrategy );
void inflate2( int aAmount, int aCircleSegCount, CORNER_STRATEGY aCornerStrategy );

View File

@ -1082,6 +1082,29 @@ void SHAPE_POLY_SET::importTree( ClipperLib::PolyTree* tree,
}
void SHAPE_POLY_SET::importPolyPath( Clipper2Lib::PolyPath64* aPolyPath,
const std::vector<CLIPPER_Z_VALUE>& aZValueBuffer,
const std::vector<SHAPE_ARC>& aArcBuffer )
{
if( !aPolyPath->IsHole() )
{
POLYGON paths;
paths.reserve( aPolyPath->Count() + 1 );
paths.emplace_back( aPolyPath->Polygon(), aZValueBuffer, aArcBuffer );
for( Clipper2Lib::PolyPath64* child : *aPolyPath )
{
paths.emplace_back( child->Polygon(), aZValueBuffer, aArcBuffer );
for( Clipper2Lib::PolyPath64* grandchild : *child )
importPolyPath( grandchild, aZValueBuffer, aArcBuffer );
}
m_polys.push_back( paths );
}
}
void SHAPE_POLY_SET::importTree( Clipper2Lib::PolyTree64& tree,
const std::vector<CLIPPER_Z_VALUE>& aZValueBuffer,
const std::vector<SHAPE_ARC>& aArcBuffer )
@ -1089,20 +1112,7 @@ void SHAPE_POLY_SET::importTree( Clipper2Lib::PolyTree64& tree,
m_polys.clear();
for( Clipper2Lib::PolyPath64* n : tree )
{
if( !n->IsHole() )
{
POLYGON paths;
paths.reserve( n->Count() + 1 );
paths.emplace_back( n->Polygon(), aZValueBuffer, aArcBuffer );
for( Clipper2Lib::PolyPath64* child : *n)
paths.emplace_back( child->Polygon(), aZValueBuffer, aArcBuffer );
m_polys.push_back( paths );
}
}
importPolyPath( n, aZValueBuffer, aArcBuffer );
}