SHAPE_LINE_CHAIN: Unify constructors

Keeps the multi element SHAPE_LINE_CHAIN constructors in a single
routine using std::vector and implicit construction.
This commit is contained in:
Seth Hillbrand 2019-03-24 06:54:56 -07:00
parent c4d853c1e8
commit eb3d32f967
12 changed files with 61 additions and 108 deletions

View File

@ -627,15 +627,10 @@ void Convert_path_polygon_to_polygon_blocks_and_dummy_blocks(
SHAPE_POLY_SET subBlockPoly;
SHAPE_LINE_CHAIN sb = SHAPE_LINE_CHAIN(
VECTOR2I( leftToRight,
topToBottom ),
VECTOR2I( leftToRight + leftToRight_inc,
topToBottom ),
VECTOR2I( leftToRight + leftToRight_inc,
topToBottom + topToBottom_inc ),
VECTOR2I( leftToRight,
topToBottom + topToBottom_inc ) );
SHAPE_LINE_CHAIN sb = SHAPE_LINE_CHAIN( { VECTOR2I( leftToRight, topToBottom ),
VECTOR2I( leftToRight + leftToRight_inc, topToBottom ),
VECTOR2I( leftToRight + leftToRight_inc, topToBottom + topToBottom_inc ),
VECTOR2I( leftToRight, topToBottom + topToBottom_inc ) } );
//sb.Append( leftToRight, topToBottom );
sb.SetClosed( true );

View File

@ -427,7 +427,7 @@ void GRFilledSegment( EDA_RECT* aClipBox, wxDC* aDC, wxPoint aStart, wxPoint aEn
}
static bool IsGRSPolyDrawable( EDA_RECT* ClipBox, int n, const wxPoint* Points, )
static bool IsGRSPolyDrawable( EDA_RECT* ClipBox, int n, const wxPoint* Points )
{
if( !ClipBox )
return true;
@ -957,7 +957,7 @@ void ClipAndDrawPoly( EDA_RECT* aClipBox, wxDC* aDC, const wxPoint* Points, int
{
if( aClipBox == NULL )
{
aDC->DrawPolygon( n, aPoints );
aDC->DrawPolygon( n, Points );
return;
}
@ -970,7 +970,7 @@ void ClipAndDrawPoly( EDA_RECT* aClipBox, wxDC* aDC, const wxPoint* Points, int
clippedPolygon.clear();
for( int ii = 0; ii < n; ii++ )
inputPolygon.push_back( PointF( (REAL) aPoints[ii].x, (REAL) aPoints[ii].y ) );
inputPolygon.push_back( PointF( (REAL) Points[ii].x, (REAL) Points[ii].y ) );
RectF window( (REAL) aClipBox->GetX(), (REAL) aClipBox->GetY(),
(REAL) aClipBox->GetWidth(), (REAL) aClipBox->GetHeight() );

View File

@ -21,10 +21,12 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <limits>
#include <vector>
#include <preview_items/polygon_geom_manager.h>
#include <geometry/geometry_utils.h>
#include <geometry/shape_line_chain.h>
POLYGON_GEOM_MANAGER::POLYGON_GEOM_MANAGER( CLIENT& aClient ):
@ -181,13 +183,13 @@ void POLYGON_GEOM_MANAGER::updateLeaderPoints( const VECTOR2I& aEndPoint, LEADER
}
}
m_leaderPts = SHAPE_LINE_CHAIN( last_pt, new_end );
m_leaderPts = SHAPE_LINE_CHAIN( { last_pt, new_end } );
if( pt )
{
// This checks for backtracking from the point to intersection
if( SEG( last_pt, new_end ).Collinear( SEG( new_end, *pt ) ) )
m_leaderPts = SHAPE_LINE_CHAIN( last_pt, *pt );
m_leaderPts = SHAPE_LINE_CHAIN( { last_pt, *pt } );
else
m_leaderPts.Append( *pt );
}
@ -195,7 +197,7 @@ void POLYGON_GEOM_MANAGER::updateLeaderPoints( const VECTOR2I& aEndPoint, LEADER
else
{
// direct segment
m_leaderPts = SHAPE_LINE_CHAIN( last_pt, aEndPoint );
m_leaderPts = SHAPE_LINE_CHAIN( { last_pt, aEndPoint } );
}
m_client.OnGeometryChange( *this );

View File

@ -26,8 +26,9 @@
#ifndef __SHAPE_LINE_CHAIN
#define __SHAPE_LINE_CHAIN
#include <vector>
#include <sstream>
#include <vector>
#include <wx/gdicmn.h>
#include <core/optional.h>
@ -70,6 +71,7 @@ public:
typedef std::vector<INTERSECTION> INTERSECTIONS;
/**
* Constructor
* Initializes an empty line chain.
@ -85,50 +87,8 @@ public:
SHAPE( SH_LINE_CHAIN ), m_points( aShape.m_points ), m_closed( aShape.m_closed )
{}
/**
* Constructor
* Initializes a 2-point line chain (a single segment)
*/
SHAPE_LINE_CHAIN( const VECTOR2I& aA, const VECTOR2I& aB ) :
SHAPE( SH_LINE_CHAIN ), m_closed( false )
{
m_points.resize( 2 );
m_points[0] = aA;
m_points[1] = aB;
}
SHAPE_LINE_CHAIN( const VECTOR2I& aA, const VECTOR2I& aB, const VECTOR2I& aC ) :
SHAPE( SH_LINE_CHAIN ), m_closed( false )
{
m_points.resize( 3 );
m_points[0] = aA;
m_points[1] = aB;
m_points[2] = aC;
}
SHAPE_LINE_CHAIN( const VECTOR2I& aA, const VECTOR2I& aB, const VECTOR2I& aC, const VECTOR2I& aD ) :
SHAPE( SH_LINE_CHAIN ), m_closed( false )
{
m_points.resize( 4 );
m_points[0] = aA;
m_points[1] = aB;
m_points[2] = aC;
m_points[3] = aD;
}
SHAPE_LINE_CHAIN( const VECTOR2I* aV, int aCount ) :
SHAPE( SH_LINE_CHAIN ),
m_closed( false )
{
m_points.resize( aCount );
for( int i = 0; i < aCount; i++ )
m_points[i] = *aV++;
}
SHAPE_LINE_CHAIN( const std::vector<wxPoint>& aV ) :
SHAPE( SH_LINE_CHAIN ),
m_closed( false )
SHAPE_LINE_CHAIN( const std::vector<wxPoint>& aV, bool aClosed = false )
: SHAPE( SH_LINE_CHAIN ), m_closed( aClosed )
{
m_points.reserve( aV.size() );
@ -136,9 +96,8 @@ public:
m_points.emplace_back( pt.x, pt.y );
}
SHAPE_LINE_CHAIN( const std::vector<VECTOR2I>& aV ) :
SHAPE( SH_LINE_CHAIN ),
m_closed( false )
SHAPE_LINE_CHAIN( const std::vector<VECTOR2I>& aV, bool aClosed = false )
: SHAPE( SH_LINE_CHAIN ), m_closed( aClosed )
{
m_points = aV;
}
@ -153,7 +112,7 @@ public:
m_points.emplace_back( point.X, point.Y );
}
~SHAPE_LINE_CHAIN()
virtual ~SHAPE_LINE_CHAIN()
{}
SHAPE* Clone() const override;

View File

@ -429,9 +429,8 @@ void DRAWSEGMENT::Print( PCB_BASE_FRAME* aFrame, wxDC* DC, const wxPoint& aOffse
for( int jj = 0; jj < outline.OutlineCount(); ++jj )
{
SHAPE_LINE_CHAIN& poly = outline.Outline( jj );
GRClosedPoly( nullptr, DC, poly.PointCount(),
static_cast<const wxPoint*>( &poly.CPoint( 0 ) ),
IsPolygonFilled(), GetWidth(), color, color );
GRClosedPoly( nullptr, DC, poly.PointCount(), (const wxPoint*) &poly.CPoint( 0 ),
IsPolygonFilled(), GetWidth(), color, color );
}
}
break;

View File

@ -281,8 +281,8 @@ void D_PAD::PrintShape( wxDC* aDC, PAD_DRAWINFO& aDrawInfo )
if( poly.PointCount() > 0 )
{
GRClosedPoly( nullptr, aDC, poly.PointCount(),
static_cast<const wxPoint*>( &poly.CPoint( 0 ) ),
false, 0, aDrawInfo.m_Color, aDrawInfo.m_Color );
(const wxPoint*) &poly.CPoint( 0 ), false, 0, aDrawInfo.m_Color,
aDrawInfo.m_Color );
}
}
}
@ -308,9 +308,8 @@ void D_PAD::PrintShape( wxDC* aDC, PAD_DRAWINFO& aDrawInfo )
SHAPE_LINE_CHAIN& poly = outline.Outline( 0 );
GRClosedPoly( nullptr, aDC, poly.PointCount(),
static_cast<const wxPoint*>( &poly.CPoint( 0 ) ), filled, 0,
aDrawInfo.m_Color, aDrawInfo.m_Color );
GRClosedPoly( nullptr, aDC, poly.PointCount(), (const wxPoint*) &poly.CPoint( 0 ), filled,
0, aDrawInfo.m_Color, aDrawInfo.m_Color );
if( aDrawInfo.m_PadClearance )
{
@ -329,8 +328,8 @@ void D_PAD::PrintShape( wxDC* aDC, PAD_DRAWINFO& aDrawInfo )
SHAPE_LINE_CHAIN& clearance_poly = outline.Outline( 0 );
GRClosedPoly( nullptr, aDC, clearance_poly.PointCount(),
static_cast<const wxPoint*>( &clearance_poly.CPoint( 0 ) ), false, 0,
aDrawInfo.m_Color, aDrawInfo.m_Color );
(const wxPoint*) &clearance_poly.CPoint( 0 ), false, 0, aDrawInfo.m_Color,
aDrawInfo.m_Color );
}
}
break;
@ -390,8 +389,8 @@ void D_PAD::PrintShape( wxDC* aDC, PAD_DRAWINFO& aDrawInfo )
{
auto& poly = outline.Outline( jj );
GRClosedPoly( nullptr, aDC, poly.PointCount(), static_cast<const wxPoint*>( &poly.CPoint( 0 ) ),
aDrawInfo.m_ShowPadFilled, 0, aDrawInfo.m_Color, aDrawInfo.m_Color );
GRClosedPoly( nullptr, aDC, poly.PointCount(), (const wxPoint*) &poly.CPoint( 0 ),
aDrawInfo.m_ShowPadFilled, 0, aDrawInfo.m_Color, aDrawInfo.m_Color );
}
if( aDrawInfo.m_PadClearance )
@ -410,8 +409,8 @@ void D_PAD::PrintShape( wxDC* aDC, PAD_DRAWINFO& aDrawInfo )
if( poly.PointCount() > 0 )
{
GRClosedPoly( nullptr, aDC, poly.PointCount(),
static_cast<const wxPoint*>( &poly.CPoint( 0 ) ),
false, 0, aDrawInfo.m_Color, aDrawInfo.m_Color );
(const wxPoint*) &poly.CPoint( 0 ), false, 0, aDrawInfo.m_Color,
aDrawInfo.m_Color );
}
}
}

