Fix knockout text bounding boxes and hit testing.

Fixes https://gitlab.com/kicad/code/kicad/issues/12133
This commit is contained in:
Jeff Young 2022-08-05 23:57:37 +01:00
parent 6a9b821b5c
commit 509d233d97
3 changed files with 30 additions and 4 deletions

View File

@ -781,7 +781,7 @@ bool EDA_SHAPE::hitTest( const VECTOR2I& aPosition, int aAccuracy ) const
for( const VECTOR2I& pt : GetRectCorners() )
poly.Append( pt );
return poly.Collide( VECTOR2I( aPosition ), maxdist );
return poly.Collide( aPosition, maxdist );
}
else // Open rect hit-test
{
@ -795,9 +795,9 @@ bool EDA_SHAPE::hitTest( const VECTOR2I& aPosition, int aAccuracy ) const
case SHAPE_T::POLY:
if( IsFilled() )
return m_poly.Collide( VECTOR2I( aPosition ), maxdist );
return m_poly.Collide( aPosition, maxdist );
else
return m_poly.CollideEdge( VECTOR2I( aPosition ), nullptr, maxdist );
return m_poly.CollideEdge( aPosition, nullptr, maxdist );
default:
UNIMPLEMENTED_FOR( SHAPE_T_asString() );

View File

@ -148,10 +148,22 @@ void PCB_TEXT::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_IT
}
int PCB_TEXT::getKnockoutMargin() const
{
VECTOR2I textSize( GetTextWidth(), GetTextHeight() );
int thickness = GetTextThickness();
return thickness * 1.5 + GetKnockoutTextMargin( textSize, thickness );
}
const EDA_RECT PCB_TEXT::GetBoundingBox() const
{
EDA_RECT rect = GetTextBox();
if( IsKnockout() )
rect.Inflate( getKnockoutMargin() );
if( !GetTextAngle().IsZero() )
rect = rect.GetBoundingBoxRotated( GetTextPos(), GetTextAngle() );
@ -161,7 +173,18 @@ const EDA_RECT PCB_TEXT::GetBoundingBox() const
bool PCB_TEXT::TextHitTest( const VECTOR2I& aPoint, int aAccuracy ) const
{
return EDA_TEXT::TextHitTest( aPoint, aAccuracy );
if( IsKnockout() )
{
SHAPE_POLY_SET poly;
TransformBoundingBoxWithClearanceToPolygon( &poly, getKnockoutMargin() );
return poly.Collide( aPoint, aAccuracy );
}
else
{
return EDA_TEXT::TextHitTest( aPoint, aAccuracy );
}
}

View File

@ -153,6 +153,9 @@ public:
#if defined(DEBUG)
virtual void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
#endif
protected:
int getKnockoutMargin() const;
};
#endif // #define PCB_TEXT_H