diff --git a/pcbnew/footprint.cpp b/pcbnew/footprint.cpp index 9fe5f40fb2..e5a4d256a5 100644 --- a/pcbnew/footprint.cpp +++ b/pcbnew/footprint.cpp @@ -4,7 +4,7 @@ * Copyright (C) 2017 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2015 SoftPLC Corporation, Dick Hollenbeck * Copyright (C) 2015 Wayne Stambaugh - * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -712,6 +712,22 @@ SHAPE_POLY_SET FOOTPRINT::GetBoundingHull() const } } + // If there are some graphic items, build the actual hull. + // However if no items, create a minimal polygon (can happen if a footprint + // is created with no item: it contains only 2 texts. + if( rawPolys.OutlineCount() == 0 ) + { + // generate a small dummy rectangular outline around the anchor + const int halfsize = Millimeter2iu( 0.02 ); + + rawPolys.NewOutline(); + // add a square: + rawPolys.Append( GetPosition().x - halfsize, GetPosition().y - halfsize ); + rawPolys.Append( GetPosition().x + halfsize, GetPosition().y - halfsize ); + rawPolys.Append( GetPosition().x + halfsize, GetPosition().y + halfsize ); + rawPolys.Append( GetPosition().x - halfsize, GetPosition().y + halfsize ); + } + std::vector convex_hull; BuildConvexHull( convex_hull, rawPolys );