Use polygon coordinates relative to the board.

Footprint polygon coordinates are relative to the footprint.
Translate to the board coordinates when doing hittest with
a (selection) rect.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/8596
This commit is contained in:
Eeli Kaikkonen 2021-06-15 10:55:23 +03:00 committed by Jeff Young
parent 38f18d0505
commit 3616a8f0ee
1 changed files with 19 additions and 3 deletions

View File

@ -878,12 +878,28 @@ bool PCB_SHAPE::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy )
// Account for the width of the line
arect.Inflate( GetWidth() / 2 );
int count = m_poly.TotalVertices();
// Polygons in footprints use coordinates relative to the footprint.
// Therefore, instead of using m_poly, we make a copy which is translated
// to the actual location in the board.
FOOTPRINT* fp{ GetParentFootprint() };
double orientation{ fp ? -DECIDEG2RAD( fp->GetOrientation() ) : 0.0 };
wxPoint offset;
if( fp )
offset = fp->GetPosition();
SHAPE_POLY_SET poly{ m_poly };
poly.Rotate( orientation );
poly.Move( offset );
int count = poly.TotalVertices();
for( int ii = 0; ii < count; ii++ )
{
auto vertex = m_poly.CVertex( ii );
auto vertexNext = m_poly.CVertex(( ii + 1 ) % count );
auto vertex = poly.CVertex( ii );
auto vertexNext = poly.CVertex(( ii + 1 ) % count );
// Test if the point is within aRect
if( arect.Contains( ( wxPoint ) vertex ) )