From 1ec217d70ef6d479476b7addd652603e6a7b6e2c Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Thu, 29 Mar 2018 22:04:51 -0400 Subject: [PATCH] Fix hit testing for zero-width gerber items --- gerbview/gerber_draw_item.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/gerbview/gerber_draw_item.cpp b/gerbview/gerber_draw_item.cpp index 93fd35a80a..06fabc748e 100644 --- a/gerbview/gerber_draw_item.cpp +++ b/gerbview/gerber_draw_item.cpp @@ -764,6 +764,9 @@ void GERBER_DRAW_ITEM::GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList ) bool GERBER_DRAW_ITEM::HitTest( const wxPoint& aRefPos ) const { + // In case the item has a very tiny width defined, allow it to be selected + const int MIN_HIT_TEST_RADIUS = Millimeter2iu( 0.01 ); + // calculate aRefPos in XY gerber axis: wxPoint ref_pos = GetXYPosition( aRefPos ); @@ -788,8 +791,11 @@ bool GERBER_DRAW_ITEM::HitTest( const wxPoint& aRefPos ) const double radius = GetLineLength( m_Start, m_ArcCentre ); VECTOR2D test_radius = VECTOR2D( ref_pos ) - VECTOR2D( m_ArcCentre ); - // Are we within m_Size.x of the radius? - bool radius_hit = ( std::fabs( test_radius.EuclideanNorm() - radius) < m_Size.x ); + int size = ( ( m_Size.x < MIN_HIT_TEST_RADIUS ) ? MIN_HIT_TEST_RADIUS + : m_Size.x ); + + // Are we close enough to the radius? + bool radius_hit = ( std::fabs( test_radius.EuclideanNorm() - radius) < size ); if( radius_hit ) { @@ -833,6 +839,9 @@ bool GERBER_DRAW_ITEM::HitTest( const wxPoint& aRefPos ) const // TODO: a better analyze of the shape (perhaps create a D_CODE::HitTest for flashed items) int radius = std::min( m_Size.x, m_Size.y ) >> 1; + if( radius < MIN_HIT_TEST_RADIUS ) + radius = MIN_HIT_TEST_RADIUS; + if( m_Flashed ) return HitTestPoints( m_Start, ref_pos, radius ); else