From b01d950071340eb4b0de2f2081ed797d23b1c984 Mon Sep 17 00:00:00 2001 From: Alex Date: Sat, 10 Dec 2022 06:21:05 +0300 Subject: [PATCH] Remove start pt when collinear with neighboring pts in zone/poly draw. --- pcbnew/tools/zone_create_helper.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/pcbnew/tools/zone_create_helper.cpp b/pcbnew/tools/zone_create_helper.cpp index b383ed038d..07df322381 100644 --- a/pcbnew/tools/zone_create_helper.cpp +++ b/pcbnew/tools/zone_create_helper.cpp @@ -355,12 +355,24 @@ void ZONE_CREATE_HELPER::OnComplete( const POLYGON_GEOM_MANAGER& aMgr ) outline->Append( leaderPts.CPoint( i ) ); const SHAPE_LINE_CHAIN loopPts = aMgr.GetLoopLinePoints(); - for( int i = 1; i < loopPts.PointCount(); i++ ) + for( int i = 1; i < loopPts.PointCount() - 1; i++ ) outline->Append( loopPts.CPoint( i ) ); } - outline->Outline( 0 ).SetClosed( true ); - outline->Outline( 0 ).Simplify( true ); + SHAPE_LINE_CHAIN& chain = outline->Outline( 0 ); + + chain.SetClosed( true ); + chain.Simplify( true ); + + // Remove the start point if it lies on the line between neighbouring points. + // Simplify doesn't handle that currently. + if( chain.PointCount() >= 3 ) + { + SEG seg( chain.CPoint( -1 ), chain.CPoint( 1 ) ); + + if( seg.LineDistance( chain.CPoint( 0 ) ) <= 1 ) + chain.Remove( 0 ); + } // hand the zone over to the committer commitZone( std::move( m_zone ) );