Polygon triangulation: Check for broken remainders

If the last three points of a tesselation are concave, we will never be
able to triangulate them.  They were likely formed from a bad polygon,
so we will drop the triangle and return completed

Fixes https://gitlab.com/kicad/code/kicad/issues/9380
This commit is contained in:
Seth Hillbrand 2021-10-12 12:13:14 -07:00
parent 35e90d0cf4
commit c1e6fdfb47
2 changed files with 13 additions and 0 deletions

View File

@ -468,6 +468,15 @@ private:
}
}
// Check to see if we are left with only three points in the polygon
if( aPoint->next && aPoint->prev == aPoint->next->next )
{
// Three concave points will never be able to be triangulated because they were
// created by an intersecting polygon, so just drop them.
if( area( aPoint->prev, aPoint, aPoint->next ) >= 0 )
return true;
}
/*
* At this point, our polygon should be fully tessellated.
*/

View File

@ -2378,6 +2378,10 @@ void SHAPE_POLY_SET::CacheTriangulation( bool aPartition )
while( tmpSet.OutlineCount() > 0 )
{
if( !m_triangulatedPolys.empty() && m_triangulatedPolys.back()->GetTriangleCount() == 0 )
m_triangulatedPolys.erase( m_triangulatedPolys.end() - 1 );
m_triangulatedPolys.push_back( std::make_unique<TRIANGULATED_POLYGON>() );
PolygonTriangulation tess( *m_triangulatedPolys.back() );