From b3cd829d9ffcd8dfaf92a822752de10df64b0657 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Tue, 13 Oct 2020 20:16:40 +0100 Subject: [PATCH] Don't allow degenerate polygons. Fixes https://gitlab.com/kicad/code/kicad/issues/5883 --- common/preview_items/centreline_rect_item.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/common/preview_items/centreline_rect_item.cpp b/common/preview_items/centreline_rect_item.cpp index e2b71ce0c8..dbe85a1357 100644 --- a/common/preview_items/centreline_rect_item.cpp +++ b/common/preview_items/centreline_rect_item.cpp @@ -30,8 +30,8 @@ using namespace KIGFX::PREVIEW; -static SHAPE_POLY_SET getRectangleAlongCentreLine( - const VECTOR2D& aClStart, const VECTOR2D& aClEnd, double aAspect ) +static SHAPE_POLY_SET getRectangleAlongCentreLine( const VECTOR2D& aClStart, + const VECTOR2D& aClEnd, double aAspect ) { SHAPE_POLY_SET poly; poly.NewOutline(); @@ -48,11 +48,15 @@ static SHAPE_POLY_SET getRectangleAlongCentreLine( */ // vector down the centre line of the rectangle - const VECTOR2D cl = aClEnd - aClStart; + VECTOR2D cl = aClEnd - aClStart; + + // don't allow degenerate polygons + if( cl.x == 0 && cl.y == 0 ) + cl.x = 1.0; // the "side" of the rectangle is the centre line rotated by 90 deg // and scaled by the aspect ratio - const VECTOR2D side = cl.Rotate( M_PI / 2.0 ) * aAspect; + VECTOR2D side = cl.Rotate( M_PI / 2.0 ) * aAspect; VECTOR2D pt = aClStart + ( side / 2.0 ); poly.Append( pt );