pcb_painter.cpp: fix incorrect shape of ROUNDRECT pads with negative clearance.

If a negative clearance (for instance on mask or paste layer) is set to more
than the corner radius, the drawn shape was broken (fully incorrect size)
This commit is contained in:
jean-pierre charras 2021-06-21 13:44:30 +02:00
parent 15d36456a9
commit 00b4134eb8
1 changed files with 13 additions and 8 deletions

View File

@ -1014,7 +1014,8 @@ void PCB_PAINTER::draw( const PAD* aPad, int aLayer )
std::shared_ptr<SHAPE_COMPOUND> shapes;
bool simpleShapes = true;
if( margin.x != margin.y && aPad->GetShape() != PAD_SHAPE::CUSTOM )
if( ( margin.x != margin.y && aPad->GetShape() != PAD_SHAPE::CUSTOM )
|| ( aPad->GetShape() == PAD_SHAPE::ROUNDRECT && ( margin.x < 0 || margin.y < 0 ) ) )
{
// Our algorithms below (polygon inflation in particular) can't handle differential
// inflation along separate axes. So for those cases we build a dummy pad instead,
@ -1026,7 +1027,18 @@ void PCB_PAINTER::draw( const PAD* aPad, int aLayer )
return;
dummyPad.reset( static_cast<PAD*>( aPad->Duplicate() ) );
int initial_radius = dummyPad->GetRoundRectCornerRadius();
dummyPad->SetSize( pad_size + margin + margin );
if( dummyPad->GetShape() == PAD_SHAPE::ROUNDRECT )
{
// To keep the right margin around the corners, we need to modify the corner radius.
// We must have only one radius correction, so use the smallest absolute margin.
int radius_margin = std::max( margin.x, margin.y ); // radius_margin is < 0
dummyPad->SetRoundRectCornerRadius( std::max( initial_radius + radius_margin, 0 ) );
}
shapes = std::dynamic_pointer_cast<SHAPE_COMPOUND>( dummyPad->GetEffectiveShape() );
margin.x = margin.y = 0;
}
@ -1099,16 +1111,9 @@ void PCB_PAINTER::draw( const PAD* aPad, int aLayer )
VECTOR2I pos = r->GetPosition();
VECTOR2I effectiveMargin = margin;
// This is a bit of an encapsulation leak, but fixing it would be a lot of
// work. We don't want to apply margins to the "internal" rectangle of a
// rounded rect. Only the 4 segments that form the edges get the margin.
if( aPad->GetShape() == PAD_SHAPE::ROUNDRECT )
effectiveMargin = { 0, 0 };
if( effectiveMargin.x < 0 )
{
// A negative margin just produces a smaller rect.
VECTOR2I effectiveSize = r->GetSize() + effectiveMargin;
if( effectiveSize.x > 0 && effectiveSize.y > 0 )