diff --git a/qa/tests/common/test_eda_shape.cpp b/qa/tests/common/test_eda_shape.cpp index dee9da28e7..0b654879be 100644 --- a/qa/tests/common/test_eda_shape.cpp +++ b/qa/tests/common/test_eda_shape.cpp @@ -78,7 +78,7 @@ BOOST_AUTO_TEST_CASE( SetAngleAndEnd ) BOOST_CHECK_EQUAL( shape.EndsSwapped(), c.m_ExpectedStartEndSwapped ); - VECTOR2I newEnd = shape.EndsSwapped() ? shape.GetStart() : shape.GetEnd(); + const VECTOR2I newEnd = shape.EndsSwapped() ? shape.GetStart() : shape.GetEnd(); BOOST_CHECK_PREDICATE( KI_TEST::IsVecWithinTol, @@ -87,4 +87,87 @@ BOOST_AUTO_TEST_CASE( SetAngleAndEnd ) } +struct SET_ARC_GEOMETRY_CASE +{ + std::string m_CaseName; + VECTOR2I m_Start; + VECTOR2I m_Mid; + VECTOR2I m_End; + VECTOR2I m_ExpectedCenter; + int m_ExpectedRadius; + bool m_ExpectedStartEndSwapped; + VECTOR2I m_ExpectedEndAfterSwap; + double m_ExpectedAngleAfterSwapDeg; +}; + +static const std::vector set_arc_geometry_cases = { + { + // Test that when setting an arc by start/mid/end, the winding + // direction is correctly determined (in 15694, this was in FP_SHAPE, + // but the logic has since been merged with EDA_SHAPE). + "Issue 15694: clockwise arc", + { 10000000, 0 }, + { 0, 10000000 }, + { -10000000, 0 }, + { 0, 0 }, + 10000000, + false, + { -10000000, 0 }, // unchanged + 180.0, + }, + { + "Issue 15694: anticlockwise arc", + { -10000000, 0 }, + { 0, 10000000 }, + { 10000000, 0 }, + { 0, 0 }, + 10000000, + true, + { 10000000, 0 }, // the start is the end after swapping + 180.0, // angle is positive after swapping + }, +}; + +BOOST_AUTO_TEST_CASE( SetArcGeometry ) +{ + const double angle_tol = 0.1; + + for( const auto& c : set_arc_geometry_cases ) + { + BOOST_TEST_INFO_SCOPE( c.m_CaseName ); + + EDA_SHAPE_MOCK shape( SHAPE_T::ARC ); + + shape.SetArcGeometry( c.m_Start, c.m_Mid, c.m_End ); + + const VECTOR2I center = shape.getCenter(); + + BOOST_CHECK_PREDICATE( + KI_TEST::IsVecWithinTol, + (center) ( c.m_ExpectedCenter ) ( SHAPE_ARC::DefaultAccuracyForPCB() ) ); + + const int radius = shape.GetRadius(); + + BOOST_CHECK_PREDICATE( + KI_TEST::IsWithin, + (radius) ( c.m_ExpectedRadius ) ( SHAPE_ARC::DefaultAccuracyForPCB() ) ); + + BOOST_CHECK_EQUAL( shape.EndsSwapped(), c.m_ExpectedStartEndSwapped ); + + const VECTOR2I newEnd = shape.EndsSwapped() ? shape.GetStart() : shape.GetEnd(); + + BOOST_CHECK_PREDICATE( + KI_TEST::IsVecWithinTol, + (newEnd) ( c.m_ExpectedEndAfterSwap ) ( SHAPE_ARC::DefaultAccuracyForPCB() ) ); + + const EDA_ANGLE angle = shape.GetArcAngle(); + + BOOST_CHECK_PREDICATE( + KI_TEST::IsWithinWrapped, + ( angle.AsDegrees() )( c.m_ExpectedAngleAfterSwapDeg )( 360.0 )( angle_tol ) ); + + // Check that the centre is still correct + } +} + BOOST_AUTO_TEST_SUITE_END()