From 636285311e6917b9b121e79ba65b00f9f45cfc66 Mon Sep 17 00:00:00 2001 From: qu1ck Date: Sun, 6 Sep 2020 17:40:18 -0700 Subject: [PATCH] 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 --- .../3d_canvas/create_3Dgraphic_brd_items.cpp | 3 +-- ...board_items_to_polygon_shape_transform.cpp | 3 +-- pcbnew/class_drawsegment.cpp | 27 +++++++++---------- pcbnew/class_drawsegment.h | 2 +- .../convert_drawsegment_list_to_polygon.cpp | 6 ++--- pcbnew/pcb_painter.cpp | 3 +-- pcbnew/plot_brditems_plotter.cpp | 6 ++--- 7 files changed, 21 insertions(+), 29 deletions(-) diff --git a/3d-viewer/3d_canvas/create_3Dgraphic_brd_items.cpp b/3d-viewer/3d_canvas/create_3Dgraphic_brd_items.cpp index 7d47a22a06..f390c78c26 100644 --- a/3d-viewer/3d_canvas/create_3Dgraphic_brd_items.cpp +++ b/3d-viewer/3d_canvas/create_3Dgraphic_brd_items.cpp @@ -629,8 +629,7 @@ void BOARD_ADAPTER::AddShapeWithClearanceToContainer( const DRAWSEGMENT* aDrawSe { if( aDrawSegment->GetWidth() > 0 ) { - std::vector pts; - aDrawSegment->GetRectCorners( &pts ); + std::vector pts = aDrawSegment->GetRectCorners(); 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 ); diff --git a/pcbnew/board_items_to_polygon_shape_transform.cpp b/pcbnew/board_items_to_polygon_shape_transform.cpp index af30183b68..45efc7d66b 100644 --- a/pcbnew/board_items_to_polygon_shape_transform.cpp +++ b/pcbnew/board_items_to_polygon_shape_transform.cpp @@ -396,8 +396,7 @@ void DRAWSEGMENT::TransformShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerB case S_RECT: { - std::vector pts; - GetRectCorners( &pts ); + std::vector pts = GetRectCorners(); if( width == 0 ) { diff --git a/pcbnew/class_drawsegment.cpp b/pcbnew/class_drawsegment.cpp index db49b9f30f..0210d27636 100644 --- a/pcbnew/class_drawsegment.cpp +++ b/pcbnew/class_drawsegment.cpp @@ -565,8 +565,7 @@ const EDA_RECT DRAWSEGMENT::GetBoundingBox() const { case S_RECT: { - std::vector pts; - GetRectCorners( &pts ); + std::vector pts = GetRectCorners(); bbox = EDA_RECT(); // re-init for merging @@ -709,8 +708,7 @@ bool DRAWSEGMENT::HitTest( const wxPoint& aPosition, int aAccuracy ) const case S_RECT: { - std::vector pts; - GetRectCorners( &pts ); + std::vector pts = GetRectCorners(); if( m_Width == 0 ) // Filled rect hit-test { @@ -814,8 +812,7 @@ bool DRAWSEGMENT::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy } else { - std::vector pts; - GetRectCorners( &pts ); + std::vector pts = GetRectCorners(); // Account for the width of the lines arect.Inflate( GetWidth() / 2 ); @@ -952,8 +949,9 @@ const BOX2I DRAWSEGMENT::ViewBBox() const } -void DRAWSEGMENT::GetRectCorners( std::vector* pts ) const +std::vector DRAWSEGMENT::GetRectCorners() const { + std::vector pts; MODULE* module = GetParentModule(); wxPoint topLeft = GetStart(); wxPoint botRight = GetEnd(); @@ -969,20 +967,22 @@ void DRAWSEGMENT::GetRectCorners( std::vector* pts ) const } // Set up the un-rotated 4 corners - pts->emplace_back( topLeft ); - pts->emplace_back( botRight.x, topLeft.y ); - pts->emplace_back( botRight ); - pts->emplace_back( topLeft.x, botRight.y ); + pts.emplace_back( topLeft ); + pts.emplace_back( botRight.x, topLeft.y ); + pts.emplace_back( botRight ); + pts.emplace_back( topLeft.x, botRight.y ); // Now re-rotate the 4 corners to get a diamond if( module && KiROUND( module->GetOrientation() ) % 900 != 0 ) { - for( wxPoint& pt : *pts ) + for( wxPoint& pt : pts ) { RotatePoint( &pt,module->GetOrientation() ); pt += module->GetPosition(); } } + + return pts; } @@ -1086,8 +1086,7 @@ std::vector DRAWSEGMENT::MakeEffectiveShapes() const case S_RECT: { - std::vector pts; - GetRectCorners( &pts ); + std::vector pts = GetRectCorners(); if( m_Width == 0 ) { diff --git a/pcbnew/class_drawsegment.h b/pcbnew/class_drawsegment.h index 29547baa86..aa0ebabfb7 100644 --- a/pcbnew/class_drawsegment.h +++ b/pcbnew/class_drawsegment.h @@ -168,7 +168,7 @@ public: wxPoint GetArcStart() const { return m_End; } wxPoint GetArcEnd() const; wxPoint GetArcMid() const; - void GetRectCorners( std::vector* pts ) const; + std::vector GetRectCorners() const; /** * function GetArcAngleStart() diff --git a/pcbnew/convert_drawsegment_list_to_polygon.cpp b/pcbnew/convert_drawsegment_list_to_polygon.cpp index 2f1f786b6b..42c51440e2 100644 --- a/pcbnew/convert_drawsegment_list_to_polygon.cpp +++ b/pcbnew/convert_drawsegment_list_to_polygon.cpp @@ -327,8 +327,7 @@ bool ConvertOutlineToPolygon( std::vector& aSegList, SHAPE_POLY_SE } else if( graphic->GetShape() == S_RECT ) { - std::vector pts; - graphic->GetRectCorners( &pts ); + std::vector pts = graphic->GetRectCorners(); aPolygons.NewOutline(); @@ -552,8 +551,7 @@ bool ConvertOutlineToPolygon( std::vector& aSegList, SHAPE_POLY_SE } else if( graphic->GetShape() == S_RECT ) { - std::vector pts; - graphic->GetRectCorners( &pts ); + std::vector pts = graphic->GetRectCorners(); for( const wxPoint& pt : pts ) aPolygons.Append( pt, -1, hole ); diff --git a/pcbnew/pcb_painter.cpp b/pcbnew/pcb_painter.cpp index 87ea2feec6..0cafa6aa06 100644 --- a/pcbnew/pcb_painter.cpp +++ b/pcbnew/pcb_painter.cpp @@ -967,8 +967,7 @@ void PCB_PAINTER::draw( const DRAWSEGMENT* aSegment, int aLayer ) case S_RECT: { - std::vector pts; - aSegment->GetRectCorners( &pts ); + std::vector pts = aSegment->GetRectCorners(); if( aSegment->GetWidth() > 0 ) { diff --git a/pcbnew/plot_brditems_plotter.cpp b/pcbnew/plot_brditems_plotter.cpp index 2f25901c65..c14d8c5fc6 100644 --- a/pcbnew/plot_brditems_plotter.cpp +++ b/pcbnew/plot_brditems_plotter.cpp @@ -506,8 +506,7 @@ void BRDITEMS_PLOTTER::PlotFootprintGraphicItem( EDGE_MODULE* aEdge ) case S_RECT: { - std::vector pts; - aEdge->GetRectCorners( &pts ); + std::vector pts = aEdge->GetRectCorners(); if( aEdge->GetWidth() > 0 ) { @@ -868,8 +867,7 @@ void BRDITEMS_PLOTTER::PlotDrawSegment( DRAWSEGMENT* aSeg ) case S_RECT: { - std::vector pts; - aSeg->GetRectCorners( &pts ); + std::vector pts = aSeg->GetRectCorners(); if( aSeg->GetWidth() > 0 ) {