Rename BuildPolyPointsList() to DupPolyPointsList() and optimize code
to avoid multiple useless copies of the list of polygon corners in code.
This commit is contained in:
parent
09ddcdbbca
commit
3316f3998a
|
@ -488,7 +488,7 @@ void PCB_SHAPE::TransformShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerBuf
|
|||
|
||||
// Build the polygon with the actual position and orientation:
|
||||
std::vector<wxPoint> poly;
|
||||
poly = BuildPolyPointsList();
|
||||
DupPolyPointsList( poly );
|
||||
|
||||
for( wxPoint& point : poly )
|
||||
{
|
||||
|
|
|
@ -1274,20 +1274,20 @@ std::shared_ptr<SHAPE> PCB_SHAPE::GetEffectiveShape( PCB_LAYER_ID aLayer ) const
|
|||
}
|
||||
|
||||
|
||||
const std::vector<wxPoint> PCB_SHAPE::BuildPolyPointsList() const
|
||||
void PCB_SHAPE::DupPolyPointsList( std::vector<wxPoint>& aBuffer ) const
|
||||
{
|
||||
std::vector<wxPoint> rv;
|
||||
|
||||
if( m_poly.OutlineCount() )
|
||||
{
|
||||
if( m_poly.COutline( 0 ).PointCount() )
|
||||
{
|
||||
for ( auto iter = m_poly.CIterate(); iter; iter++ )
|
||||
rv.emplace_back( iter->x, iter->y );
|
||||
}
|
||||
}
|
||||
int pointCount = m_poly.COutline( 0 ).PointCount();
|
||||
|
||||
return rv;
|
||||
if( pointCount )
|
||||
{
|
||||
aBuffer.reserve( pointCount );
|
||||
|
||||
for ( auto iter = m_poly.CIterate(); iter; iter++ )
|
||||
aBuffer.emplace_back( iter->x, iter->y );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -223,13 +223,13 @@ public:
|
|||
const std::vector<wxPoint>& GetBezierPoints() const { return m_bezierPoints; }
|
||||
|
||||
/**
|
||||
* Build and return the list of corners in a std::vector<wxPoint>
|
||||
* Duplicate the list of corners in a std::vector<wxPoint>
|
||||
*
|
||||
* 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<wxPoint> BuildPolyPointsList() const;
|
||||
void DupPolyPointsList( std::vector<wxPoint>& aBuffer ) const;
|
||||
|
||||
/**
|
||||
* @return the number of corners of the polygonal shape
|
||||
|
|
|
@ -627,25 +627,20 @@ void BRDITEMS_PLOTTER::PlotFootprintGraphicItem( const FP_SHAPE* aShape )
|
|||
case SHAPE_T::POLY:
|
||||
if( aShape->IsPolyShapeValid() )
|
||||
{
|
||||
const std::vector<wxPoint> &polyPoints = aShape->BuildPolyPointsList();
|
||||
std::vector<wxPoint> 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<wxPoint> cornerList;
|
||||
|
||||
cornerList.reserve( polyPoints.size() );
|
||||
|
||||
for( wxPoint corner : polyPoints )
|
||||
{
|
||||
if( parentFootprint )
|
||||
{
|
||||
for( wxPoint corner : cornerList )
|
||||
{
|
||||
RotatePoint( &corner, parentFootprint->GetOrientation() );
|
||||
corner += parentFootprint->GetPosition();
|
||||
}
|
||||
|
||||
cornerList.push_back( corner );
|
||||
}
|
||||
|
||||
if( sketch || thickness > 0 )
|
||||
|
|
|
@ -579,8 +579,10 @@ void PCB_GRID_HELPER::computeAnchors( BOARD_ITEM* aItem, const VECTOR2I& aRefPos
|
|||
{
|
||||
SHAPE_LINE_CHAIN lc;
|
||||
lc.SetClosed( true );
|
||||
std::vector<wxPoint> poly;
|
||||
shape->DupPolyPointsList( poly );
|
||||
|
||||
for( const wxPoint& p : shape->BuildPolyPointsList() )
|
||||
for( const wxPoint& p : poly )
|
||||
{
|
||||
addAnchor( p, CORNER | SNAPPABLE, shape );
|
||||
lc.Append( p );
|
||||
|
|
|
@ -1596,7 +1596,8 @@ void PCB_POINT_EDITOR::updatePoints()
|
|||
|
||||
case SHAPE_T::POLY:
|
||||
{
|
||||
const auto& points = shape->BuildPolyPointsList();
|
||||
std::vector<wxPoint> points;
|
||||
shape->DupPolyPointsList( points );
|
||||
|
||||
if( m_editPoints->PointsSize() != (unsigned) points.size() )
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue