Normalize rectangular shapes before feeding to point editor.
Fixes https://gitlab.com/kicad/code/kicad/issues/11339
This commit is contained in:
parent
67d54ecb4c
commit
356d565d48
|
@ -89,6 +89,27 @@ void LIB_SHAPE::MoveTo( const VECTOR2I& aPosition )
|
|||
}
|
||||
|
||||
|
||||
void LIB_SHAPE::Normalize()
|
||||
{
|
||||
if( GetShape() == SHAPE_T::RECT )
|
||||
{
|
||||
VECTOR2I size = GetEnd() - GetPosition();
|
||||
|
||||
if( size.y < 0 )
|
||||
{
|
||||
SetStartY( GetStartY() + size.y );
|
||||
SetEndY( GetStartY() - size.y );
|
||||
}
|
||||
|
||||
if( size.x < 0 )
|
||||
{
|
||||
SetStartX( GetStartX() + size.x );
|
||||
SetEndX( GetStartX() - size.x );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void LIB_SHAPE::MirrorHorizontal( const VECTOR2I& aCenter )
|
||||
{
|
||||
flip( aCenter, true );
|
||||
|
|
|
@ -79,6 +79,8 @@ public:
|
|||
|
||||
VECTOR2I GetCenter() const { return getCenter(); }
|
||||
|
||||
void Normalize();
|
||||
|
||||
void MirrorHorizontal( const VECTOR2I& aCenter ) override;
|
||||
void MirrorVertical( const VECTOR2I& aCenter ) override;
|
||||
void Rotate( const VECTOR2I& aCenter, bool aRotateCCW = true ) override;
|
||||
|
|
|
@ -69,6 +69,27 @@ void SCH_SHAPE::Move( const VECTOR2I& aOffset )
|
|||
}
|
||||
|
||||
|
||||
void SCH_SHAPE::Normalize()
|
||||
{
|
||||
if( GetShape() == SHAPE_T::RECT )
|
||||
{
|
||||
VECTOR2I size = GetEnd() - GetPosition();
|
||||
|
||||
if( size.y < 0 )
|
||||
{
|
||||
SetStartY( GetStartY() + size.y );
|
||||
SetEndY( GetStartY() - size.y );
|
||||
}
|
||||
|
||||
if( size.x < 0 )
|
||||
{
|
||||
SetStartX( GetStartX() + size.x );
|
||||
SetEndX( GetStartX() - size.x );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SCH_SHAPE::MirrorHorizontally( int aCenter )
|
||||
{
|
||||
flip( VECTOR2I( aCenter, 0 ), true );
|
||||
|
|
|
@ -85,6 +85,8 @@ public:
|
|||
|
||||
void Move( const VECTOR2I& aOffset ) override;
|
||||
|
||||
void Normalize();
|
||||
|
||||
void MirrorHorizontally( int aCenter ) override;
|
||||
void MirrorVertically( int aCenter ) override;
|
||||
void Rotate( const VECTOR2I& aCenter ) override;
|
||||
|
|
|
@ -103,15 +103,10 @@ public:
|
|||
|
||||
case SHAPE_T::RECT:
|
||||
{
|
||||
// point editor works only with rectangles having width and height > 0
|
||||
// Some symbols can have rectangles with width or height < 0
|
||||
// So normalize the size:
|
||||
BOX2I dummy;
|
||||
dummy.SetOrigin( mapCoords( shape->GetPosition() ) );
|
||||
dummy.SetEnd( mapCoords( shape->GetEnd() ) );
|
||||
dummy.Normalize();
|
||||
VECTOR2I topLeft = dummy.GetPosition();
|
||||
VECTOR2I botRight = dummy.GetEnd();
|
||||
shape->Normalize();
|
||||
|
||||
VECTOR2I topLeft = mapCoords( shape->GetPosition() );
|
||||
VECTOR2I botRight = mapCoords( shape->GetEnd() );
|
||||
|
||||
points->AddPoint( topLeft );
|
||||
points->AddPoint( VECTOR2I( botRight.x, topLeft.y ) );
|
||||
|
@ -151,15 +146,10 @@ public:
|
|||
{
|
||||
LIB_TEXTBOX* textBox = static_cast<LIB_TEXTBOX*>( aItem );
|
||||
|
||||
// point editor works only with rectangles having width and height > 0
|
||||
// Some symbols can have rectangles with width or height < 0
|
||||
// So normalize the size:
|
||||
BOX2I dummy;
|
||||
dummy.SetOrigin( mapCoords( textBox->GetPosition() ) );
|
||||
dummy.SetEnd( mapCoords( textBox->GetEnd() ) );
|
||||
dummy.Normalize();
|
||||
VECTOR2I topLeft = dummy.GetPosition();
|
||||
VECTOR2I botRight = dummy.GetEnd();
|
||||
textBox->Normalize();
|
||||
|
||||
VECTOR2I topLeft = mapCoords( textBox->GetPosition() );
|
||||
VECTOR2I botRight = mapCoords( textBox->GetEnd() );
|
||||
|
||||
points->AddPoint( topLeft );
|
||||
points->AddPoint( VECTOR2I( botRight.x, topLeft.y ) );
|
||||
|
@ -197,15 +187,10 @@ public:
|
|||
|
||||
case SHAPE_T::RECT:
|
||||
{
|
||||
// point editor works only with rectangles having width and height > 0
|
||||
// Some symbols can have rectangles with width or height < 0
|
||||
// So normalize the size:
|
||||
BOX2I dummy;
|
||||
dummy.SetOrigin( shape->GetPosition() );
|
||||
dummy.SetEnd( shape->GetEnd() );
|
||||
dummy.Normalize();
|
||||
VECTOR2I topLeft = dummy.GetPosition();
|
||||
VECTOR2I botRight = dummy.GetEnd();
|
||||
shape->Normalize();
|
||||
|
||||
VECTOR2I topLeft = shape->GetPosition();
|
||||
VECTOR2I botRight = shape->GetEnd();
|
||||
|
||||
points->AddPoint( topLeft );
|
||||
points->AddPoint( VECTOR2I( botRight.x, topLeft.y ) );
|
||||
|
@ -245,15 +230,10 @@ public:
|
|||
{
|
||||
SCH_TEXTBOX* textBox = static_cast<SCH_TEXTBOX*>( aItem );
|
||||
|
||||
// point editor works only with rectangles having width and height > 0
|
||||
// Some symbols can have rectangles with width or height < 0
|
||||
// So normalize the size:
|
||||
BOX2I dummy;
|
||||
dummy.SetOrigin( textBox->GetPosition() );
|
||||
dummy.SetEnd( textBox->GetEnd() );
|
||||
dummy.Normalize();
|
||||
VECTOR2I topLeft = dummy.GetPosition();
|
||||
VECTOR2I botRight = dummy.GetEnd();
|
||||
textBox->Normalize();
|
||||
|
||||
VECTOR2I topLeft = textBox->GetPosition();
|
||||
VECTOR2I botRight = textBox->GetEnd();
|
||||
|
||||
points->AddPoint( topLeft );
|
||||
points->AddPoint( VECTOR2I( botRight.x, topLeft.y ) );
|
||||
|
|
Loading…
Reference in New Issue