From 9bedb6eedb8295ea309ff447c48cb53ac028ada5 Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Mon, 19 May 2025 17:45:59 -0700 Subject: [PATCH] Fix silk board edge collision case First, fix the error limit check in drc_test_provider_edge_clearance. Then, we rotate the final point incorrectly in SHAPE_ARC::Collide (need negative angle). We were not checking this result in the QA, so add the proper tests --- libs/kimath/src/geometry/shape_arc.cpp | 2 +- .../drc/drc_test_provider_edge_clearance.cpp | 2 +- .../libs/kimath/geometry/test_shape_arc.cpp | 33 ++++++++++++++----- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/libs/kimath/src/geometry/shape_arc.cpp b/libs/kimath/src/geometry/shape_arc.cpp index 3f8888e7c4..4180eb4346 100644 --- a/libs/kimath/src/geometry/shape_arc.cpp +++ b/libs/kimath/src/geometry/shape_arc.cpp @@ -786,7 +786,7 @@ bool SHAPE_ARC::Collide( const VECTOR2I& aP, int aClearance, int* aActual, // because this trucates the distance to an integer before subtracting dist = KiROUND( radius - sqrt( ( aP - center ).SquaredEuclideanNorm() ) ); nearestPt = center + VECTOR2I( radius, 0 ); - RotatePoint( nearestPt, center, angleToPt ); + RotatePoint( nearestPt, center, -angleToPt ); } // If not a 360 degree arc, need to use arc angles to decide if point collides diff --git a/pcbnew/drc/drc_test_provider_edge_clearance.cpp b/pcbnew/drc/drc_test_provider_edge_clearance.cpp index 57ffecce33..b756ea09c9 100644 --- a/pcbnew/drc/drc_test_provider_edge_clearance.cpp +++ b/pcbnew/drc/drc_test_provider_edge_clearance.cpp @@ -150,7 +150,7 @@ bool DRC_TEST_PROVIDER_EDGE_CLEARANCE::Run() if( !reportPhase( _( "Checking copper to board edge clearances..." ) ) ) return false; // DRC cancelled } - else if( m_drcEngine->IsErrorLimitExceeded( DRCE_SILK_EDGE_CLEARANCE ) ) + else if( !m_drcEngine->IsErrorLimitExceeded( DRCE_SILK_EDGE_CLEARANCE ) ) { if( !reportPhase( _( "Checking silk to board edge clearances..." ) ) ) return false; // DRC cancelled diff --git a/qa/tests/libs/kimath/geometry/test_shape_arc.cpp b/qa/tests/libs/kimath/geometry/test_shape_arc.cpp index f67d100a10..30e51d2ffa 100644 --- a/qa/tests/libs/kimath/geometry/test_shape_arc.cpp +++ b/qa/tests/libs/kimath/geometry/test_shape_arc.cpp @@ -670,22 +670,25 @@ struct ARC_SEG_COLLIDE_CASE : public KI_TEST::NAMED_CASE SEG m_seg; bool m_exp_result; int m_exp_distance; + VECTOR2I m_collide_point; }; static const std::vector arc_seg_collide_cases = { - { "0 deg ", { { 0, 0 }, { 100, 0 }, 270.0 }, 0, { { 100, 0 }, { 50, 0 } }, true, 0 }, - { "90 deg ", { { 0, 0 }, { 100, 0 }, 270.0 }, 0, { { 0, 100 }, { 0, 50 } }, true, 0 }, - { "180 deg ", { { 0, 0 }, { 100, 0 }, 270.0 }, 0, { { -100, 0 }, { -50, 0 } }, true, 0 }, - { "270 deg ", { { 0, 0 }, { 100, 0 }, 270.0 }, 0, { { 0, -100 }, { 0, -50 } }, true, 0 }, - { "45 deg ", { { 0, 0 }, { 100, 0 }, 270.0 }, 0, { { 71, 71 }, { 35, 35 } }, true, 0 }, - { "-45 deg ", { { 0, 0 }, { 100, 0 }, 270.0 }, 0, { { 71, -71 }, { 35, -35 } }, false, -1 }, + { "0 deg ", { { 0, 0 }, { 100, 0 }, 270.0 }, 0, { { 100, 0 }, { 50, 0 } }, true, 0, { 100, 0 } }, + { "90 deg ", { { 0, 0 }, { 100, 0 }, 270.0 }, 0, { { 0, 100 }, { 0, 50 } }, true, 0, { 0, 100 } }, + { "180 deg ", { { 0, 0 }, { 100, 0 }, 270.0 }, 0, { { -100, 0 }, { -50, 0 } }, true, 0, { -100, 0 } }, + { "270 deg ", { { 0, 0 }, { 100, 0 }, 270.0 }, 0, { { 0, -100 }, { 0, -50 } }, true, 0, { 0, -100 } }, + { "45 deg ", { { 0, 0 }, { 100, 0 }, 270.0 }, 0, { { 71, 71 }, { 35, 35 } }, true, 0, { 70, 70 } }, + { "-45 deg ", { { 0, 0 }, { 100, 0 }, 270.0 }, 0, { { 71, -71 }, { 35, -35 } }, false, -1, { 0, 0 } }, { "seg inside arc start", { { 0, 0 }, { 71, -71 }, 90.0 }, - 10, { { 90, 0 }, { -35, 0 } }, true, 10 }, + 10, { { 90, 0 }, { -35, 0 } }, true, 10, { 100, 0 } }, { "seg inside arc end", { { 0, 0 }, { 71, -71 }, 90.0 }, - 10, { { -35, 0 }, { 90, 0 } }, true, 10 }, + 10, { { -35, 0 }, { 90, 0 } }, true, 10, { 100, 0 } }, { "large diameter arc", { { 172367922, 82282076 }, { 162530000, 92120000 }, -45.0 }, - 433300, { { 162096732, 92331236 }, { 162096732, 78253268 } }, true, 433268 }, + 433300, { { 162096732, 92331236 }, { 162096732, 78253268 } }, true, 433268, { 162530000, 92120000 } }, + { "upside down collide", { { 26250000, 16520000 }, { 28360000, 16520000 }, 90.0 }, + 0, { { 27545249, 18303444 }, { 27545249, 18114500 } }, true, 0, { 27545249, 18185662 } } }; @@ -715,6 +718,18 @@ BOOST_DATA_TEST_CASE( CollideSeg, boost::unit_test::data::make( arc_seg_collide_ else BOOST_CHECK_EQUAL( dist, -1 ); } + + BOOST_TEST_CONTEXT( "Test Collide Point" ) + { + VECTOR2I collide_point; + int dist = -1; + + if( c.m_exp_result ) + { + arc.Collide( c.m_seg, c.m_arc_clearance, &dist, &collide_point ); + BOOST_CHECK_EQUAL( collide_point, c.m_collide_point ); + } + } } struct ARC_DATA_MM