From 98d6d68e2d2c0feab0ec2a4b20c394639c24566f Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Sat, 15 Dec 2018 17:11:21 -0700 Subject: [PATCH] tesselate: Check for non-polygons Elements with only 0, 1 or 2 vertices cannot form valid polygons, so do not attempt to tesselate them. --- include/geometry/polygon_triangulation.h | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/include/geometry/polygon_triangulation.h b/include/geometry/polygon_triangulation.h index c437e58bb1..a6b6900703 100644 --- a/include/geometry/polygon_triangulation.h +++ b/include/geometry/polygon_triangulation.h @@ -619,13 +619,16 @@ public: if( !m_bbox.GetWidth() || !m_bbox.GetHeight() ) return; - Vertex* outerNode = createList( aPoly ); - if( !outerNode ) + /// Place the polygon Vertices into a circular linked list + /// and check for lists that have only 0, 1 or 2 elements and + /// therefore cannot be polygons + Vertex* firstVertex = createList( aPoly ); + if( !firstVertex || firstVertex->prev == firstVertex->next ) return; - outerNode->updateList(); + firstVertex->updateList(); - if( !earcutList( outerNode ) ) + if( !earcutList( firstVertex ) ) { m_vertices.clear(); m_result.Clear(); @@ -635,13 +638,13 @@ public: for( auto path : simplified ) { - outerNode = createList( path ); + firstVertex = createList( path ); - if( !outerNode ) + if( !firstVertex ) return; - outerNode->updateList(); - earcutList( outerNode ); + firstVertex->updateList(); + earcutList( firstVertex ); } }