From b4342d813b1e945ab396dbd884bb1efc6025bb5e Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Thu, 25 Nov 2021 10:05:27 -0500 Subject: [PATCH] Fix SHAPE_LINE_CHAIN::Slice when end is an arc followed by a point Fixes https://gitlab.com/kicad/code/kicad/-/issues/9770 --- libs/kimath/src/geometry/shape_line_chain.cpp | 2 +- pcbnew/router/pns_meander_placer_base.cpp | 4 ++-- qa/libs/kimath/geometry/test_shape_line_chain.cpp | 9 +++++++++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/libs/kimath/src/geometry/shape_line_chain.cpp b/libs/kimath/src/geometry/shape_line_chain.cpp index 31ca8b5634..4e8757d3aa 100644 --- a/libs/kimath/src/geometry/shape_line_chain.cpp +++ b/libs/kimath/src/geometry/shape_line_chain.cpp @@ -988,7 +988,7 @@ int SHAPE_LINE_CHAIN::NextShape( int aPointIndex, bool aForwards ) const if( aPointIndex == lastIndex ) { - if( !m_closed ) + if( !m_closed && arcIndex( aPointIndex ) == currentArcIdx ) return -1; else return lastIndex; // Segment between last point and the start diff --git a/pcbnew/router/pns_meander_placer_base.cpp b/pcbnew/router/pns_meander_placer_base.cpp index 581358dabf..fbafa88071 100644 --- a/pcbnew/router/pns_meander_placer_base.cpp +++ b/pcbnew/router/pns_meander_placer_base.cpp @@ -95,11 +95,11 @@ void MEANDER_PLACER_BASE::cutTunedLine( const SHAPE_LINE_CHAIN& aOrigin, const V if( idx >= 0 ) { const SEG& s = aOrigin.CSegment( idx ); - cp += (s.B - s.A).Resize(2); + cp += ( s.B - s.A ).Resize( 2 ); } else { - cp += VECTOR2I (2, 5); // some arbitrary value that is not 45 degrees oriented + cp += VECTOR2I( 2, 5 ); // some arbitrary value that is not 45 degrees oriented } } diff --git a/qa/libs/kimath/geometry/test_shape_line_chain.cpp b/qa/libs/kimath/geometry/test_shape_line_chain.cpp index 0448d8f7d5..050b0490d9 100644 --- a/qa/libs/kimath/geometry/test_shape_line_chain.cpp +++ b/qa/libs/kimath/geometry/test_shape_line_chain.cpp @@ -393,6 +393,15 @@ BOOST_AUTO_TEST_CASE( Slice ) BOOST_CHECK_EQUAL( sliceResult.GetPoint( 8 ), targetSegment.B ); BOOST_CHECK_EQUAL( sliceResult.GetPoint( 9 ), secondArc.GetP0() ); } + + BOOST_TEST_CONTEXT( "Case 5: Chain ends in arc and point" ) + { + SHAPE_LINE_CHAIN chainCopy = chain; + chainCopy.Append( VECTOR2I( 400000, 400000 ) ); + + SHAPE_LINE_CHAIN sliceResult = chainCopy.Slice( 11, -1 ); + BOOST_CHECK_EQUAL( sliceResult.GetPoint( -1 ), VECTOR2I( 400000, 400000 ) ); + } }