diff --git a/libs/kimath/src/geometry/shape_arc.cpp b/libs/kimath/src/geometry/shape_arc.cpp index ae3962b125..9b6c266fbd 100644 --- a/libs/kimath/src/geometry/shape_arc.cpp +++ b/libs/kimath/src/geometry/shape_arc.cpp @@ -473,7 +473,7 @@ bool SHAPE_ARC::NearestPoints( const SHAPE_CIRCLE& aCircle, VECTOR2I& aPtA, VECT } } - std::vector pts = { m_start, m_end, circle1.NearestPoint( GetCenter() ) }; + std::vector pts = { m_start, m_end, circle1.NearestPoint( aCircle.GetCenter() ) }; for( const VECTOR2I& pt : pts ) { diff --git a/qa/tests/libs/kimath/geometry/test_shape_arc.cpp b/qa/tests/libs/kimath/geometry/test_shape_arc.cpp index 41f79c6698..f67d100a10 100644 --- a/qa/tests/libs/kimath/geometry/test_shape_arc.cpp +++ b/qa/tests/libs/kimath/geometry/test_shape_arc.cpp @@ -26,7 +26,7 @@ #include #include - +#include #include #include @@ -165,6 +165,12 @@ struct ARC_CENTRE_PT_ANGLE VECTOR2I m_start_point; double m_center_angle; }; +struct ARC_START_MID_END +{ + VECTOR2I m_start_point; + VECTOR2I m_mid_point; + VECTOR2I m_end_point; +}; struct ARC_CPA_CASE : public KI_TEST::NAMED_CASE @@ -521,6 +527,49 @@ BOOST_DATA_TEST_CASE( BasicSECGeom, boost::unit_test::data::make( arc_sec_cases } +struct ARC_CICLE_COLLIDE_CASE : public KI_TEST::NAMED_CASE +{ + ARC_START_MID_END m_geom; + int m_arc_clearance; + VECTOR2I m_circle_center; + int m_circle_radius; + bool m_exp_result; + int m_exp_distance; +}; + +static const std::vector arc_circle_collide_cases = { + { " Issue 20336, large arc", { { 183000000, 65710001}, {150496913, 147587363},{116291153, 66406583}}, 2000000 / 2, {116300000, 133100000}, 300000, true, 53319 } +}; + + +BOOST_DATA_TEST_CASE( CollideCircle, boost::unit_test::data::make( arc_circle_collide_cases ), c ) +{ + SHAPE_ARC arc( c.m_geom.m_start_point, c.m_geom.m_mid_point, c.m_geom.m_end_point, 0 ); + SHAPE_CIRCLE circle( c.m_circle_center, c.m_circle_radius ); + + // Test a zero width arc (distance should equal the clearance) + BOOST_TEST_CONTEXT( "Test Clearance" ) + { + int dist = -1; + BOOST_CHECK_EQUAL( arc.Collide( &circle, c.m_arc_clearance, &dist ), c.m_exp_result ); + BOOST_CHECK_EQUAL( dist, c.m_exp_distance ); + } + + // Test by changing the width of the arc (distance should equal zero) + BOOST_TEST_CONTEXT( "Test Width" ) + { + int dist = -1; + arc.SetWidth( c.m_arc_clearance * 2 ); + BOOST_CHECK_EQUAL( arc.Collide( &circle, 0, &dist ), c.m_exp_result ); + + if( c.m_exp_result ) + BOOST_CHECK_EQUAL( dist, 0 ); + else + BOOST_CHECK_EQUAL( dist, -1 ); + } +} + + struct ARC_PT_COLLIDE_CASE : public KI_TEST::NAMED_CASE { ARC_CENTRE_PT_ANGLE m_geom;