Make DRAWSEGMENT::GetRectCorners return vector

... instead of modifying the argument.
This will make the method usable in python API and will not incur
permormance penalty because named return value optimization (NRVO)
is a thing since C++11.
But even if copy is not elided vector is moved instead of copied.
https://en.cppreference.com/w/cpp/language/copy_elision
This commit is contained in:
qu1ck 2020-09-06 17:40:18 -07:00 committed by Seth Hillbrand
parent 758a4c26d5
commit 636285311e
7 changed files with 21 additions and 29 deletions

View File

@ -629,8 +629,7 @@ void BOARD_ADAPTER::AddShapeWithClearanceToContainer( const DRAWSEGMENT* aDrawSe
{ {
if( aDrawSegment->GetWidth() > 0 ) if( aDrawSegment->GetWidth() > 0 )
{ {
std::vector<wxPoint> pts; std::vector<wxPoint> pts = aDrawSegment->GetRectCorners();
aDrawSegment->GetRectCorners( &pts );
const SFVEC2F topLeft3DU( pts[0].x * m_biuTo3Dunits, -pts[0].y * m_biuTo3Dunits ); const SFVEC2F topLeft3DU( pts[0].x * m_biuTo3Dunits, -pts[0].y * m_biuTo3Dunits );
const SFVEC2F topRight3DU( pts[1].x * m_biuTo3Dunits, -pts[1].y * m_biuTo3Dunits ); const SFVEC2F topRight3DU( pts[1].x * m_biuTo3Dunits, -pts[1].y * m_biuTo3Dunits );

View File

@ -396,8 +396,7 @@ void DRAWSEGMENT::TransformShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerB
case S_RECT: case S_RECT:
{ {
std::vector<wxPoint> pts; std::vector<wxPoint> pts = GetRectCorners();
GetRectCorners( &pts );
if( width == 0 ) if( width == 0 )
{ {

View File

@ -565,8 +565,7 @@ const EDA_RECT DRAWSEGMENT::GetBoundingBox() const
{ {
case S_RECT: case S_RECT:
{ {
std::vector<wxPoint> pts; std::vector<wxPoint> pts = GetRectCorners();
GetRectCorners( &pts );
bbox = EDA_RECT(); // re-init for merging bbox = EDA_RECT(); // re-init for merging
@ -709,8 +708,7 @@ bool DRAWSEGMENT::HitTest( const wxPoint& aPosition, int aAccuracy ) const
case S_RECT: case S_RECT:
{ {
std::vector<wxPoint> pts; std::vector<wxPoint> pts = GetRectCorners();
GetRectCorners( &pts );
if( m_Width == 0 ) // Filled rect hit-test if( m_Width == 0 ) // Filled rect hit-test
{ {
@ -814,8 +812,7 @@ bool DRAWSEGMENT::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy
} }
else else
{ {
std::vector<wxPoint> pts; std::vector<wxPoint> pts = GetRectCorners();
GetRectCorners( &pts );
// Account for the width of the lines // Account for the width of the lines
arect.Inflate( GetWidth() / 2 ); arect.Inflate( GetWidth() / 2 );
@ -952,8 +949,9 @@ const BOX2I DRAWSEGMENT::ViewBBox() const
} }
void DRAWSEGMENT::GetRectCorners( std::vector<wxPoint>* pts ) const std::vector<wxPoint> DRAWSEGMENT::GetRectCorners() const
{ {
std::vector<wxPoint> pts;
MODULE* module = GetParentModule(); MODULE* module = GetParentModule();
wxPoint topLeft = GetStart(); wxPoint topLeft = GetStart();
wxPoint botRight = GetEnd(); wxPoint botRight = GetEnd();
@ -969,20 +967,22 @@ void DRAWSEGMENT::GetRectCorners( std::vector<wxPoint>* pts ) const
} }
// Set up the un-rotated 4 corners // Set up the un-rotated 4 corners
pts->emplace_back( topLeft ); pts.emplace_back( topLeft );
pts->emplace_back( botRight.x, topLeft.y ); pts.emplace_back( botRight.x, topLeft.y );
pts->emplace_back( botRight ); pts.emplace_back( botRight );
pts->emplace_back( topLeft.x, botRight.y ); pts.emplace_back( topLeft.x, botRight.y );
// Now re-rotate the 4 corners to get a diamond // Now re-rotate the 4 corners to get a diamond
if( module && KiROUND( module->GetOrientation() ) % 900 != 0 ) if( module && KiROUND( module->GetOrientation() ) % 900 != 0 )
{ {
for( wxPoint& pt : *pts ) for( wxPoint& pt : pts )
{ {
RotatePoint( &pt,module->GetOrientation() ); RotatePoint( &pt,module->GetOrientation() );
pt += module->GetPosition(); pt += module->GetPosition();
} }
} }
return pts;
} }
@ -1086,8 +1086,7 @@ std::vector<SHAPE*> DRAWSEGMENT::MakeEffectiveShapes() const
case S_RECT: case S_RECT:
{ {
std::vector<wxPoint> pts; std::vector<wxPoint> pts = GetRectCorners();
GetRectCorners( &pts );
if( m_Width == 0 ) if( m_Width == 0 )
{ {

View File

@ -168,7 +168,7 @@ public:
wxPoint GetArcStart() const { return m_End; } wxPoint GetArcStart() const { return m_End; }
wxPoint GetArcEnd() const; wxPoint GetArcEnd() const;
wxPoint GetArcMid() const; wxPoint GetArcMid() const;
void GetRectCorners( std::vector<wxPoint>* pts ) const; std::vector<wxPoint> GetRectCorners() const;
/** /**
* function GetArcAngleStart() * function GetArcAngleStart()

View File

@ -327,8 +327,7 @@ bool ConvertOutlineToPolygon( std::vector<DRAWSEGMENT*>& aSegList, SHAPE_POLY_SE
} }
else if( graphic->GetShape() == S_RECT ) else if( graphic->GetShape() == S_RECT )
{ {
std::vector<wxPoint> pts; std::vector<wxPoint> pts = graphic->GetRectCorners();
graphic->GetRectCorners( &pts );
aPolygons.NewOutline(); aPolygons.NewOutline();
@ -552,8 +551,7 @@ bool ConvertOutlineToPolygon( std::vector<DRAWSEGMENT*>& aSegList, SHAPE_POLY_SE
} }
else if( graphic->GetShape() == S_RECT ) else if( graphic->GetShape() == S_RECT )
{ {
std::vector<wxPoint> pts; std::vector<wxPoint> pts = graphic->GetRectCorners();
graphic->GetRectCorners( &pts );
for( const wxPoint& pt : pts ) for( const wxPoint& pt : pts )
aPolygons.Append( pt, -1, hole ); aPolygons.Append( pt, -1, hole );

View File

@ -967,8 +967,7 @@ void PCB_PAINTER::draw( const DRAWSEGMENT* aSegment, int aLayer )
case S_RECT: case S_RECT:
{ {
std::vector<wxPoint> pts; std::vector<wxPoint> pts = aSegment->GetRectCorners();
aSegment->GetRectCorners( &pts );
if( aSegment->GetWidth() > 0 ) if( aSegment->GetWidth() > 0 )
{ {

View File

@ -506,8 +506,7 @@ void BRDITEMS_PLOTTER::PlotFootprintGraphicItem( EDGE_MODULE* aEdge )
case S_RECT: case S_RECT:
{ {
std::vector<wxPoint> pts; std::vector<wxPoint> pts = aEdge->GetRectCorners();
aEdge->GetRectCorners( &pts );
if( aEdge->GetWidth() > 0 ) if( aEdge->GetWidth() > 0 )
{ {
@ -868,8 +867,7 @@ void BRDITEMS_PLOTTER::PlotDrawSegment( DRAWSEGMENT* aSeg )
case S_RECT: case S_RECT:
{ {
std::vector<wxPoint> pts; std::vector<wxPoint> pts = aSeg->GetRectCorners();
aSeg->GetRectCorners( &pts );
if( aSeg->GetWidth() > 0 ) if( aSeg->GetWidth() > 0 )
{ {