View File

@ -690,8 +690,7 @@ void BRDITEMS_PLOTTER::PlotFilledAreas( ZONE_CONTAINER* aZone, SHAPE_POLY_SET& p
for( int ic = 0; ic < outline.PointCount(); ++ic )
{
VECTOR2I& point = outline.Point( ic );
cornerList.emplace_back( wxPoint( point.x, point.y ) );
cornerList.emplace_back( wxPoint( outline.CPoint( ic ) ) );
}
if( cornerList.size() ) // Plot the current filled area outline

View File

@ -520,8 +520,8 @@ void DP_GATEWAYS::BuildFromPrimitivePair( const DP_PRIMITIVE_PAIR& aPair, bool a
VECTOR2I gw_p( p0_p + sign * ( dir + dp ) + dv );
VECTOR2I gw_n( p0_n + sign * ( dir + dp ) - dv );
SHAPE_LINE_CHAIN entryP( p0_p, p0_p + sign * dir, gw_p );
SHAPE_LINE_CHAIN entryN( p0_n, p0_n + sign * dir, gw_n );
SHAPE_LINE_CHAIN entryP( { p0_p, p0_p + sign * dir, gw_p } );
SHAPE_LINE_CHAIN entryN( { p0_n, p0_n + sign * dir, gw_n } );
DP_GATEWAY gw( gw_p, gw_n, false );

View File

@ -548,8 +548,8 @@ bool LINE_PLACER::rhStopAtNearestObstacle( const VECTOR2I& aP, LINE& aNewHead )
SEG segL( s.B, leadL.LineProject( aP ) );
SEG segR( s.B, leadR.LineProject( aP ) );
LINE finishL( l0, SHAPE_LINE_CHAIN( segL.A, segL.B ) );
LINE finishR( l0, SHAPE_LINE_CHAIN( segR.A, segR.B ) );
LINE finishL( l0, SHAPE_LINE_CHAIN( { segL.A, segL.B } ) );
LINE finishR( l0, SHAPE_LINE_CHAIN( { segR.A, segR.B } ) );
LINE reducedL = reduceToNearestObstacle( finishL );
LINE reducedR = reduceToNearestObstacle( finishR );
@ -1213,7 +1213,7 @@ bool LINE_PLACER::buildInitialLine( const VECTOR2I& aP, LINE& aHead, bool aInver
{
if( Settings().GetFreeAngleMode() && Settings().Mode() == RM_MarkObstacles )
{
l = SHAPE_LINE_CHAIN( m_p_start, aP );
l = SHAPE_LINE_CHAIN( { m_p_start, aP } );
}
else
{

View File

@ -723,10 +723,10 @@ OPTIMIZER::BREAKOUT_LIST OPTIMIZER::rectBreakouts( int aWidth,
VECTOR2I d_vert = VECTOR2I( 0, s.y / 2 + aWidth );
VECTOR2I d_horiz = VECTOR2I( s.x / 2 + aWidth, 0 );
breakouts.push_back( SHAPE_LINE_CHAIN( c, c + d_horiz ) );
breakouts.push_back( SHAPE_LINE_CHAIN( c, c - d_horiz ) );
breakouts.push_back( SHAPE_LINE_CHAIN( c, c + d_vert ) );
breakouts.push_back( SHAPE_LINE_CHAIN( c, c - d_vert ) );
breakouts.push_back( SHAPE_LINE_CHAIN( { c, c + d_horiz } ) );
breakouts.push_back( SHAPE_LINE_CHAIN( { c, c - d_horiz } ) );
breakouts.push_back( SHAPE_LINE_CHAIN( { c, c + d_vert } ) );
breakouts.push_back( SHAPE_LINE_CHAIN( { c, c - d_vert } ) );
if( aPermitDiagonal )
{
@ -735,26 +735,26 @@ OPTIMIZER::BREAKOUT_LIST OPTIMIZER::rectBreakouts( int aWidth,
if( s.x >= s.y )
{
breakouts.push_back( SHAPE_LINE_CHAIN( c, c + d_offset,
c + d_offset + VECTOR2I( l, l ) ) );
breakouts.push_back( SHAPE_LINE_CHAIN( c, c + d_offset,
c + d_offset - VECTOR2I( -l, l ) ) );
breakouts.push_back( SHAPE_LINE_CHAIN( c, c - d_offset,
c - d_offset + VECTOR2I( -l, l ) ) );
breakouts.push_back( SHAPE_LINE_CHAIN( c, c - d_offset,
c - d_offset - VECTOR2I( l, l ) ) );
breakouts.push_back(
SHAPE_LINE_CHAIN( { c, c + d_offset, c + d_offset + VECTOR2I( l, l ) } ) );
breakouts.push_back(
SHAPE_LINE_CHAIN( { c, c + d_offset, c + d_offset - VECTOR2I( -l, l ) } ) );
breakouts.push_back(
SHAPE_LINE_CHAIN( { c, c - d_offset, c - d_offset + VECTOR2I( -l, l ) } ) );
breakouts.push_back(
SHAPE_LINE_CHAIN( { c, c - d_offset, c - d_offset - VECTOR2I( l, l ) } ) );
}
else
{
// fixme: this could be done more efficiently
breakouts.push_back( SHAPE_LINE_CHAIN( c, c + d_offset,
c + d_offset + VECTOR2I( l, l ) ) );
breakouts.push_back( SHAPE_LINE_CHAIN( c, c - d_offset,
c - d_offset - VECTOR2I( -l, l ) ) );
breakouts.push_back( SHAPE_LINE_CHAIN( c, c + d_offset,
c + d_offset + VECTOR2I( -l, l ) ) );
breakouts.push_back( SHAPE_LINE_CHAIN( c, c - d_offset,
c - d_offset - VECTOR2I( l, l ) ) );
breakouts.push_back(
SHAPE_LINE_CHAIN( { c, c + d_offset, c + d_offset + VECTOR2I( l, l ) } ) );
breakouts.push_back(
SHAPE_LINE_CHAIN( { c, c - d_offset, c - d_offset - VECTOR2I( -l, l ) } ) );
breakouts.push_back(
SHAPE_LINE_CHAIN( { c, c + d_offset, c + d_offset + VECTOR2I( -l, l ) } ) );
breakouts.push_back(
SHAPE_LINE_CHAIN( { c, c - d_offset, c - d_offset - VECTOR2I( l, l ) } ) );
}
}

View File

@ -97,7 +97,7 @@ public:
const SHAPE_LINE_CHAIN CLine() const
{
return SHAPE_LINE_CHAIN( m_seg.GetSeg().A, m_seg.GetSeg().B );
return SHAPE_LINE_CHAIN( { m_seg.GetSeg().A, m_seg.GetSeg().B } );
}
void SetEnds( const VECTOR2I& a, const VECTOR2I& b )

View File

@ -35,7 +35,7 @@ SHAPE_LINE_CHAIN BuildRectChain( const VECTOR2I& aSize, const VECTOR2I& aCentre
{ aCentre.x + aSize.x / 2, aCentre.y - aSize.y / 2 },
};
SHAPE_LINE_CHAIN chain( pts.data(), pts.size() );
SHAPE_LINE_CHAIN chain( pts );
chain.SetClosed( true );
return chain;
@ -46,4 +46,4 @@ SHAPE_LINE_CHAIN BuildSquareChain( int aSize, const VECTOR2I& aCentre )
return BuildRectChain( { aSize, aSize }, aCentre );
}
} // namespace KI_TEST
} // namespace KI_TEST