From 873a6331810c922bd3207afb1abd0c8d7cbc18ca Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Fri, 27 Mar 2020 16:15:39 +0100 Subject: [PATCH] Gerber: fix a minor issue in OBLONG standard aperture: - incorrect (too big) bounding box. - HitTest did not test the exact shape. --- gerbview/gerber_draw_item.cpp | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/gerbview/gerber_draw_item.cpp b/gerbview/gerber_draw_item.cpp index bb1cbca588..aa952be8cb 100644 --- a/gerbview/gerber_draw_item.cpp +++ b/gerbview/gerber_draw_item.cpp @@ -348,7 +348,7 @@ const EDA_RECT GERBER_DRAW_ITEM::GetBoundingBox() const case GBR_SPOT_OVAL: { if( code ) - bbox.Inflate( code->m_Size.x, code->m_Size.y ); + bbox.Inflate( code->m_Size.x /2, code->m_Size.y / 2 ); break; } @@ -808,6 +808,37 @@ bool GERBER_DRAW_ITEM::HitTest( const wxPoint& aRefPos, int aAccuracy ) const case GBR_SPOT_RECT: return GetBoundingBox().Contains( aRefPos ); + case GBR_SPOT_OVAL: + { + EDA_RECT bbox = GetBoundingBox(); + + if( ! bbox.Contains( aRefPos ) ) + return false; + + // This is similar to a segment with thickness = min( m_Size.x, m_Size.y ) + int radius = std::min( m_Size.x, m_Size.y )/2; + wxPoint start, end; + if( m_Size.x > m_Size.y ) // Horizontal oval + { + int len = m_Size.y - m_Size.x; + start.x = -len/2; + end.x = len/2; + } + else // Vertical oval + { + int len = m_Size.x - m_Size.y; + start.y = -len/2; + end.y = len/2; + } + start += bbox.Centre(); + end += bbox.Centre(); + + if( radius < MIN_HIT_TEST_RADIUS ) + radius = MIN_HIT_TEST_RADIUS; + + return TestSegmentHit( aRefPos, start, end, radius ); + } + case GBR_ARC: { double radius = GetLineLength( m_Start, m_ArcCentre );