Add regression test for arc winding
While the bug has been fixes, the winding handling in the
SetArcGeometry() function isn't tested. This adds a regression
test on EDA_SHAPE, which is where the logic now lives.
Relates-To: https://gitlab.com/kicad/code/kicad/-/issues/15694
Cherry-Pick: fb12db5f2c
This commit is contained in:
parent
1d6caa9a35
commit
b64573f5d4
|
@ -82,7 +82,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<VECTOR2I>,
|
||||
|
@ -91,4 +91,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_CASE> 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<VECTOR2I>,
|
||||
(center) ( c.m_ExpectedCenter ) ( SHAPE_ARC::DefaultAccuracyForPCB() ) );
|
||||
|
||||
const int radius = shape.GetRadius();
|
||||
|
||||
BOOST_CHECK_PREDICATE(
|
||||
KI_TEST::IsWithin<int>,
|
||||
(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<VECTOR2I>,
|
||||
(newEnd) ( c.m_ExpectedEndAfterSwap ) ( SHAPE_ARC::DefaultAccuracyForPCB() ) );
|
||||
|
||||
const EDA_ANGLE angle = shape.GetArcAngle();
|
||||
|
||||
BOOST_CHECK_PREDICATE(
|
||||
KI_TEST::IsWithinWrapped<double>,
|
||||
( angle.AsDegrees() )( c.m_ExpectedAngleAfterSwapDeg )( 360.0 )( angle_tol ) );
|
||||
|
||||
// Check that the centre is still correct
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
|
Loading…
Reference in New Issue