Fix selfintersecting or outline intersecting holes issue.

This commit is contained in:
Jean-Pierre Charras 2015-07-27 21:48:38 +02:00 committed by Maciej Suminski
parent 81e2f2e22e
commit fb8afc61ab
1 changed files with 23 additions and 1 deletions

View File

@ -120,10 +120,32 @@ int CPolyLine::NormalizeAreaOutlines( std::vector<CPolyLine*>* aNewPolygonList )
SHAPE_POLY_SET polySet = ConvertPolyListToPolySet( m_CornersList );
// We are expecting only one main outline, but this main outline can have holes
// if holes: combine holes and remove them from the main outline.
SHAPE_POLY_SET::POLYGON& outline = polySet.Polygon( 0 );
SHAPE_POLY_SET holesBuffer;
// Move holes stored in outline to holesBuffer:
// The first SHAPE_LINE_CHAIN is the main outline, others are holes
while( outline.size() > 1 )
{
holesBuffer.AddOutline( outline.back() );
outline.pop_back();
}
polySet.Simplify();
// If any hole, substract it to main outline
if( holesBuffer.OutlineCount() )
{
holesBuffer.Simplify();
polySet.BooleanSubtract( holesBuffer );
}
RemoveAllContours();
// Note: we can have more than outline, because a self intersecting outline will be
// broken to non intersecting polygons, and removing holes can also create a few polygons
for( int ii = 0; ii < polySet.OutlineCount(); ii++ )
{
CPolyLine* polyline = this;
@ -1344,4 +1366,4 @@ const CPOLYGONS_LIST ConvertPolySetToPolyList(const SHAPE_POLY_SET& aPolyset)
}
return list;
}
}