Fix SHAPE_LINE_CHAIN::Simplify() when there are only 3 points in the chain

We weren't updating m_shapes properly.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/11695
This commit is contained in:
Roberto Fernandez Bautista 2022-08-19 20:49:10 +01:00
parent 46df421064
commit 1fa1b44d02
2 changed files with 22 additions and 1 deletions

View File

@ -1696,7 +1696,7 @@ SHAPE_LINE_CHAIN& SHAPE_LINE_CHAIN::Simplify( bool aRemoveColinear )
else if( PointCount() == 3 )
{
if( m_points[0] == m_points[1] )
m_points.pop_back();
Remove( 1 );
return *this;
}

View File

@ -106,6 +106,7 @@ BOOST_AUTO_TEST_CASE( ArcToPolylineLargeCoords )
base_chain.ClearArcs();
BOOST_CHECK( GEOM_TEST::IsOutlineValid( base_chain ) );
BOOST_CHECK_EQUAL( base_chain.CPoints().size(), base_chain.CShapes().size() );
BOOST_CHECK_EQUAL( base_chain.PointCount(), 11 ); // We should have the same number of points
BOOST_CHECK_EQUAL( base_chain.ArcCount(), 0 ); // All arcs should have been removed
BOOST_CHECK_EQUAL( base_chain.Area(), areaPriorToArcRemoval ); // Area should not have changed
@ -130,10 +131,30 @@ BOOST_AUTO_TEST_CASE( SetClosedDuplicatePoint )
// CLOSED CHAIN
chain.SetClosed( true );
BOOST_CHECK_EQUAL( chain.CPoints().size(), chain.CShapes().size() );
BOOST_CHECK_EQUAL( chain.PointCount(), 30 ); // (-1) should have removed coincident points
BOOST_CHECK( GEOM_TEST::IsOutlineValid( chain ) );
}
// Test that duplicate point gets removed when we call simplify
BOOST_AUTO_TEST_CASE( SimplifyDuplicatePoint )
{
SHAPE_LINE_CHAIN chain;
chain.Append( { 100, 100 } );
chain.Append( { 100, 100 }, true ); //duplicate point to simplify
chain.Append( { 200, 100 } );
BOOST_CHECK( GEOM_TEST::IsOutlineValid( chain ) );
BOOST_CHECK_EQUAL( chain.PointCount(), 3 );
chain.Simplify();
BOOST_CHECK_EQUAL( chain.CPoints().size(), chain.CShapes().size() );
BOOST_CHECK_EQUAL( chain.PointCount(), 2 ); // (-1) should have removed coincident points
BOOST_CHECK( GEOM_TEST::IsOutlineValid( chain ) );
}
// Test special case where the last arc in the chain has a shared point with the first arc
BOOST_AUTO_TEST_CASE( ArcWrappingToStartSharedPoints )