diff --git a/pcbnew/board_items_to_polygon_shape_transform.cpp b/pcbnew/board_items_to_polygon_shape_transform.cpp index f0625cb1d3..af13f39964 100644 --- a/pcbnew/board_items_to_polygon_shape_transform.cpp +++ b/pcbnew/board_items_to_polygon_shape_transform.cpp @@ -488,7 +488,7 @@ void PCB_SHAPE::TransformShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerBuf // Build the polygon with the actual position and orientation: std::vector poly; - poly = BuildPolyPointsList(); + DupPolyPointsList( poly ); for( wxPoint& point : poly ) { diff --git a/pcbnew/pcb_shape.cpp b/pcbnew/pcb_shape.cpp index f9461cd942..bad23b12cb 100644 --- a/pcbnew/pcb_shape.cpp +++ b/pcbnew/pcb_shape.cpp @@ -1274,20 +1274,20 @@ std::shared_ptr PCB_SHAPE::GetEffectiveShape( PCB_LAYER_ID aLayer ) const } -const std::vector PCB_SHAPE::BuildPolyPointsList() const +void PCB_SHAPE::DupPolyPointsList( std::vector& aBuffer ) const { - std::vector rv; - if( m_poly.OutlineCount() ) { - if( m_poly.COutline( 0 ).PointCount() ) + int pointCount = m_poly.COutline( 0 ).PointCount(); + + if( pointCount ) { + aBuffer.reserve( pointCount ); + for ( auto iter = m_poly.CIterate(); iter; iter++ ) - rv.emplace_back( iter->x, iter->y ); + aBuffer.emplace_back( iter->x, iter->y ); } } - - return rv; } diff --git a/pcbnew/pcb_shape.h b/pcbnew/pcb_shape.h index a10288eaab..c1139f0947 100644 --- a/pcbnew/pcb_shape.h +++ b/pcbnew/pcb_shape.h @@ -223,13 +223,13 @@ public: const std::vector& GetBezierPoints() const { return m_bezierPoints; } /** - * Build and return the list of corners in a std::vector + * Duplicate the list of corners in a std::vector * * It must be used only to convert the SHAPE_POLY_SET internal corner buffer * to a list of wxPoints, and nothing else, because it duplicates the buffer, * that is inefficient to know for instance the corner count */ - const std::vector BuildPolyPointsList() const; + void DupPolyPointsList( std::vector& aBuffer ) const; /** * @return the number of corners of the polygonal shape diff --git a/pcbnew/plot_brditems_plotter.cpp b/pcbnew/plot_brditems_plotter.cpp index e4a8129792..210d5a0c8c 100644 --- a/pcbnew/plot_brditems_plotter.cpp +++ b/pcbnew/plot_brditems_plotter.cpp @@ -627,25 +627,20 @@ void BRDITEMS_PLOTTER::PlotFootprintGraphicItem( const FP_SHAPE* aShape ) case SHAPE_T::POLY: if( aShape->IsPolyShapeValid() ) { - const std::vector &polyPoints = aShape->BuildPolyPointsList(); + std::vector cornerList; + aShape->DupPolyPointsList( cornerList ); // We must compute board coordinates from m_PolyList which are relative to the parent // position at orientation 0 const FOOTPRINT *parentFootprint = aShape->GetParentFootprint(); - std::vector cornerList; - - cornerList.reserve( polyPoints.size() ); - - for( wxPoint corner : polyPoints ) + if( parentFootprint ) { - if( parentFootprint ) + for( wxPoint corner : cornerList ) { RotatePoint( &corner, parentFootprint->GetOrientation() ); corner += parentFootprint->GetPosition(); } - - cornerList.push_back( corner ); } if( sketch || thickness > 0 ) diff --git a/pcbnew/tools/pcb_grid_helper.cpp b/pcbnew/tools/pcb_grid_helper.cpp index 640cb72a31..d2456045f0 100644 --- a/pcbnew/tools/pcb_grid_helper.cpp +++ b/pcbnew/tools/pcb_grid_helper.cpp @@ -579,8 +579,10 @@ void PCB_GRID_HELPER::computeAnchors( BOARD_ITEM* aItem, const VECTOR2I& aRefPos { SHAPE_LINE_CHAIN lc; lc.SetClosed( true ); + std::vector poly; + shape->DupPolyPointsList( poly ); - for( const wxPoint& p : shape->BuildPolyPointsList() ) + for( const wxPoint& p : poly ) { addAnchor( p, CORNER | SNAPPABLE, shape ); lc.Append( p ); diff --git a/pcbnew/tools/pcb_point_editor.cpp b/pcbnew/tools/pcb_point_editor.cpp index a3581123b6..f31d5b9ff0 100644 --- a/pcbnew/tools/pcb_point_editor.cpp +++ b/pcbnew/tools/pcb_point_editor.cpp @@ -1596,7 +1596,8 @@ void PCB_POINT_EDITOR::updatePoints() case SHAPE_T::POLY: { - const auto& points = shape->BuildPolyPointsList(); + std::vector points; + shape->DupPolyPointsList( points ); if( m_editPoints->PointsSize() != (unsigned) points.size() ) {