From 9e557d84c66569b068ebc457362c691e0bfc23a1 Mon Sep 17 00:00:00 2001 From: Roberto Fernandez Bautista Date: Wed, 13 Oct 2021 18:58:21 +0100 Subject: [PATCH] Ensure appended arcs are valid arcs (start, mid, end cannot be collinear) Fixes https://gitlab.com/kicad/code/kicad/-/issues/9380 --- libs/kimath/src/geometry/shape_line_chain.cpp | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/libs/kimath/src/geometry/shape_line_chain.cpp b/libs/kimath/src/geometry/shape_line_chain.cpp index bfc29829ec..ce4f303d6a 100644 --- a/libs/kimath/src/geometry/shape_line_chain.cpp +++ b/libs/kimath/src/geometry/shape_line_chain.cpp @@ -1052,15 +1052,26 @@ void SHAPE_LINE_CHAIN::Append( const SHAPE_LINE_CHAIN& aOtherLine ) void SHAPE_LINE_CHAIN::Append( const SHAPE_ARC& aArc ) { - SHAPE_LINE_CHAIN chain = aArc.ConvertToPolyline(); + SEG startToEnd( aArc.GetP0(), aArc.GetP1() ); - // @todo should the below 4 LOC be moved to SHAPE_ARC::ConvertToPolyline ? - chain.m_arcs.push_back( aArc ); + if( startToEnd.Distance( aArc.GetArcMid() ) < 1 ) + { + // Not really a valid arc. Add as a straight line segment instead + Append( aArc.GetP0() ); + Append( aArc.GetP1() ); + } + else + { + SHAPE_LINE_CHAIN chain = aArc.ConvertToPolyline(); - for( auto& sh : chain.m_shapes ) - sh.first = 0; + // @todo should the below 4 LOC be moved to SHAPE_ARC::ConvertToPolyline ? + chain.m_arcs.push_back( aArc ); - Append( chain ); + for( auto& sh : chain.m_shapes ) + sh.first = 0; + + Append( chain ); + } assert( m_shapes.size() == m_points.size() ); }