Add EDA_RECT hit test for S_POLYGON

Fixes lp:1749989
This commit is contained in:
Andrzej Wolski 2018-02-18 22:36:18 +01:00 committed by Maciej Suminski
parent ab8e2419c2
commit 9241a399a7
1 changed files with 35 additions and 3 deletions

View File

@ -638,7 +638,6 @@ bool DRAWSEGMENT::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy
break; break;
case S_ARC: case S_ARC:
// Test for full containment of this arc in the rect // Test for full containment of this arc in the rect
if( aContained ) if( aContained )
{ {
@ -657,6 +656,7 @@ bool DRAWSEGMENT::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy
arcRect.IntersectsCircleEdge( GetCenter(), GetRadius(), GetWidth() ); arcRect.IntersectsCircleEdge( GetCenter(), GetRadius(), GetWidth() );
} }
break; break;
case S_SEGMENT: case S_SEGMENT:
if( aContained ) if( aContained )
{ {
@ -671,10 +671,42 @@ bool DRAWSEGMENT::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy
break; break;
case S_CURVE: case S_POLYGON:
case S_POLYGON: // not yet handled if( aContained )
{
return arect.Contains( bb );
}
else
{
// Fast test: if aRect is outside the polygon bounding box,
// rectangles cannot intersect
if( !arect.Intersects( bb ) )
return false;
// Account for the width of the line
arect.Inflate( GetWidth() / 2 );
int count = m_Poly.TotalVertices();
for( int ii = 0; ii < count; ii++ )
{
auto vertex = m_Poly.CVertex( ii );
auto vertexNext = m_Poly.CVertex( ( ii + 1 ) % count );
// Test if the point is within aRect
if( arect.Contains( ( wxPoint ) vertex ) )
return true;
// Test if this edge intersects aRect
if( arect.Intersects( ( wxPoint ) vertex, ( wxPoint ) vertexNext ) )
return true;
}
}
break; break;
case S_CURVE: // not yet handled
break;
default: default:
wxASSERT_MSG( 0, wxString::Format( "unknown DRAWSEGMENT shape: %d", m_Shape ) ); wxASSERT_MSG( 0, wxString::Format( "unknown DRAWSEGMENT shape: %d", m_Shape ) );
break; break;