KiCad PCB EDA Suite
SHAPE_LINE_CHAIN Class Reference

SHAPE_LINE_CHAIN. More...

#include <shape_line_chain.h>

Inheritance diagram for SHAPE_LINE_CHAIN:
SHAPE_LINE_CHAIN_BASE SHAPE SHAPE_BASE

Classes

struct  compareOriginDistance
 
struct  INTERSECTION
 Struct INTERSECTION. More...
 
class  POINT_INSIDE_TRACKER
 Class POINT_INSIDE_TRACKER. More...
 

Public Types

typedef std::vector< INTERSECTIONINTERSECTIONS
 

Public Member Functions

 SHAPE_LINE_CHAIN ()
 Constructor Initializes an empty line chain. More...
 
 SHAPE_LINE_CHAIN (const SHAPE_LINE_CHAIN &aShape)
 Copy Constructor. More...
 
 SHAPE_LINE_CHAIN (const std::vector< int > &aV)
 
 SHAPE_LINE_CHAIN (const std::vector< wxPoint > &aV, bool aClosed=false)
 
 SHAPE_LINE_CHAIN (const std::vector< VECTOR2I > &aV, bool aClosed=false)
 
 SHAPE_LINE_CHAIN (const SHAPE_ARC &aArc, bool aClosed=false)
 
 SHAPE_LINE_CHAIN (const ClipperLib::Path &aPath)
 
virtual ~SHAPE_LINE_CHAIN ()
 
SHAPE_LINE_CHAINoperator= (const SHAPE_LINE_CHAIN &)=default
 
SHAPEClone () const override
 Function Clone() More...
 
void Clear ()
 Function Clear() Removes all points from the line chain. More...
 
void SetClosed (bool aClosed)
 Function SetClosed() More...
 
bool IsClosed () const override
 Function IsClosed() More...
 
void SetWidth (int aWidth)
 Sets the width of all segments in the chain. More...
 
int Width () const
 Gets the current width of the segments in the chain. More...
 
int SegmentCount () const
 Function SegmentCount() More...
 
int PointCount () const
 Function PointCount() More...
 
SEG Segment (int aIndex)
 Function Segment() More...
 
const SEG CSegment (int aIndex) const
 Function CSegment() More...
 
void SetPoint (int aIndex, const VECTOR2I &aPos)
 Accessor Function to move a point to a specific location. More...
 
const VECTOR2ICPoint (int aIndex) const
 Function Point() More...
 
const std::vector< VECTOR2I > & CPoints () const
 
const VECTOR2ICLastPoint () const
 Returns the last point in the line chain. More...
 
const std::vector< SHAPE_ARC > & CArcs () const
 
const std::vector< ssize_t > & CShapes () const
 
const BOX2I BBox (int aClearance=0) const override
 Function BBox() More...
 
void GenerateBBoxCache ()
 
const BOX2I BBoxFromCache () const
 
int Distance (const VECTOR2I &aP, bool aOutlineOnly=false) const
 Function Distance() More...
 
const SHAPE_LINE_CHAIN Reverse () const
 Function Reverse() More...
 
long long int Length () const
 Function Length() More...
 
void Append (int aX, int aY, bool aAllowDuplication=false)
 Function Append() More...
 
void Append (const VECTOR2I &aP, bool aAllowDuplication=false)
 Function Append() More...
 
void Append (const SHAPE_LINE_CHAIN &aOtherLine)
 Function Append() More...
 
void Append (const SHAPE_ARC &aArc)
 
void Insert (size_t aVertex, const VECTOR2I &aP)
 
void Insert (size_t aVertex, const SHAPE_ARC &aArc)
 
void Replace (int aStartIndex, int aEndIndex, const VECTOR2I &aP)
 Function Replace() More...
 
void Replace (int aStartIndex, int aEndIndex, const SHAPE_LINE_CHAIN &aLine)
 Function Replace() More...
 
void Remove (int aStartIndex, int aEndIndex)
 Function Remove() More...
 
void Remove (int aIndex)
 Function Remove() removes the aIndex-th point from the line chain. More...
 
int Split (const VECTOR2I &aP)
 Function Split() More...
 
int Find (const VECTOR2I &aP) const
 Function Find() More...
 
int FindSegment (const VECTOR2I &aP) const
 Function FindSegment() More...
 
const SHAPE_LINE_CHAIN Slice (int aStartIndex, int aEndIndex=-1) const
 Function Slice() More...
 
bool Intersects (const SHAPE_LINE_CHAIN &aChain) const
 
int Intersect (const SEG &aSeg, INTERSECTIONS &aIp) const
 Function Intersect() More...
 
int Intersect (const SHAPE_LINE_CHAIN &aChain, INTERSECTIONS &aIp) const
 Function Intersect() More...
 
int PathLength (const VECTOR2I &aP) const
 Function PathLength() More...
 
bool CheckClearance (const VECTOR2I &aP, const int aDist) const
 Function CheckClearance() More...
 
const OPT< INTERSECTIONSelfIntersecting () const
 Function SelfIntersecting() More...
 
SHAPE_LINE_CHAINSimplify ()
 Function Simplify() More...
 
void convertArc (ssize_t aArcIndex)
 Converts an arc to only a point chain by removing the arc and references. More...
 
ClipperLib::Path convertToClipper (bool aRequiredOrientation) const
 Creates a new Clipper path from the SHAPE_LINE_CHAIN in a given orientation. More...
 
int NearestSegment (const VECTOR2I &aP) const
 Find the segment nearest the given point. More...
 
const VECTOR2I NearestPoint (const VECTOR2I &aP) const
 Function NearestPoint() More...
 
const VECTOR2I NearestPoint (const SEG &aSeg, int &dist) const
 Function NearestPoint() More...
 
const std::string Format () const override
 
bool Parse (std::stringstream &aStream) override
 
bool operator!= (const SHAPE_LINE_CHAIN &aRhs) const
 
bool CompareGeometry (const SHAPE_LINE_CHAIN &aOther) const
 
void Move (const VECTOR2I &aVector) override
 
void Mirror (bool aX=true, bool aY=false, const VECTOR2I &aRef={ 0, 0 })
 Mirrors the line points about y or x (or both) More...
 
void Rotate (double aAngle, const VECTOR2I &aCenter=VECTOR2I(0, 0)) override
 Function Rotate rotates all vertices by a given angle. More...
 
bool IsSolid () const override
 
const VECTOR2I PointAlong (int aPathLength) const
 
double Area () const
 
size_t ArcCount () const
 
ssize_t ArcIndex (size_t aSegment) const
 
const SHAPE_ARCArc (size_t aArc) const
 
bool isArc (size_t aSegment) const
 
virtual const VECTOR2I GetPoint (int aIndex) const override
 
virtual const SEG GetSegment (int aIndex) const override
 
virtual size_t GetPointCount () const override
 
virtual size_t GetSegmentCount () const override
 
virtual bool Collide (const VECTOR2I &aP, int aClearance=0, int *aActual=nullptr) const override
 Function Collide() More...
 
virtual bool Collide (const SEG &aSeg, int aClearance=0, int *aActual=nullptr) const override
 Function Collide() More...
 
virtual bool Collide (const SHAPE *aShape, int aClearance, VECTOR2I *aMTV) const
 Function Collide() More...
 
virtual bool Collide (const SHAPE *aShape, int aClearance=0, int *aActual=nullptr) const
 
SEG::ecoord SquaredDistance (const VECTOR2I &aP, bool aOutlineOnly=false) const
 
bool PointInside (const VECTOR2I &aPt, int aAccuracy=0, bool aUseBBoxCache=false) const
 Function PointInside() More...
 
bool PointOnEdge (const VECTOR2I &aP, int aAccuracy=0) const
 Function PointOnEdge() More...
 
int EdgeContainingPoint (const VECTOR2I &aP, int aAccuracy=0) const
 Function EdgeContainingPoint() More...
 
bool IsNull () const
 Function IsNull() More...
 
virtual VECTOR2I Centre () const
 Function Centre() More...
 
FACETNewFacet ()
 
SGNODECalcShape (SGNODE *aParent, SGNODE *aColor, WRL1_ORDER aVertexOrder, float aCreaseLimit=0.74317, bool isVRML2=false)
 
SHAPE_TYPE Type () const
 Function Type() More...
 
virtual bool HasIndexableSubshapes () const
 
virtual size_t GetIndexableSubshapeCount ()
 
virtual void GetIndexableSubshape (SHAPE_BASE &aSubshape) const
 

Protected Types

typedef VECTOR2I::extended_type ecoord
 

Protected Attributes

SHAPE_TYPE m_type
 

type of our shape

More...
 

Private Types

typedef std::vector< VECTOR2I >::iterator point_iter
 
typedef std::vector< VECTOR2I >::const_iterator point_citer
 

Private Attributes

std::vector< VECTOR2Im_points
 array of vertices More...
 
std::vector< ssize_t > m_shapes
 Array of indices that refer to the index of the shape if the point is part of a larger shape, e.g. More...
 
std::vector< SHAPE_ARCm_arcs
 
bool m_closed
 is the line chain closed? More...
 
int m_width
 Width of the segments (for BBox calculations in RTree) TODO Adjust usage of SHAPE_LINE_CHAIN to account for where we need a width and where not Alternatively, we could split the class into a LINE_CHAIN (no width) and SHAPE_LINE_CHAIN that derives from SHAPE as well that does have a width. More...
 
BOX2I m_bbox
 cached bounding box More...
 

Static Private Attributes

static constexpr ssize_t SHAPE_IS_PT = -1
 

Detailed Description

SHAPE_LINE_CHAIN.

Represents a polyline (an zero-thickness chain of connected line segments). I purposedly didn't name it "polyline" to avoid confusion with the existing CPolyLine in pcbnew.

SHAPE_LINE_CHAIN class shall not be used for polygons!

Definition at line 46 of file shape_line_chain.h.

Member Typedef Documentation

◆ ecoord

typedef VECTOR2I::extended_type SHAPE::ecoord
protectedinherited

Definition at line 123 of file shape.h.

◆ INTERSECTIONS

Definition at line 95 of file shape_line_chain.h.

◆ point_citer

typedef std::vector<VECTOR2I>::const_iterator SHAPE_LINE_CHAIN::point_citer
private

Definition at line 50 of file shape_line_chain.h.

◆ point_iter

typedef std::vector<VECTOR2I>::iterator SHAPE_LINE_CHAIN::point_iter
private

Definition at line 49 of file shape_line_chain.h.

Constructor & Destructor Documentation

◆ SHAPE_LINE_CHAIN() [1/7]

SHAPE_LINE_CHAIN::SHAPE_LINE_CHAIN ( )
inline

Constructor Initializes an empty line chain.

Definition at line 102 of file shape_line_chain.h.

103  {}
SHAPE_LINE_CHAIN_BASE(SHAPE_TYPE aType)
Definition: shape.h:245
bool m_closed
is the line chain closed?
int m_width
Width of the segments (for BBox calculations in RTree) TODO Adjust usage of SHAPE_LINE_CHAIN to accou...
line segment
Definition: shape.h:44

Referenced by Clone().

◆ SHAPE_LINE_CHAIN() [2/7]

SHAPE_LINE_CHAIN::SHAPE_LINE_CHAIN ( const SHAPE_LINE_CHAIN aShape)
inline

Copy Constructor.

Definition at line 109 of file shape_line_chain.h.

111  m_points( aShape.m_points ),
112  m_shapes( aShape.m_shapes ),
113  m_arcs( aShape.m_arcs ),
114  m_closed( aShape.m_closed ),
115  m_width( aShape.m_width ),
116  m_bbox( aShape.m_bbox )
117  {}
SHAPE_LINE_CHAIN_BASE(SHAPE_TYPE aType)
Definition: shape.h:245
BOX2I m_bbox
cached bounding box
std::vector< SHAPE_ARC > m_arcs
bool m_closed
is the line chain closed?
std::vector< VECTOR2I > m_points
array of vertices
std::vector< ssize_t > m_shapes
Array of indices that refer to the index of the shape if the point is part of a larger shape,...
int m_width
Width of the segments (for BBox calculations in RTree) TODO Adjust usage of SHAPE_LINE_CHAIN to accou...
line segment
Definition: shape.h:44

◆ SHAPE_LINE_CHAIN() [3/7]

SHAPE_LINE_CHAIN::SHAPE_LINE_CHAIN ( const std::vector< int > &  aV)

Definition at line 39 of file shape_line_chain.cpp.

41 {
42  for(size_t i = 0; i < aV.size(); i+= 2 )
43  {
44  Append( aV[i], aV[i+1] );
45  }
46 }
SHAPE_LINE_CHAIN_BASE(SHAPE_TYPE aType)
Definition: shape.h:245
void Append(int aX, int aY, bool aAllowDuplication=false)
Function Append()
bool m_closed
is the line chain closed?
int m_width
Width of the segments (for BBox calculations in RTree) TODO Adjust usage of SHAPE_LINE_CHAIN to accou...
line segment
Definition: shape.h:44

References Append().

◆ SHAPE_LINE_CHAIN() [4/7]

SHAPE_LINE_CHAIN::SHAPE_LINE_CHAIN ( const std::vector< wxPoint > &  aV,
bool  aClosed = false 
)
inline

Definition at line 121 of file shape_line_chain.h.

122  : SHAPE_LINE_CHAIN_BASE( SH_LINE_CHAIN ), m_closed( aClosed ), m_width( 0 )
123  {
124  m_points.reserve( aV.size() );
125 
126  for( auto pt : aV )
127  m_points.emplace_back( pt.x, pt.y );
128 
129  m_shapes = std::vector<ssize_t>( aV.size(), ssize_t( SHAPE_IS_PT ) );
130  }
SHAPE_LINE_CHAIN_BASE(SHAPE_TYPE aType)
Definition: shape.h:245
bool m_closed
is the line chain closed?
std::vector< VECTOR2I > m_points
array of vertices
std::vector< ssize_t > m_shapes
Array of indices that refer to the index of the shape if the point is part of a larger shape,...
static constexpr ssize_t SHAPE_IS_PT
int m_width
Width of the segments (for BBox calculations in RTree) TODO Adjust usage of SHAPE_LINE_CHAIN to accou...
line segment
Definition: shape.h:44

References m_points, m_shapes, and SHAPE_IS_PT.

◆ SHAPE_LINE_CHAIN() [5/7]

SHAPE_LINE_CHAIN::SHAPE_LINE_CHAIN ( const std::vector< VECTOR2I > &  aV,
bool  aClosed = false 
)
inline

Definition at line 132 of file shape_line_chain.h.

133  : SHAPE_LINE_CHAIN_BASE( SH_LINE_CHAIN ), m_closed( aClosed ), m_width( 0 )
134  {
135  m_points = aV;
136  m_shapes = std::vector<ssize_t>( aV.size(), ssize_t( SHAPE_IS_PT ) );
137  }
SHAPE_LINE_CHAIN_BASE(SHAPE_TYPE aType)
Definition: shape.h:245
bool m_closed
is the line chain closed?
std::vector< VECTOR2I > m_points
array of vertices
std::vector< ssize_t > m_shapes
Array of indices that refer to the index of the shape if the point is part of a larger shape,...
static constexpr ssize_t SHAPE_IS_PT
int m_width
Width of the segments (for BBox calculations in RTree) TODO Adjust usage of SHAPE_LINE_CHAIN to accou...
line segment
Definition: shape.h:44

References m_points, m_shapes, and SHAPE_IS_PT.

◆ SHAPE_LINE_CHAIN() [6/7]

SHAPE_LINE_CHAIN::SHAPE_LINE_CHAIN ( const SHAPE_ARC aArc,
bool  aClosed = false 
)
inline

Definition at line 139 of file shape_line_chain.h.

141  m_closed( aClosed ),
142  m_width( 0 )
143  {
145  m_arcs.emplace_back( aArc );
146  m_shapes = std::vector<ssize_t>( m_points.size(), 0 );
147  }
SHAPE_LINE_CHAIN_BASE(SHAPE_TYPE aType)
Definition: shape.h:245
std::vector< SHAPE_ARC > m_arcs
bool m_closed
is the line chain closed?
const std::vector< VECTOR2I > & CPoints() const
std::vector< VECTOR2I > m_points
array of vertices
std::vector< ssize_t > m_shapes
Array of indices that refer to the index of the shape if the point is part of a larger shape,...
int m_width
Width of the segments (for BBox calculations in RTree) TODO Adjust usage of SHAPE_LINE_CHAIN to accou...
line segment
Definition: shape.h:44
const SHAPE_LINE_CHAIN ConvertToPolyline(double aAccuracy=500.0) const
Constructs a SHAPE_LINE_CHAIN of segments from a given arc.
Definition: shape_arc.cpp:231

References SHAPE_ARC::ConvertToPolyline(), CPoints(), m_arcs, m_points, and m_shapes.

◆ SHAPE_LINE_CHAIN() [7/7]

SHAPE_LINE_CHAIN::SHAPE_LINE_CHAIN ( const ClipperLib::Path &  aPath)
inline

Definition at line 149 of file shape_line_chain.h.

149  :
151  m_closed( true ),
152  m_width( 0 )
153  {
154  m_points.reserve( aPath.size() );
155  m_shapes = std::vector<ssize_t>( aPath.size(), ssize_t( SHAPE_IS_PT ) );
156 
157  for( const auto& point : aPath )
158  m_points.emplace_back( point.X, point.Y );
159  }
SHAPE_LINE_CHAIN_BASE(SHAPE_TYPE aType)
Definition: shape.h:245
bool m_closed
is the line chain closed?
std::vector< VECTOR2I > m_points
array of vertices
std::vector< ssize_t > m_shapes
Array of indices that refer to the index of the shape if the point is part of a larger shape,...
static constexpr ssize_t SHAPE_IS_PT
int m_width
Width of the segments (for BBox calculations in RTree) TODO Adjust usage of SHAPE_LINE_CHAIN to accou...
line segment
Definition: shape.h:44

References m_points, m_shapes, and SHAPE_IS_PT.

◆ ~SHAPE_LINE_CHAIN()

virtual SHAPE_LINE_CHAIN::~SHAPE_LINE_CHAIN ( )
inlinevirtual

Definition at line 161 of file shape_line_chain.h.

162  {}

Member Function Documentation

◆ Append() [1/4]

void SHAPE_LINE_CHAIN::Append ( int  aX,
int  aY,
bool  aAllowDuplication = false 
)
inline

Function Append()

Appends a new point at the end of the line chain.

Parameters
aXis X coordinate of the new point
aYis Y coordinate of the new point
aAllowDuplication= true to append the new point even it is the same as the last entered point false (default) to skip it if it is the same as the last entered point

Definition at line 410 of file shape_line_chain.h.

411  {
412  VECTOR2I v( aX, aY );
413  Append( v, aAllowDuplication );
414  }
VECTOR2 defines a general 2D-vector/point.
Definition: vector2d.h:61
void Append(int aX, int aY, bool aAllowDuplication=false)
Function Append()

Referenced by PNS_PCBNEW_DEBUG_DECORATOR::AddBox(), ZONE_FILLER::addHatchFillTypeOnZone(), POLYGON_GEOM_MANAGER::AddPoint(), PNS_PCBNEW_DEBUG_DECORATOR::AddPoint(), ZONE_CONTAINER::AddPolygon(), PNS_PCBNEW_DEBUG_DECORATOR::AddSegment(), PNS::POSTURE_SOLVER::AddTrailPoint(), SHAPE_SIMPLE::Append(), PNS::DIFF_PAIR::Append(), PNS::ArcHull(), PNS::NODE::AssembleLine(), D_PAD::BuildEffectiveShapes(), PNS::DIFF_PAIR::BuildInitial(), DIRECTION_45::BuildInitialTrace(), ZONE_FILLER::buildThermalSpokes(), SHAPE_POLY_SET::chamferFilletPolygon(), PNS::KEEP_TOPOLOGY_CONSTRAINT::Check(), PNS::OPTIMIZER::circleBreakouts(), PNS::clipToLoopStart(), KI_TEST::CommonTestData::CommonTestData(), GRID_HELPER::computeAnchors(), SCH_SHEET_PIN::ConstrainOnEdge(), SHAPE_ARC::ConvertToPolyline(), PNS::ConvexHull(), PLACEFILE_GERBER_WRITER::CreatePlaceFile(), PNS::OPTIMIZER::customBreakouts(), PNS::MEANDER_PLACER::doMove(), PNS::LINE::dragCorner45(), PNS::dragCornerInternal(), PNS::LINE::dragSegment45(), PNS::MEANDER_SHAPE::forward(), SHAPE_POLY_SET::fractureSingle(), PNS::MEANDER_SHAPE::genMeanderShape(), CADSTAR_PCB_ARCHIVE_LOADER::getLineChainFromDrawsegments(), PNS::POSTURE_SOLVER::GetPosture(), LIB_POLYLINE::HitTest(), IteratorFixture::IteratorFixture(), PNS::TOPOLOGY::LeadingRatLine(), PNS::MEANDER_SHAPE::MakeCorner(), PNS::MEANDER_SHAPE::makeMiterShape(), CONVERT_TOOL::makePolysFromRects(), CONVERT_TOOL::makePolysFromSegs(), GEOM_TEST::MakeSquarePolyLine(), PNS::LINE_PLACER::mergeHead(), PNS::OPTIMIZER::mergeObtuse(), PNS::MEANDER_SHAPE::miter(), PNS::DP_MEANDER_PLACER::Move(), PNS::OctagonalHull(), ZONE_CREATE_HELPER::OnComplete(), PNS::LINE_PLACER::optimizeTailHeadTransition(), SHAPE_RECT::Outline(), SHAPE_POLY_SET::Parse(), ALTIUM_PCB::ParseRegions6Data(), partitionPolyIntoRegularCellGrid(), BRDITEMS_PLOTTER::PlotDrawSegment(), BRDITEMS_PLOTTER::PlotFootprintGraphicItem(), CONVERT_TOOL::PolyToLines(), PNS::LINE_PLACER::rhShoveOnly(), PNS::LINE_PLACER::rhStopAtNearestObstacle(), PNS::WALKAROUND::Route(), PNS::SegmentHull(), SHAPE_LINE_CHAIN(), MARKER_BASE::ShapeToPolygon(), PNS::WALKAROUND::singleStep(), Slice(), PNS::OPTIMIZER::smartPadsSingle(), PNS::MEANDER_SHAPE::start(), TestConcaveSquareFillet(), PNS::tightenSegment(), PNS::LINE_PLACER::Trace(), TransformCircleToPolygon(), unfracture(), SHAPE_POLY_SET::unfractureSingle(), POLYGON_GEOM_MANAGER::updateLeaderPoints(), and PNS::LINE::Walkaround().

◆ Append() [2/4]

void SHAPE_LINE_CHAIN::Append ( const VECTOR2I aP,
bool  aAllowDuplication = false 
)
inline

Function Append()

Appends a new point at the end of the line chain.

Parameters
aPthe new point
aAllowDuplication= true to append the new point even it is the same as the last entered point false (default) to skip it if it is the same as the last entered point

Definition at line 425 of file shape_line_chain.h.

426  {
427  if( m_points.size() == 0 )
428  m_bbox = BOX2I( aP, VECTOR2I( 0, 0 ) );
429 
430  if( m_points.size() == 0 || aAllowDuplication || CPoint( -1 ) != aP )
431  {
432  m_points.push_back( aP );
433  m_shapes.push_back( ssize_t( SHAPE_IS_PT ) );
434  m_bbox.Merge( aP );
435  }
436  }
BOX2I m_bbox
cached bounding box
BOX2< VECTOR2I > BOX2I
Definition: box2.h:522
VECTOR2< int > VECTOR2I
Definition: vector2d.h:594
const VECTOR2I & CPoint(int aIndex) const
Function Point()
std::vector< VECTOR2I > m_points
array of vertices
BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Function Merge modifies the position and size of the rectangle in order to contain aRect.
Definition: box2.h:386
std::vector< ssize_t > m_shapes
Array of indices that refer to the index of the shape if the point is part of a larger shape,...
static constexpr ssize_t SHAPE_IS_PT

References CPoint(), m_bbox, m_points, m_shapes, BOX2< Vec >::Merge(), and SHAPE_IS_PT.

◆ Append() [3/4]

void SHAPE_LINE_CHAIN::Append ( const SHAPE_LINE_CHAIN aOtherLine)

Function Append()

Appends another line chain at the end.

Parameters
aOtherLinethe line chain to be appended.

Definition at line 387 of file shape_line_chain.cpp.

388 {
389  assert( m_shapes.size() == m_points.size() );
390 
391  if( aOtherLine.PointCount() == 0 )
392  return;
393 
394  else if( PointCount() == 0 || aOtherLine.CPoint( 0 ) != CPoint( -1 ) )
395  {
396  const VECTOR2I p = aOtherLine.CPoint( 0 );
397  m_points.push_back( p );
398  m_shapes.push_back( ssize_t( SHAPE_IS_PT ) );
399  m_bbox.Merge( p );
400  }
401 
402  size_t num_arcs = m_arcs.size();
403  m_arcs.insert( m_arcs.end(), aOtherLine.m_arcs.begin(), aOtherLine.m_arcs.end() );
404 
405  for( int i = 1; i < aOtherLine.PointCount(); i++ )
406  {
407  const VECTOR2I p = aOtherLine.CPoint( i );
408  m_points.push_back( p );
409 
410  ssize_t arcIndex = aOtherLine.ArcIndex( i );
411 
412  if( arcIndex != ssize_t( SHAPE_IS_PT ) )
413  m_shapes.push_back( num_arcs + arcIndex );
414  else
415  m_shapes.push_back( ssize_t( SHAPE_IS_PT ) );
416 
417  m_bbox.Merge( p );
418  }
419 
420  assert( m_shapes.size() == m_points.size() );
421 }
BOX2I m_bbox
cached bounding box
VECTOR2 defines a general 2D-vector/point.
Definition: vector2d.h:61
int PointCount() const
Function PointCount()
std::vector< SHAPE_ARC > m_arcs
ssize_t ArcIndex(size_t aSegment) const
const VECTOR2I & CPoint(int aIndex) const
Function Point()
std::vector< VECTOR2I > m_points
array of vertices
BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Function Merge modifies the position and size of the rectangle in order to contain aRect.
Definition: box2.h:386
std::vector< ssize_t > m_shapes
Array of indices that refer to the index of the shape if the point is part of a larger shape,...
static constexpr ssize_t SHAPE_IS_PT

References ArcIndex(), CPoint(), m_arcs, m_bbox, m_points, m_shapes, BOX2< Vec >::Merge(), PointCount(), and SHAPE_IS_PT.

◆ Append() [4/4]

void SHAPE_LINE_CHAIN::Append ( const SHAPE_ARC aArc)

Definition at line 424 of file shape_line_chain.cpp.

425 {
426  auto& chain = aArc.ConvertToPolyline();
427 
428  for( auto& pt : chain.CPoints() )
429  {
430  m_points.push_back( pt );
431  m_shapes.push_back( m_arcs.size() );
432  }
433 
434  m_arcs.push_back( aArc );
435 
436  assert( m_shapes.size() == m_points.size() );
437 }
std::vector< SHAPE_ARC > m_arcs
std::vector< VECTOR2I > m_points
array of vertices
std::vector< ssize_t > m_shapes
Array of indices that refer to the index of the shape if the point is part of a larger shape,...
const SHAPE_LINE_CHAIN ConvertToPolyline(double aAccuracy=500.0) const
Constructs a SHAPE_LINE_CHAIN of segments from a given arc.
Definition: shape_arc.cpp:231

References SHAPE_ARC::ConvertToPolyline(), m_arcs, m_points, and m_shapes.

◆ Arc()

const SHAPE_ARC& SHAPE_LINE_CHAIN::Arc ( size_t  aArc) const
inline

Definition at line 712 of file shape_line_chain.h.

713  {
714  return m_arcs[aArc];
715  }
std::vector< SHAPE_ARC > m_arcs

References m_arcs.

Referenced by PNS::NODE::Add(), and PNS::LINE_PLACER::FixRoute().

◆ ArcCount()

size_t SHAPE_LINE_CHAIN::ArcCount ( ) const
inline

Definition at line 699 of file shape_line_chain.h.

700  {
701  return m_arcs.size();
702  }
std::vector< SHAPE_ARC > m_arcs

References m_arcs.

Referenced by PNS::LINE::ArcCount(), and ROUTER_PREVIEW_ITEM::drawLineChain().

◆ ArcIndex()

ssize_t SHAPE_LINE_CHAIN::ArcIndex ( size_t  aSegment) const
inline

Definition at line 704 of file shape_line_chain.h.

705  {
706  if( aSegment >= m_shapes.size() )
707  return SHAPE_IS_PT;
708 
709  return m_shapes[aSegment];
710  }
std::vector< ssize_t > m_shapes
Array of indices that refer to the index of the shape if the point is part of a larger shape,...
static constexpr ssize_t SHAPE_IS_PT

References m_shapes, and SHAPE_IS_PT.

Referenced by Append(), and PNS::LINE_PLACER::FixRoute().

◆ Area()

double SHAPE_LINE_CHAIN::Area ( ) const

Definition at line 1022 of file shape_line_chain.cpp.

1023 {
1024  // see https://www.mathopenref.com/coordpolygonarea2.html
1025 
1026  if( !m_closed )
1027  return 0.0;
1028 
1029  double area = 0.0;
1030  int size = m_points.size();
1031 
1032  for( int i = 0, j = size - 1; i < size; ++i )
1033  {
1034  area += ( (double) m_points[j].x + m_points[i].x ) * ( (double) m_points[j].y - m_points[i].y );
1035  j = i;
1036  }
1037 
1038  return -area * 0.5;
1039 }
bool m_closed
is the line chain closed?
std::vector< VECTOR2I > m_points
array of vertices

References m_closed, and m_points.

Referenced by ZONE_FILLER::addHatchFillTypeOnZone(), ZONE_CONTAINER::CalculateFilledArea(), ZONE_FILLER::Fill(), DIALOG_BOARD_STATISTICS::getDataFromPCB(), PNS::POSTURE_SOLVER::GetPosture(), PlotSolderMaskLayer(), polygonArea(), unfracture(), and SHAPE_POLY_SET::unfractureSingle().

◆ BBox()

const BOX2I SHAPE_LINE_CHAIN::BBox ( int  aClearance = 0) const
inlineoverridevirtual

Function BBox()

Computes a bounding box of the shape, with a margin of aClearance a collision.

Parameters
aClearancehow much the bounding box is expanded wrs to the minimum enclosing rectangle for the shape.
Returns
the bounding box.

Implements SHAPE.

Definition at line 351 of file shape_line_chain.h.

352  {
353  BOX2I bbox;
354  bbox.Compute( m_points );
355 
356  if( aClearance != 0 || m_width != 0 )
357  bbox.Inflate( aClearance + m_width );
358 
359  return bbox;
360  }
void Compute(const Container &aPointList)
Compute the bounding box from a given list of points.
Definition: box2.h:91
std::vector< VECTOR2I > m_points
array of vertices
BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Function Inflate inflates the rectangle horizontally by dx and vertically by dy.
Definition: box2.h:302
int m_width
Width of the segments (for BBox calculations in RTree) TODO Adjust usage of SHAPE_LINE_CHAIN to accou...

References BOX2< Vec >::Compute(), BOX2< Vec >::Inflate(), m_points, and m_width.

Referenced by SHAPE_SIMPLE::BBox(), POLY_GRID_PARTITION::build(), PNS::KEEP_TOPOLOGY_CONSTRAINT::Check(), AR_AUTOPLACER::fillMatrix(), DIALOG_BOARD_STATISTICS::getDataFromPCB(), Intersect(), and PolygonTriangulation::TesselatePolygon().

◆ BBoxFromCache()

const BOX2I SHAPE_LINE_CHAIN::BBoxFromCache ( ) const
inline

Definition at line 370 of file shape_line_chain.h.

371  {
372  return m_bbox;
373  }
BOX2I m_bbox
cached bounding box

References m_bbox.

◆ CalcShape()

SGNODE * SHAPE::CalcShape ( SGNODE aParent,
SGNODE aColor,
WRL1_ORDER  aVertexOrder,
float  aCreaseLimit = 0.74317,
bool  isVRML2 = false 
)
inherited

Definition at line 713 of file wrlfacet.cpp.

715 {
716  if( facets.empty() || !facets.front()->HasMinPoints() )
717  return NULL;
718 
719  std::vector< std::list< FACET* > > flist;
720 
721  // determine the max. index and size flist as appropriate
722  std::list< FACET* >::iterator sF = facets.begin();
723  std::list< FACET* >::iterator eF = facets.end();
724 
725  int maxIdx = 0;
726  int tmi;
727  float maxV = 0.0;
728  float tV = 0.0;
729 
730  while( sF != eF )
731  {
732  tV = (*sF)->CalcFaceNormal();
733  tmi = (*sF)->GetMaxIndex();
734 
735  if( tmi > maxIdx )
736  maxIdx = tmi;
737 
738  if( tV > maxV )
739  maxV = tV;
740 
741  ++sF;
742  }
743 
744  ++maxIdx;
745 
746  if( maxIdx < 3 )
747  return NULL;
748 
749  flist.resize( maxIdx );
750 
751  // create the lists of facets common to indices
752  sF = facets.begin();
753 
754  while( sF != eF )
755  {
756  (*sF)->Renormalize( tV );
757  (*sF)->CollectVertices( flist );
758  ++sF;
759  }
760 
761  // calculate the normals
762  size_t vs = flist.size();
763 
764  for( size_t i = 0; i < vs; ++i )
765  {
766  sF = flist[i].begin();
767  eF = flist[i].end();
768 
769  while( sF != eF )
770  {
771  (*sF)->CalcVertexNormal( i, flist[i], aCreaseLimit );
772  ++sF;
773  }
774  }
775 
776  std::vector< WRLVEC3F > vertices;
777  std::vector< WRLVEC3F > normals;
778  std::vector< SGCOLOR > colors;
779 
780  // push the facet data to the final output list
781  sF = facets.begin();
782  eF = facets.end();
783 
784  while( sF != eF )
785  {
786  (*sF)->GetData( vertices, normals, colors, aVertexOrder );
787  ++sF;
788  }
789 
790  flist.clear();
791 
792  if( vertices.size() < 3 )
793  return NULL;
794 
795  IFSG_SHAPE shapeNode( false );
796 
797  if( !isVRML2 )
798  {
799  shapeNode.NewNode( aParent );
800 
801  if( aColor )
802  {
803  if( NULL == S3D::GetSGNodeParent( aColor ) )
804  shapeNode.AddChildNode( aColor );
805  else
806  shapeNode.AddRefNode( aColor );
807  }
808  }
809 
810  std::vector< SGPOINT > lCPts; // vertex points in SGPOINT (double) format
811  std::vector< SGVECTOR > lCNorm; // per-vertex normals
812  vs = vertices.size();
813 
814  for( size_t i = 0; i < vs; ++i )
815  {
816  SGPOINT pt;
817  pt.x = vertices[i].x;
818  pt.y = vertices[i].y;
819  pt.z = vertices[i].z;
820  lCPts.push_back( pt );
821  lCNorm.emplace_back( normals[i].x, normals[i].y, normals[i].z );
822  }
823 
824  vertices.clear();
825  normals.clear();
826 
827  IFSG_FACESET fsNode( false );
828 
829  if( !isVRML2 )
830  fsNode.NewNode( shapeNode );
831  else
832  fsNode.NewNode( aParent );
833 
834  IFSG_COORDS cpNode( fsNode );
835  cpNode.SetCoordsList( lCPts.size(), &lCPts[0] );
836  IFSG_COORDINDEX ciNode( fsNode );
837 
838  for( int i = 0; i < (int)lCPts.size(); ++i )
839  ciNode.AddIndex( i );
840 
841  IFSG_NORMALS nmNode( fsNode );
842  nmNode.SetNormalList( lCNorm.size(), &lCNorm[0] );
843 
844  if( !colors.empty() )
845  {
846  IFSG_COLORS nmColor( fsNode );
847  nmColor.SetColorList( colors.size(), &colors[0] );
848  colors.clear();
849  }
850 
851  if( !isVRML2 )
852  return shapeNode.GetRawPtr();
853 
854  return fsNode.GetRawPtr();
855 }
double x
Definition: sg_base.h:70
IFSG_COORDS is the wrapper for SGCOORDS.
Definition: ifsg_coords.h:40
IFSG_COORDINDEX is the wrapper for SGCOORDINDEX.
IFSG_COLORS is the wrapper for SGCOLORS.
Definition: ifsg_colors.h:41
SGLIB_API SGNODE * GetSGNodeParent(SGNODE *aNode)
Definition: ifsg_api.cpp:636
double y
Definition: sg_base.h:71
IFSG_NORMALS is the wrapper for the SGNORMALS class.
Definition: ifsg_normals.h:40
#define NULL
std::list< FACET * > facets
Definition: wrlfacet.h:143
IFSG_FACESET is the wrapper for the SGFACESET class.
Definition: ifsg_faceset.h:40
double z
Definition: sg_base.h:72
static VRML_COLOR colors[VRML_COLOR_LAST]
IFSG_SHAPE is the wrapper for the SGSHAPE class.
Definition: ifsg_shape.h:40

References IFSG_NODE::AddChildNode(), IFSG_INDEX::AddIndex(), IFSG_NODE::AddRefNode(), colors, SHAPE::facets, IFSG_NODE::GetRawPtr(), S3D::GetSGNodeParent(), IFSG_FACESET::NewNode(), IFSG_SHAPE::NewNode(), NULL, IFSG_COLORS::SetColorList(), IFSG_COORDS::SetCoordsList(), IFSG_NORMALS::SetNormalList(), SGPOINT::x, SGPOINT::y, and SGPOINT::z.

Referenced by WRL1FACESET::TranslateToSG(), X3DIFACESET::TranslateToSG(), and WRL2FACESET::TranslateToSG().

◆ CArcs()

const std::vector<SHAPE_ARC>& SHAPE_LINE_CHAIN::CArcs ( ) const
inline
Returns
the vector of stored arcs

Definition at line 337 of file shape_line_chain.h.

338  {
339  return m_arcs;
340  }
std::vector< SHAPE_ARC > m_arcs

References m_arcs.

Referenced by ROUTER_PREVIEW_ITEM::drawLineChain().

◆ Centre()

virtual VECTOR2I SHAPE::Centre ( ) const
inlinevirtualinherited

Function Centre()

Computes a center-of-mass of the shape

Returns
the center-of-mass point

Definition at line 220 of file shape.h.

221  {
222  return BBox( 0 ).Centre(); // if nothing better is available....
223  }
virtual const BOX2I BBox(int aClearance=0) const =0
Function BBox()
Vec Centre() const
Definition: box2.h:79

References SHAPE::BBox(), and BOX2< Vec >::Centre().

Referenced by PNS_PCBNEW_RULE_RESOLVER::CollideHoles().

◆ CheckClearance()

bool SHAPE_LINE_CHAIN::CheckClearance ( const VECTOR2I aP,
const int  aDist 
) const

Function CheckClearance()

Checks if point aP is closer to (or on) an edge or vertex of the line chain.

Parameters
aPpoint to check
aDistdistance in internal units
Returns
true if the point is equal to or closer than aDist to the line chain.

Definition at line 690 of file shape_line_chain.cpp.

691 {
692  if( !PointCount() )
693  return false;
694 
695  else if( PointCount() == 1 )
696  return m_points[0] == aP;
697 
698  for( int i = 0; i < SegmentCount(); i++ )
699  {
700  const SEG s = CSegment( i );
701 
702  if( s.A == aP || s.B == aP )
703  return true;
704 
705  if( s.Distance( aP ) <= aDist )
706  return true;
707  }
708 
709  return false;
710 }
int Distance(const SEG &aSeg) const
Function Distance()
Definition: seg.h:207
int PointCount() const
Function PointCount()
std::vector< VECTOR2I > m_points
array of vertices
int SegmentCount() const
Function SegmentCount()
Definition: seg.h:39
const SEG CSegment(int aIndex) const
Function CSegment()
VECTOR2I A
Definition: seg.h:47
VECTOR2I B
Definition: seg.h:48

References SEG::A, SEG::B, CSegment(), SEG::Distance(), m_points, PointCount(), and SegmentCount().

◆ CLastPoint()

const VECTOR2I& SHAPE_LINE_CHAIN::CLastPoint ( ) const
inline

Returns the last point in the line chain.

Definition at line 329 of file shape_line_chain.h.

330  {
331  return m_points[PointCount() - 1];
332  }
int PointCount() const
Function PointCount()
std::vector< VECTOR2I > m_points
array of vertices

References m_points, and PointCount().

Referenced by POLYGON_GEOM_MANAGER::DeleteLastCorner(), and POLYGON_GEOM_MANAGER::updateLeaderPoints().

◆ Clear()

void SHAPE_LINE_CHAIN::Clear ( )
inline

Function Clear() Removes all points from the line chain.

Definition at line 172 of file shape_line_chain.h.

173  {
174  m_points.clear();
175  m_arcs.clear();
176  m_shapes.clear();
177  m_closed = false;
178  }
std::vector< SHAPE_ARC > m_arcs
bool m_closed
is the line chain closed?
std::vector< VECTOR2I > m_points
array of vertices
std::vector< ssize_t > m_shapes
Array of indices that refer to the index of the shape if the point is part of a larger shape,...

References m_arcs, m_closed, m_points, and m_shapes.

Referenced by PNS_PCBNEW_DEBUG_DECORATOR::AddPoint(), PNS::LINE_PLACER::buildInitialLine(), SHAPE_SIMPLE::Clear(), PNS::POSTURE_SOLVER::Clear(), PNS::LINE::Clear(), PNS::DIFF_PAIR::Clear(), PNS::LINE::ClipToNearestObstacle(), KI_TEST::CommonTestData::CommonTestData(), PNS::MEANDER_PLACER::doMove(), PNS::LINE_PLACER::FixRoute(), PNS::POSTURE_SOLVER::GetPosture(), PNS::LINE_PLACER::handlePullback(), PNS::LINE_PLACER::handleSelfIntersections(), PNS::LINE_PLACER::initPlacement(), IteratorFixture::IteratorFixture(), PNS::TOPOLOGY::LeadingRatLine(), PNS::MEANDER_SHAPE::MakeCorner(), PNS::DP_MEANDER_PLACER::Move(), PNS::SHOVE::onReverseCollidingVia(), PNS::LINE_PLACER::optimizeTailHeadTransition(), PNS::LINE_PLACER::reduceTail(), POLYGON_GEOM_MANAGER::Reset(), PNS::LINE_PLACER::SetLayer(), PNS::MEANDER_SHAPE::start(), PNS::tightenSegment(), PNS::LINE_PLACER::UnfixRoute(), and PNS::LINE::Walkaround().

◆ Clone()

SHAPE * SHAPE_LINE_CHAIN::Clone ( ) const
overridevirtual

Function Clone()

Returns a dynamically allocated copy of the shape

Return values
copyof the shape

Reimplemented from SHAPE.

Definition at line 945 of file shape_line_chain.cpp.

946 {
947  return new SHAPE_LINE_CHAIN( *this );
948 }
SHAPE_LINE_CHAIN()
Constructor Initializes an empty line chain.

References SHAPE_LINE_CHAIN().

Referenced by ROUTER_PREVIEW_ITEM::Line().

◆ Collide() [1/4]

bool SHAPE::Collide ( const SHAPE aShape,
int  aClearance,
VECTOR2I aMTV 
) const
virtualinherited

Function Collide()

Checks if the boundary of shape (this) lies closer to the shape aShape than aClearance, indicating a collision.

Parameters
aShapeshape to check collision against
aClearanceminimum clearance
aMTVminimum translation vector
aActualan optional pointer to an int to store the actual distance in the event of a collision.
Returns
true, if there is a collision.

Reimplemented in SHAPE_RECT, SHAPE_SEGMENT, and SHAPE_COMPOUND.

Definition at line 719 of file shape_collisions.cpp.

720 {
721  return collideShapes( this, aShape, aClearance, nullptr, aMTV );
722 }
static bool collideShapes(const SHAPE *aA, const SHAPE *aB, int aClearance, int *aActual, VECTOR2I *aMTV)

References collideShapes().

◆ Collide() [2/4]

bool SHAPE::Collide ( const SHAPE aShape,
int  aClearance = 0,
int *  aActual = nullptr 
) const
virtualinherited

Reimplemented in SHAPE_RECT, SHAPE_SEGMENT, and SHAPE_COMPOUND.

Definition at line 725 of file shape_collisions.cpp.

726 {
727  return collideShapes( this, aShape, aClearance, aActual, nullptr );
728 }
static bool collideShapes(const SHAPE *aA, const SHAPE *aB, int aClearance, int *aActual, VECTOR2I *aMTV)

References collideShapes().

◆ Collide() [3/4]

bool SHAPE_LINE_CHAIN_BASE::Collide ( const VECTOR2I aP,
int  aClearance = 0,
int *  aActual = nullptr 
) const
overridevirtualinherited

Function Collide()

Checks if point aP lies closer to us than aClearance.

Parameters
aPthe point to check for collisions with
aClearanceminimum distance that does not qualify as a collision.
aActualan optional pointer to an int to store the actual distance in the event of a collision.
Returns
true, when a collision has been found

Reimplemented from SHAPE.

Definition at line 88 of file shape_line_chain.cpp.

89 {
91  SEG::ecoord clearance_sq = SEG::Square( aClearance );
92 
93  // fixme: why this only checks open curves?
94 
95  for( int i = 0; i < GetSegmentCount(); i++ )
96  {
97  const SEG& s = GetSegment( i );
98  dist_sq = std::min( dist_sq, s.SquaredDistance( aP ) );
99 
100  if( ( dist_sq == 0 || dist_sq < clearance_sq ) && !aActual )
101  return true;
102  }
103 
104  if( dist_sq == 0 || dist_sq < clearance_sq )
105  {
106  if( aActual )
107  *aActual = sqrt( dist_sq );
108 
109  return true;
110  }
111 
112  return false;
113 }
VECTOR2I::extended_type ecoord
Definition: seg.h:42
ecoord SquaredDistance(const SEG &aSeg) const
Definition: seg.cpp:37
virtual size_t GetSegmentCount() const =0
static SEG::ecoord Square(int a)
Definition: seg.h:116
static constexpr extended_type ECOORD_MAX
Definition: vector2d.h:80
Definition: seg.h:39
virtual const SEG GetSegment(int aIndex) const =0

References VECTOR2< T >::ECOORD_MAX, SHAPE_LINE_CHAIN_BASE::GetSegment(), SHAPE_LINE_CHAIN_BASE::GetSegmentCount(), SEG::Square(), and SEG::SquaredDistance().

Referenced by PNS::MEANDERED_LINE::CheckSelfIntersections(), SHAPE_SIMPLE::Collide(), and Collide().

◆ Collide() [4/4]

bool SHAPE_LINE_CHAIN_BASE::Collide ( const SEG aSeg,
int  aClearance = 0,
int *  aActual = nullptr 
) const
overridevirtualinherited

Function Collide()

Checks if segment aSeg lies closer to us than aClearance.

Parameters
aSegthe segment to check for collisions with
aClearanceminimum distance that does not qualify as a collision.
aActualan optional pointer to an int to store the actual distance in the event of a collision.
Returns
true, when a collision has been found

Implements SHAPE.

Reimplemented in SHAPE_SIMPLE.

Definition at line 130 of file shape_line_chain.cpp.

131 {
133  SEG::ecoord clearance_sq = SEG::Square( aClearance );
134 
135  for( int i = 0; i < GetSegmentCount(); i++ )
136  {
137  const SEG& s = GetSegment( i );
138  dist_sq = std::min( dist_sq, s.SquaredDistance( aSeg ) );
139 
140  if( ( dist_sq == 0 || dist_sq < clearance_sq ) && !aActual )
141  return true;
142  }
143 
144  if( dist_sq == 0 || dist_sq < clearance_sq )
145  {
146  if( aActual )
147  *aActual = sqrt( dist_sq );
148 
149  return true;
150  }
151 
152  return false;
153 }
VECTOR2I::extended_type ecoord
Definition: seg.h:42
ecoord SquaredDistance(const SEG &aSeg) const
Definition: seg.cpp:37
virtual size_t GetSegmentCount() const =0
static SEG::ecoord Square(int a)
Definition: seg.h:116
static constexpr extended_type ECOORD_MAX
Definition: vector2d.h:80
Definition: seg.h:39
virtual const SEG GetSegment(int aIndex) const =0

References VECTOR2< T >::ECOORD_MAX, SHAPE_LINE_CHAIN_BASE::GetSegment(), SHAPE_LINE_CHAIN_BASE::GetSegmentCount(), SEG::Square(), and SEG::SquaredDistance().

◆ CompareGeometry()

bool SHAPE_LINE_CHAIN::CompareGeometry ( const SHAPE_LINE_CHAIN aOther) const

Definition at line 922 of file shape_line_chain.cpp.

923 {
924  SHAPE_LINE_CHAIN a(*this), b( aOther );
925  a.Simplify();
926  b.Simplify();
927 
928  if( a.m_points.size() != b.m_points.size() )
929  return false;
930 
931  for( int i = 0; i < a.PointCount(); i++)
932  if( a.CPoint( i ) != b.CPoint( i ) )
933  return false;
934  return true;
935 }
SHAPE_LINE_CHAIN.

References CPoint(), m_points, and Simplify().

Referenced by PNS::LINE::CompareGeometry(), and PNS::SHOVE::processHullSet().

◆ convertArc()

void SHAPE_LINE_CHAIN::convertArc ( ssize_t  aArcIndex)

Converts an arc to only a point chain by removing the arc and references.

Parameters
aArcIndexindex of the arc to convert to points

Definition at line 66 of file shape_line_chain.cpp.

67 {
68  if( aArcIndex < 0 )
69  aArcIndex += m_arcs.size();
70 
71  if( aArcIndex >= static_cast<ssize_t>( m_arcs.size() ) )
72  return;
73 
74  // Clear the shapes references
75  for( auto& sh : m_shapes )
76  {
77  if( sh == aArcIndex )
78  sh = SHAPE_IS_PT;
79 
80  if( sh > aArcIndex )
81  --sh;
82  }
83 
84  m_arcs.erase( m_arcs.begin() + aArcIndex );
85 }
std::vector< SHAPE_ARC > m_arcs
std::vector< ssize_t > m_shapes
Array of indices that refer to the index of the shape if the point is part of a larger shape,...
static constexpr ssize_t SHAPE_IS_PT

References m_arcs, m_shapes, and SHAPE_IS_PT.

Referenced by Insert(), Remove(), Replace(), and SetPoint().

◆ convertToClipper()

ClipperLib::Path SHAPE_LINE_CHAIN::convertToClipper ( bool  aRequiredOrientation) const

Creates a new Clipper path from the SHAPE_LINE_CHAIN in a given orientation.

Definition at line 48 of file shape_line_chain.cpp.

49 {
50  ClipperLib::Path c_path;
51 
52  for( int i = 0; i < PointCount(); i++ )
53  {
54  const VECTOR2I& vertex = CPoint( i );
55  c_path.push_back( ClipperLib::IntPoint( vertex.x, vertex.y ) );
56  }
57 
58  if( Orientation( c_path ) != aRequiredOrientation )
59  ReversePath( c_path );
60 
61  return c_path;
62 }
VECTOR2 defines a general 2D-vector/point.
Definition: vector2d.h:61
int PointCount() const
Function PointCount()
const VECTOR2I & CPoint(int aIndex) const
Function Point()

References CPoint(), PointCount(), VECTOR2< T >::x, and VECTOR2< T >::y.

◆ CPoint()

const VECTOR2I& SHAPE_LINE_CHAIN::CPoint ( int  aIndex) const
inline

Function Point()

Returns a const reference to a given point in the line chain.

Parameters
aIndexindex of the point
Returns
const reference to the point

Definition at line 311 of file shape_line_chain.h.

312  {
313  if( aIndex < 0 )
314  aIndex += PointCount();
315  else if( aIndex >= PointCount() )
316  aIndex -= PointCount();
317 
318  return m_points[aIndex];
319  }
int PointCount() const
Function PointCount()
std::vector< VECTOR2I > m_points
array of vertices

References m_points, and PointCount().

Referenced by POLYGON_GEOM_MANAGER::AddPoint(), SHAPE_LINE_CHAIN::POINT_INSIDE_TRACKER::AddPolyline(), BOARD_ADAPTER::AddSolidAreasShapesToContainer(), CLAYER_TRIANGLES::AddToMiddleContourns(), PNS::POSTURE_SOLVER::AddTrailPoint(), Append(), PNS::LINE::AppendVia(), ArePolylineEndPointsNearCircle(), ArePolylineMidPointsNearCircle(), BOOST_AUTO_TEST_CASE(), BuildConvexHull(), D_PAD::BuildEffectiveShapes(), PNS::LINE_PLACER::buildInitialLine(), BOARD_ADAPTER::buildPadShapeThickOutlineAsPolygon(), BOARD_ADAPTER::buildPadShapeThickOutlineAsSegments(), SHAPE_POLY_SET::chamferFilletPolygon(), PNS::LINE::ChangedArea(), PNS::KEEP_TOPOLOGY_CONSTRAINT::Check(), CompareGeometry(), convertToClipper(), PNS::coupledBypass(), SHAPE_SIMPLE::CPoint(), PNS::LINE::CPoint(), PolygonTriangulation::createList(), CreatePadsShapesSection(), PNS::dragCornerInternal(), PNS::LINE::dragSegment45(), APERTURE_MACRO::DrawApertureMacroShape(), KIGFX::CAIRO_GAL_BASE::drawPoly(), KIGFX::OPENGL_GAL::DrawPolygon(), KIGFX::OPENGL_GAL::DrawPolyline(), export_vrml_board(), export_vrml_padshape(), export_vrml_polygon(), export_vrml_zones(), DSN::SPECCTRA_DB::fillBOUNDARY(), AR_AUTOPLACER::fillMatrix(), Find(), PNS::LINE_PLACER::FixRoute(), HPGL_PLOTTER::FlashPadCustom(), PSLIKE_PLOTTER::FlashPadCustom(), GERBER_PLOTTER::FlashPadCustom(), DXF_PLOTTER::FlashPadCustom(), HPGL_PLOTTER::FlashPadRoundRect(), PSLIKE_PLOTTER::FlashPadRoundRect(), GERBER_PLOTTER::FlashPadRoundRect(), DXF_PLOTTER::FlashPadRoundRect(), PNS::TOPOLOGY::followTrivialPath(), PCB_IO::format(), PNS::MEANDER_SHAPE::genMeanderShape(), DRAWSEGMENT::GetMsgPanelInfo(), SHAPE_SIMPLE::GetPoint(), GetPoint(), PNS::POSTURE_SOLVER::GetPosture(), PNS::LINE_PLACER::handlePullback(), PNS::LINE_PLACER::handleSelfIntersections(), WS_DRAW_ITEM_POLYPOLYGONS::HitTest(), POLYGON_GEOM_MANAGER::IsSelfIntersecting(), DSN::SPECCTRA_DB::makePADSTACK(), PNS::LINE_PLACER::mergeHead(), PNS::MEANDER_SHAPE::miter(), PNS::LINE_PLACER::Move(), NearestPoint(), POLYGON_GEOM_MANAGER::NewPointClosesOutline(), operator!=(), BOOST_TEST_PRINT_NAMESPACE_OPEN::print_log_value< SHAPE_LINE_CHAIN >::operator()(), PNS::LINE_PLACER::optimizeTailHeadTransition(), BITMAPCONV_INFO::outputOnePolygon(), BRDITEMS_PLOTTER::PlotFilledAreas(), PlotLayerOutlines(), PLOTTER::PlotPoly(), DXF_PLOTTER::PlotPoly(), PlotSolderMaskLayer(), PlotWorkSheet(), PointAlong(), PNS::pointInside2(), polygon_Convert(), GERBER_DRAW_ITEM::PrintGerberPoly(), WS_DRAW_ITEM_POLYPOLYGONS::PrintWsItem(), PNS::SHOVE::processHullSet(), PNS::LINE_PLACER::removeLoops(), PNS::DIFF_PAIR_PLACER::routeHead(), PNS::OPTIMIZER::runSmartPads(), KIGFX::PREVIEW::POLYGON_ITEM::SetPoints(), PNS::shovedArea(), Simplify(), DXF_PLOTTER::ThickSegment(), unfracture(), SHAPE_POLY_SET::unfractureSingle(), PNS::MEANDER_SHAPE::updateBaseSegment(), POLYGON_GEOM_MANAGER::updateLeaderPoints(), PNS::LINE::Walkaround(), PNS::SHOVE::walkaroundLoneVia(), HYPERLYNX_EXPORTER::writeNetObjects(), GBR_TO_PCB_EXPORTER::writePcbPolygon(), and GBR_TO_PCB_EXPORTER::writePcbZoneItem().

◆ CPoints()

const std::vector<VECTOR2I>& SHAPE_LINE_CHAIN::CPoints ( ) const
inline

◆ CSegment()

const SEG SHAPE_LINE_CHAIN::CSegment ( int  aIndex) const
inline

Function CSegment()

Returns a constant copy of the aIndex-th segment in the line chain.

Parameters
aIndexindex of the segment in the line chain. Negative values are counted from the end (i.e. -1 means the last segment in the line chain)
Returns
const SEG - aIndex-th segment in the line chain

Definition at line 273 of file shape_line_chain.h.

274  {
275  if( aIndex < 0 )
276  aIndex += SegmentCount();
277 
278  if( aIndex == (int)( m_points.size() - 1 ) && m_closed )
279  return SEG( const_cast<VECTOR2I&>( m_points[aIndex] ),
280  const_cast<VECTOR2I&>( m_points[0] ), aIndex );
281  else
282  return SEG( const_cast<VECTOR2I&>( m_points[aIndex] ),
283  const_cast<VECTOR2I&>( m_points[aIndex + 1] ), aIndex );
284  }
bool m_closed
is the line chain closed?
std::vector< VECTOR2I > m_points
array of vertices
int SegmentCount() const
Function SegmentCount()
Definition: seg.h:39

References m_closed, m_points, and SegmentCount().

Referenced by PNS::POSTURE_SOLVER::AddTrailPoint(), PNS::ArcHull(), PNS::LINE_PLACER::buildInitialLine(), PNS::PRESERVE_VERTEX_CONSTRAINT::Check(), CheckClearance(), PNS::NODE::CheckColliding(), PNS::DIFF_PAIR::CheckConnectionAngle(), PNS::checkGap(), PNS::MEANDERED_LINE::CheckSelfIntersections(), PNS::closestProjectedPoint(), PNS::COST_ESTIMATOR::CornerCost(), PNS::LINE::CountCorners(), PNS::coupledBypass(), PNS::DIFF_PAIR::CoupledLength(), PNS::LINE::CSegment(), PNS::MEANDER_PLACER_BASE::cutTunedLine(), PNS::dragCornerInternal(), PNS::LINE::dragSegment45(), ROUTER_PREVIEW_ITEM::drawLineChain(), PNS::findCoupledVertices(), FindSegment(), PNS::DIFF_PAIR_PLACER::FixRoute(), PNS::LINE_PLACER::FixRoute(), DRAWSEGMENT::GetLength(), SHAPE_SIMPLE::GetSegment(), GetSegment(), PNS::LINE_PLACER::handlePullback(), PNS::LINE_PLACER::handleSelfIntersections(), Intersect(), PNS::LINE::Is45Degree(), Length(), PNS::OPTIMIZER::mergeDpStep(), PNS::LINE_PLACER::mergeHead(), PNS::OPTIMIZER::mergeObtuse(), PNS::OPTIMIZER::mergeStep(), PNS::NODE::NearestObstacle(), NearestPoint(), NearestSegment(), PathLength(), PointAlong(), PNS::LINE_PLACER::reduceTail(), PNS::LINE_PLACER::rhStopAtNearestObstacle(), POLY_GRID_PARTITION::scanCell(), PNS::SegmentHull(), SelfIntersecting(), PNS::OPTIMIZER::smartPadsSingle(), PNS::LINE::snapDraggedCorner(), PNS::LINE::snapToNeighbourSegments(), Split(), PNS::tightenSegment(), SHAPE_POLY_SET::unfractureSingle(), PNS::LINE::Walkaround(), and HYPERLYNX_EXPORTER::writeBoardInfo().

◆ CShapes()

const std::vector<ssize_t>& SHAPE_LINE_CHAIN::CShapes ( ) const
inline
Returns
the vector of values indicating shape type and location

Definition at line 345 of file shape_line_chain.h.

346  {
347  return m_shapes;
348  }
std::vector< ssize_t > m_shapes
Array of indices that refer to the index of the shape if the point is part of a larger shape,...

References m_shapes.

Referenced by BOOST_AUTO_TEST_CASE().

◆ Distance()

int SHAPE_LINE_CHAIN::Distance ( const VECTOR2I aP,
bool  aOutlineOnly = false 
) const

Function Distance()

Computes the minimum distance between the line chain and a point aP.

Parameters
aPthe point
Returns
minimum distance.

Definition at line 291 of file shape_line_chain.cpp.

292 {
293  return sqrt( SquaredDistance( aP, aOutlineOnly ) );
294 }
SEG::ecoord SquaredDistance(const VECTOR2I &aP, bool aOutlineOnly=false) const

References SHAPE_LINE_CHAIN_BASE::SquaredDistance().

Referenced by D_PAD::GetBestAnchorPosition().

◆ EdgeContainingPoint()

int SHAPE_LINE_CHAIN_BASE::EdgeContainingPoint ( const VECTOR2I aP,
int  aAccuracy = 0 
) const
inherited

Function EdgeContainingPoint()

Checks if point aP lies on an edge or vertex of the line chain.

Parameters
aPpoint to check
Returns
index of the first edge containing the point, otherwise negative

Definition at line 664 of file shape_line_chain.cpp.

665 {
666  if( !GetPointCount() )
667  return -1;
668 
669  else if( GetPointCount() == 1 )
670  {
671  VECTOR2I dist = GetPoint(0) - aPt;
672  return ( hypot( dist.x, dist.y ) <= aAccuracy + 1 ) ? 0 : -1;
673  }
674 
675  for( int i = 0; i < GetSegmentCount(); i++ )
676  {
677  const SEG s = GetSegment( i );
678 
679  if( s.A == aPt || s.B == aPt )
680  return i;
681 
682  if( s.Distance( aPt ) <= aAccuracy + 1 )
683  return i;
684  }
685 
686  return -1;
687 }
int Distance(const SEG &aSeg) const
Function Distance()
Definition: seg.h:207
VECTOR2 defines a general 2D-vector/point.
Definition: vector2d.h:61
virtual size_t GetPointCount() const =0
virtual size_t GetSegmentCount() const =0
Definition: seg.h:39
virtual const SEG GetSegment(int aIndex) const =0
VECTOR2I A
Definition: seg.h:47
virtual const VECTOR2I GetPoint(int aIndex) const =0
VECTOR2I B
Definition: seg.h:48

References SEG::A, SEG::B, SEG::Distance(), SHAPE_LINE_CHAIN_BASE::GetPoint(), SHAPE_LINE_CHAIN_BASE::GetPointCount(), SHAPE_LINE_CHAIN_BASE::GetSegment(), SHAPE_LINE_CHAIN_BASE::GetSegmentCount(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by SHAPE_LINE_CHAIN_BASE::PointOnEdge(), and PNS::LINE::Walkaround().

◆ Find()

int SHAPE_LINE_CHAIN::Find ( const VECTOR2I aP) const

Function Find()

Searches for point aP.

Parameters
aPthe point to be looked for
Returns
index of the correspoinding point in the line chain or negative when not found.

Definition at line 350 of file shape_line_chain.cpp.

351 {
352  for( int s = 0; s < PointCount(); s++ )
353  if( CPoint( s ) == aP )
354  return s;
355 
356  return -1;
357 }
int PointCount() const
Function PointCount()
const VECTOR2I & CPoint(int aIndex) const
Function Point()

References CPoint(), and PointCount().

Referenced by PNS::MEANDER_PLACER_BASE::cutTunedLine(), PNS::DRAGGER::dragViaMarkObstacles(), PNS::DRAGGER::dragViaWalkaround(), PNS::NODE::FindLinesBetweenJoints(), Split(), and PNS::LINE::Walkaround().

◆ FindSegment()

int SHAPE_LINE_CHAIN::FindSegment ( const VECTOR2I aP) const

Function FindSegment()

Searches for segment containing point aP.

Parameters
aPthe point to be looked for
Returns
index of the correspoinding segment in the line chain or negative when not found.

Definition at line 360 of file shape_line_chain.cpp.

361 {
362  for( int s = 0; s < SegmentCount(); s++ )
363  if( CSegment( s ).Distance( aP ) <= 1 )
364  return s;
365 
366  return -1;
367 }
int Distance(const SEG &aSeg) const
Function Distance()
Definition: seg.h:207
int SegmentCount() const
Function SegmentCount()
const SEG CSegment(int aIndex) const
Function CSegment()

References CSegment(), SEG::Distance(), and SegmentCount().

Referenced by PNS::MEANDER_PLACER_BASE::cutTunedLine().

◆ Format()

const std::string SHAPE_LINE_CHAIN::Format ( ) const
overridevirtual

Reimplemented from SHAPE.

Definition at line 904 of file shape_line_chain.cpp.

905 {
906  std::stringstream ss;
907 
908  ss << m_points.size() << " " << ( m_closed ? 1 : 0 ) << " " << m_arcs.size() << " ";
909 
910  for( int i = 0; i < PointCount(); i++ )
911  ss << m_points[i].x << " " << m_points[i].y << " " << m_shapes[i];
912 
913  for( size_t i = 0; i < m_arcs.size(); i++ )
914  ss << m_arcs[i].GetCenter().x << " " << m_arcs[i].GetCenter().y << " "
915  << m_arcs[i].GetP0().x << " " << m_arcs[i].GetP0().y << " "
916  << m_arcs[i].GetCentralAngle();
917 
918  return ss.str();
919 }
int PointCount() const
Function PointCount()
std::vector< SHAPE_ARC > m_arcs
bool m_closed
is the line chain closed?
std::vector< VECTOR2I > m_points
array of vertices
std::vector< ssize_t > m_shapes
Array of indices that refer to the index of the shape if the point is part of a larger shape,...

References m_arcs, m_closed, m_points, m_shapes, and PointCount().

◆ GenerateBBoxCache()

void SHAPE_LINE_CHAIN::GenerateBBoxCache ( )
inline

Definition at line 362 of file shape_line_chain.h.

363  {
365 
366  if( m_width != 0 )
368  }
BOX2I m_bbox
cached bounding box
void Compute(const Container &aPointList)
Compute the bounding box from a given list of points.
Definition: box2.h:91
std::vector< VECTOR2I > m_points
array of vertices
BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Function Inflate inflates the rectangle horizontally by dx and vertically by dy.
Definition: box2.h:302
int m_width
Width of the segments (for BBox calculations in RTree) TODO Adjust usage of SHAPE_LINE_CHAIN to accou...

References BOX2< Vec >::Compute(), BOX2< Vec >::Inflate(), m_bbox, m_points, and m_width.

Referenced by SHAPE_POLY_SET::BuildBBoxCaches(), and ZONE_FILLER::buildThermalSpokes().

◆ GetIndexableSubshape()

virtual void SHAPE_BASE::GetIndexableSubshape ( SHAPE_BASE aSubshape) const
inlinevirtualinherited

Definition at line 108 of file shape.h.

108 {};

◆ GetIndexableSubshapeCount()

virtual size_t SHAPE_BASE::GetIndexableSubshapeCount ( )
inlinevirtualinherited

Definition at line 106 of file shape.h.

106 { return 0; }

◆ GetPoint()

virtual const VECTOR2I SHAPE_LINE_CHAIN::GetPoint ( int  aIndex) const
inlineoverridevirtual

Implements SHAPE_LINE_CHAIN_BASE.

Definition at line 722 of file shape_line_chain.h.

722 { return CPoint(aIndex); }
const VECTOR2I & CPoint(int aIndex) const
Function Point()

References CPoint().

◆ GetPointCount()

virtual size_t SHAPE_LINE_CHAIN::GetPointCount ( ) const
inlineoverridevirtual

Implements SHAPE_LINE_CHAIN_BASE.

Definition at line 724 of file shape_line_chain.h.

724 { return PointCount(); }
int PointCount() const
Function PointCount()

References PointCount().

◆ GetSegment()

virtual const SEG SHAPE_LINE_CHAIN::GetSegment ( int  aIndex) const
inlineoverridevirtual

Implements SHAPE_LINE_CHAIN_BASE.

Definition at line 723 of file shape_line_chain.h.

723 { return CSegment(aIndex); }
const SEG CSegment(int aIndex) const
Function CSegment()

References CSegment().

◆ GetSegmentCount()

virtual size_t SHAPE_LINE_CHAIN::GetSegmentCount ( ) const
inlineoverridevirtual

Implements SHAPE_LINE_CHAIN_BASE.

Definition at line 725 of file shape_line_chain.h.

725 { return SegmentCount(); }
int SegmentCount() const
Function SegmentCount()

References SegmentCount().

◆ HasIndexableSubshapes()

virtual bool SHAPE_BASE::HasIndexableSubshapes ( ) const
inlinevirtualinherited

Definition at line 101 of file shape.h.

102  {
103  return false;
104  }

◆ Insert() [1/2]

void SHAPE_LINE_CHAIN::Insert ( size_t  aVertex,
const VECTOR2I aP 
)

Definition at line 440 of file shape_line_chain.cpp.

441 {
442  if( m_shapes[aVertex] != SHAPE_IS_PT )
443  convertArc( aVertex );
444 
445  m_points.insert( m_points.begin() + aVertex, aP );
446  m_shapes.insert( m_shapes.begin() + aVertex, ssize_t( SHAPE_IS_PT ) );
447 
448  assert( m_shapes.size() == m_points.size() );
449 }
void convertArc(ssize_t aArcIndex)
Converts an arc to only a point chain by removing the arc and references.
std::vector< VECTOR2I > m_points
array of vertices
std::vector< ssize_t > m_shapes
Array of indices that refer to the index of the shape if the point is part of a larger shape,...
static constexpr ssize_t SHAPE_IS_PT

References convertArc(), m_points, m_shapes, and SHAPE_IS_PT.

Referenced by PNS::LINE::dragSegment45().

◆ Insert() [2/2]

void SHAPE_LINE_CHAIN::Insert ( size_t  aVertex,
const SHAPE_ARC aArc 
)

Step 1: Find the position for the new arc in the existing arc vector

Step 2: Add the arc polyline points to the chain

Step 3: Add the vector of indices to the shape vector

Definition at line 452 of file shape_line_chain.cpp.

453 {
454  if( m_shapes[aVertex] != SHAPE_IS_PT )
455  convertArc( aVertex );
456 
458  size_t arc_pos = m_arcs.size();
459 
460  for( auto arc_it = m_shapes.rbegin() ;
461  arc_it != m_shapes.rend() + aVertex;
462  arc_it++ )
463  {
464  if( *arc_it != SHAPE_IS_PT )
465  arc_pos = ( *arc_it )++;
466  }
467 
468  m_arcs.insert( m_arcs.begin() + arc_pos, aArc );
469 
471  auto& chain = aArc.ConvertToPolyline();
472  m_points.insert( m_points.begin() + aVertex,
473  chain.CPoints().begin(), chain.CPoints().end() );
474 
476  std::vector<size_t> new_points( chain.PointCount(), arc_pos );
477  m_shapes.insert( m_shapes.begin() + aVertex, new_points.begin(), new_points.end() );
478  assert( m_shapes.size() == m_points.size() );
479 }
void convertArc(ssize_t aArcIndex)
Converts an arc to only a point chain by removing the arc and references.
std::vector< SHAPE_ARC > m_arcs
std::vector< VECTOR2I > m_points
array of vertices
std::vector< ssize_t > m_shapes
Array of indices that refer to the index of the shape if the point is part of a larger shape,...
static constexpr ssize_t SHAPE_IS_PT
const SHAPE_LINE_CHAIN ConvertToPolyline(double aAccuracy=500.0) const
Constructs a SHAPE_LINE_CHAIN of segments from a given arc.
Definition: shape_arc.cpp:231

References convertArc(), SHAPE_ARC::ConvertToPolyline(), m_arcs, m_points, m_shapes, and SHAPE_IS_PT.

◆ Intersect() [1/2]

int SHAPE_LINE_CHAIN::Intersect ( const SEG aSeg,
INTERSECTIONS aIp 
) const

Function Intersect()

Finds all intersection points between our line chain and the segment aSeg.

Parameters
aSegthe segment chain to find intersections with
aIpreference to a vector to store found intersections. Intersection points are sorted with increasing distances from point aSeg.a.
Returns
number of intersections found

Definition at line 497 of file shape_line_chain.cpp.

498 {
499  for( int s = 0; s < SegmentCount(); s++ )
500  {
501  OPT_VECTOR2I p = CSegment( s ).Intersect( aSeg );
502 
503  if( p )
504  {
505  INTERSECTION is;
506  is.our = CSegment( s );
507  is.their = aSeg;
508  is.p = *p;
509  aIp.push_back( is );
510  }
511  }
512 
513  compareOriginDistance comp( aSeg.A );
514  sort( aIp.begin(), aIp.end(), comp );
515 
516  return aIp.size();
517 }
OPT_VECTOR2I Intersect(const SEG &aSeg, bool aIgnoreEndpoints=false, bool aLines=false) const
Function Intersect()
Definition: seg.cpp:93
OPT< VECTOR2I > OPT_VECTOR2I
Definition: seg.h:37
int SegmentCount() const
Function SegmentCount()
const SEG CSegment(int aIndex) const
Function CSegment()
VECTOR2I A
Definition: seg.h:47

References SEG::A, CSegment(), SEG::Intersect(), SHAPE_LINE_CHAIN::INTERSECTION::our, SHAPE_LINE_CHAIN::INTERSECTION::p, SegmentCount(), and SHAPE_LINE_CHAIN::INTERSECTION::their.

Referenced by PNS::OPTIMIZER::customBreakouts(), CN_ITEM::GetAnchor(), PNS::LINE_PLACER::handleSelfIntersections(), Intersects(), PNS::NODE::NearestObstacle(), POLYGON_GEOM_MANAGER::updateLeaderPoints(), and PNS::LINE::Walkaround().

◆ Intersect() [2/2]

int SHAPE_LINE_CHAIN::Intersect ( const SHAPE_LINE_CHAIN aChain,
INTERSECTIONS aIp 
) const

Function Intersect()

Finds all intersection points between our line chain and the line chain aChain.

Parameters
aChainthe line chain to find intersections with
aIpreference to a vector to store found intersections. Intersection points are sorted with increasing path lengths from the starting point of aChain.
Returns
number of intersections found

Definition at line 538 of file shape_line_chain.cpp.

539 {
540  BOX2I bb_other = aChain.BBox();
541 
542  for( int s1 = 0; s1 < SegmentCount(); s1++ )
543  {
544  const SEG& a = CSegment( s1 );
545  const BOX2I bb_cur( a.A, a.B - a.A );
546 
547  if( !bb_other.Intersects( bb_cur ) )
548  continue;
549 
550  for( int s2 = 0; s2 < aChain.SegmentCount(); s2++ )
551  {
552  const SEG& b = aChain.CSegment( s2 );
553  INTERSECTION is;
554 
555  if( a.Collinear( b ) )
556  {
557  is.our = a;
558  is.their = b;
559 
560  if( a.Contains( b.A ) ) { is.p = b.A; addIntersection(aIp, PointCount(), is); }
561  if( a.Contains( b.B ) ) { is.p = b.B; addIntersection(aIp, PointCount(), is); }
562  if( b.Contains( a.A ) ) { is.p = a.A; addIntersection(aIp, PointCount(), is); }
563  if( b.Contains( a.B ) ) { is.p = a.B; addIntersection(aIp, PointCount(), is); }
564  }
565  else
566  {
567  OPT_VECTOR2I p = a.Intersect( b );
568 
569  if( p )
570  {
571  is.p = *p;
572  is.our = a;
573  is.their = b;
574  addIntersection(aIp, PointCount(), is);
575  }
576  }
577  }
578  }
579 
580  return aIp.size();
581 }
OPT_VECTOR2I Intersect(const SEG &aSeg, bool aIgnoreEndpoints=false, bool aLines=false) const
Function Intersect()
Definition: seg.cpp:93
int PointCount() const
Function PointCount()
bool Intersects(const BOX2< Vec > &aRect) const
Function Intersects.
Definition: box2.h:236
const BOX2I BBox(int aClearance=0) const override
Function BBox()
OPT< VECTOR2I > OPT_VECTOR2I
Definition: seg.h:37
int SegmentCount() const
Function SegmentCount()
bool Collinear(const SEG &aSeg) const
Function Collinear()
Definition: seg.h:243
Definition: seg.h:39
const SEG CSegment(int aIndex) const
Function CSegment()
VECTOR2I A
Definition: seg.h:47
static void addIntersection(SHAPE_LINE_CHAIN::INTERSECTIONS &aIps, int aPc, const SHAPE_LINE_CHAIN::INTERSECTION &aP)
bool Contains(const SEG &aSeg) const
Definition: seg.h:299
VECTOR2I B
Definition: seg.h:48

References SEG::A, addIntersection(), SEG::B, BBox(), SEG::Collinear(), SEG::Contains(), CSegment(), SEG::Intersect(), BOX2< Vec >::Intersects(), SHAPE_LINE_CHAIN::INTERSECTION::our, SHAPE_LINE_CHAIN::INTERSECTION::p, PointCount(), SegmentCount(), and SHAPE_LINE_CHAIN::INTERSECTION::their.

◆ Intersects()

bool SHAPE_LINE_CHAIN::Intersects ( const SHAPE_LINE_CHAIN aChain) const

Definition at line 938 of file shape_line_chain.cpp.

939 {
941  return Intersect( aChain, dummy ) != 0;
942 }
int Intersect(const SEG &aSeg, INTERSECTIONS &aIp) const
Function Intersect()
std::vector< INTERSECTION > INTERSECTIONS
static LIB_PART * dummy()
Used to draw a dummy shape when a LIB_PART is not found in library.

References dummy(), and Intersect().

Referenced by PNS::DIFF_PAIR::BuildInitial().

◆ isArc()

bool SHAPE_LINE_CHAIN::isArc ( size_t  aSegment) const
inline

Definition at line 717 of file shape_line_chain.h.

718  {
719  return aSegment < m_shapes.size() && m_shapes[aSegment] != SHAPE_IS_PT;
720  }
std::vector< ssize_t > m_shapes
Array of indices that refer to the index of the shape if the point is part of a larger shape,...
static constexpr ssize_t SHAPE_IS_PT

References m_shapes, and SHAPE_IS_PT.

Referenced by PNS::LINE::Is45Degree(), and PNS::OPTIMIZER::mergeStep().

◆ IsClosed()

bool SHAPE_LINE_CHAIN::IsClosed ( ) const
inlineoverridevirtual

Function IsClosed()

Returns
aClosed: true, when our line is closed.

Implements SHAPE_LINE_CHAIN_BASE.

Definition at line 197 of file shape_line_chain.h.

198  {
199  return m_closed;
200  }
bool m_closed
is the line chain closed?

References m_closed.

Referenced by SHAPE_POLY_SET::AddOutline(), ZONE_CONTAINER::AddPolygon(), ROUTER_PREVIEW_ITEM::drawLineChain(), KIGFX::CAIRO_GAL_BASE::drawPoly(), KIGFX::OPENGL_GAL::DrawPolyline(), PLOTTER::PlotPoly(), PNS::pointInside2(), and SelfIntersecting().

◆ IsNull()

bool SHAPE::IsNull ( ) const
inlineinherited

Function IsNull()

Returns true if the shape is a null shape.

Return values
trueif null :-)

Definition at line 158 of file shape.h.

159  {
160  return m_type == SH_NULL;
161  }
SHAPE_TYPE m_type
type of our shape
Definition: shape.h:108
circular arc
Definition: shape.h:50

References SHAPE_BASE::m_type, and SH_NULL.

◆ IsSolid()

bool SHAPE_LINE_CHAIN::IsSolid ( ) const
inlineoverridevirtual

Implements SHAPE.

Definition at line 690 of file shape_line_chain.h.

691  {
692  return false;
693  }

◆ Length()

long long int SHAPE_LINE_CHAIN::Length ( ) const

◆ Mirror()

void SHAPE_LINE_CHAIN::Mirror ( bool  aX = true,
bool  aY = false,
const VECTOR2I aRef = { 0, 0 } 
)

Mirrors the line points about y or x (or both)

Parameters
aXIf true, mirror about the y axis (flip X coordinate)
aYIf true, mirror about the x axis (flip Y coordinate)
aRefsets the reference point about which to mirror

Definition at line 188 of file shape_line_chain.cpp.

189 {
190  for( auto& pt : m_points )
191  {
192  if( aX )
193  pt.x = -pt.x + 2 * aRef.x;
194 
195  if( aY )
196  pt.y = -pt.y + 2 * aRef.y;
197  }
198 
199  for( auto& arc : m_arcs )
200  arc.Mirror( aX, aY, aRef );
201 }
std::vector< SHAPE_ARC > m_arcs
std::vector< VECTOR2I > m_points
array of vertices

References m_arcs, m_points, VECTOR2< T >::x, and VECTOR2< T >::y.

◆ Move()

void SHAPE_LINE_CHAIN::Move ( const VECTOR2I aVector)
inlineoverridevirtual

Implements SHAPE.

Definition at line 665 of file shape_line_chain.h.

666  {
667  for( auto& pt : m_points )
668  pt += aVector;
669 
670  for( auto& arc : m_arcs )
671  arc.Move( aVector );
672  }
std::vector< SHAPE_ARC > m_arcs
std::vector< VECTOR2I > m_points
array of vertices

References m_arcs, and m_points.

Referenced by ZONE_FILLER::addHatchFillTypeOnZone(), D_PAD::BuildEffectiveShapes(), ZONE_FILLER::buildThermalSpokes(), PLACEFILE_GERBER_WRITER::CreatePlaceFile(), and SHAPE_SIMPLE::Move().

◆ NearestPoint() [1/2]

const VECTOR2I SHAPE_LINE_CHAIN::NearestPoint ( const VECTOR2I aP) const

Function NearestPoint()

Finds a point on the line chain that is closest to point aP.

Returns
the nearest point.

Definition at line 844 of file shape_line_chain.cpp.

845 {
846  int min_d = INT_MAX;
847  int nearest = 0;
848 
849  for( int i = 0; i < SegmentCount(); i++ )
850  {
851  int d = CSegment( i ).Distance( aP );
852 
853  if( d < min_d )
854  {
855  min_d = d;
856  nearest = i;
857  }
858  }
859 
860  return CSegment( nearest ).NearestPoint( aP );
861 }
int Distance(const SEG &aSeg) const
Function Distance()
Definition: seg.h:207
const VECTOR2I NearestPoint(const VECTOR2I &aP) const
Function NearestPoint()
Definition: seg.h:395
int SegmentCount() const
Function SegmentCount()
const SEG CSegment(int aIndex) const
Function CSegment()

References CSegment(), SEG::Distance(), SEG::NearestPoint(), and SegmentCount().

Referenced by GRID_HELPER::computeAnchors(), PNS::MEANDER_PLACER_BASE::cutTunedLine(), PNS::DRAGGER::dragShove(), PNS::MoveDiagonal(), and PNS::DRAGGER::optimizeAndUpdateDraggedLine().

◆ NearestPoint() [2/2]

const VECTOR2I SHAPE_LINE_CHAIN::NearestPoint ( const SEG aSeg,
int &  dist 
) const

Function NearestPoint()

Finds a point on the line chain that is closest to the line defined by the points of segment aSeg, also returns the distance.

Parameters
aSegSegment defining the line.
distreference receiving the distance to the nearest point.
Returns
the nearest point.

Definition at line 864 of file shape_line_chain.cpp.

865 {
866  int nearest = 0;
867 
868  dist = INT_MAX;
869  for( int i = 0; i < PointCount(); i++ )
870  {
871  int d = aSeg.LineDistance( CPoint( i ) );
872 
873  if( d < dist )
874  {
875  dist = d;
876  nearest = i;
877  }
878  }
879 
880  return CPoint( nearest );
881 }
int LineDistance(const VECTOR2I &aP, bool aDetermineSide=false) const
Function LineDistance()
Definition: seg.h:378
int PointCount() const
Function PointCount()
const VECTOR2I & CPoint(int aIndex) const
Function Point()

References CPoint(), SEG::LineDistance(), and PointCount().

◆ NearestSegment()

int SHAPE_LINE_CHAIN::NearestSegment ( const VECTOR2I aP) const

Find the segment nearest the given point.

Parameters
aPpoint to compare with
Returns
the index of the segment closest to the point

Definition at line 884 of file shape_line_chain.cpp.

885 {
886  int min_d = INT_MAX;
887  int nearest = 0;
888 
889  for( int i = 0; i < SegmentCount(); i++ )
890  {
891  int d = CSegment( i ).Distance( aP );
892 
893  if( d < min_d )
894  {
895  min_d = d;
896  nearest = i;
897  }
898  }
899 
900  return nearest;
901 }
int Distance(const SEG &aSeg) const
Function Distance()
Definition: seg.h:207
int SegmentCount() const
Function SegmentCount()
const SEG CSegment(int aIndex) const
Function CSegment()

References CSegment(), SEG::Distance(), and SegmentCount().

Referenced by SCH_SHEET_PIN::ConstrainOnEdge().

◆ NewFacet()

FACET * SHAPE::NewFacet ( )
inherited

Definition at line 705 of file wrlfacet.cpp.

706 {
707  FACET* fp = new FACET;
708  facets.push_back( fp );
709  return fp;
710 }
Definition: wrlfacet.h:41
std::list< FACET * > facets
Definition: wrlfacet.h:143

References SHAPE::facets.

Referenced by WRL1FACESET::TranslateToSG(), X3DIFACESET::TranslateToSG(), and WRL2FACESET::TranslateToSG().

◆ operator!=()

bool SHAPE_LINE_CHAIN::operator!= ( const SHAPE_LINE_CHAIN aRhs) const
inline

Definition at line 649 of file shape_line_chain.h.

650  {
651  if( PointCount() != aRhs.PointCount() )
652  return true;
653 
654  for( int i = 0; i < PointCount(); i++ )
655  {
656  if( CPoint( i ) != aRhs.CPoint( i ) )
657  return true;
658  }
659 
660  return false;
661  }
int PointCount() const
Function PointCount()
const VECTOR2I & CPoint(int aIndex) const
Function Point()

References CPoint(), and PointCount().

◆ operator=()

SHAPE_LINE_CHAIN& SHAPE_LINE_CHAIN::operator= ( const SHAPE_LINE_CHAIN )
default

◆ Parse()

bool SHAPE_LINE_CHAIN::Parse ( std::stringstream &  aStream)
overridevirtual

Reimplemented from SHAPE.

Definition at line 950 of file shape_line_chain.cpp.

951 {
952  size_t n_pts;
953  size_t n_arcs;
954 
955  m_points.clear();
956  aStream >> n_pts;
957 
958  // Rough sanity check, just make sure the loop bounds aren't absolutely outlandish
959  if( n_pts > aStream.str().size() )
960  return false;
961 
962  aStream >> m_closed;
963  aStream >> n_arcs;
964 
965  if( n_arcs > aStream.str().size() )
966  return false;
967 
968  for( size_t i = 0; i < n_pts; i++ )
969  {
970  int x, y;
971  ssize_t ind;
972  aStream >> x;
973  aStream >> y;
974  m_points.emplace_back( x, y );
975 
976  aStream >> ind;
977  m_shapes.push_back( ind );
978  }
979 
980  for( size_t i = 0; i < n_arcs; i++ )
981  {
982  VECTOR2I p0, pc;
983  double angle;
984 
985  aStream >> pc.x;
986  aStream >> pc.y;
987  aStream >> p0.x;
988  aStream >> p0.y;
989  aStream >> angle;
990 
991  m_arcs.emplace_back( pc, p0, angle );
992  }
993 
994  return true;
995 }
VECTOR2 defines a general 2D-vector/point.
Definition: vector2d.h:61
std::vector< SHAPE_ARC > m_arcs
bool m_closed
is the line chain closed?
std::vector< VECTOR2I > m_points
array of vertices
std::vector< ssize_t > m_shapes
Array of indices that refer to the index of the shape if the point is part of a larger shape,...
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)

References PNS::angle(), m_arcs, m_closed, m_points, m_shapes, VECTOR2< T >::x, and VECTOR2< T >::y.

◆ PathLength()

int SHAPE_LINE_CHAIN::PathLength ( const VECTOR2I aP) const

Function PathLength()

Computes the walk path length from the beginning of the line chain and the point aP belonging to our line.

Returns
: path length in Euclidean metric or -1 if aP does not belong to the line chain.

Definition at line 584 of file shape_line_chain.cpp.

585 {
586  int sum = 0;
587 
588  for( int i = 0; i < SegmentCount(); i++ )
589  {
590  const SEG seg = CSegment( i );
591  int d = seg.Distance( aP );
592 
593  if( d <= 1 )
594  {
595  sum += ( aP - seg.A ).EuclideanNorm();
596  return sum;
597  }
598  else
599  sum += seg.Length();
600  }
601 
602  return -1;
603 }
double EuclideanNorm(const wxPoint &vector)
Euclidean norm of a 2D vector.
Definition: trigo.h:133
int Length() const
Function Length()
Definition: seg.h:319
int Distance(const SEG &aSeg) const
Function Distance()
Definition: seg.h:207
int SegmentCount() const
Function SegmentCount()
Definition: seg.h:39
const SEG CSegment(int aIndex) const
Function CSegment()
VECTOR2I A
Definition: seg.h:47

References SEG::A, CSegment(), SEG::Distance(), EuclideanNorm(), SEG::Length(), and SegmentCount().

Referenced by PNS::NODE::NearestObstacle(), and PNS::LINE::Walkaround().

◆ PointAlong()

const VECTOR2I SHAPE_LINE_CHAIN::PointAlong ( int  aPathLength) const

Definition at line 998 of file shape_line_chain.cpp.

999 {
1000  int total = 0;
1001 
1002  if( aPathLength == 0 )
1003  return CPoint( 0 );
1004 
1005  for( int i = 0; i < SegmentCount(); i++ )
1006  {
1007  const SEG& s = CSegment( i );
1008  int l = s.Length();
1009 
1010  if( total + l >= aPathLength )
1011  {
1012  VECTOR2I d( s.B - s.A );
1013  return s.A + d.Resize( aPathLength - total );
1014  }
1015 
1016  total += l;
1017  }
1018 
1019  return CPoint( -1 );
1020 }
int Length() const
Function Length()
Definition: seg.h:319
VECTOR2 defines a general 2D-vector/point.
Definition: vector2d.h:61
const VECTOR2I & CPoint(int aIndex) const
Function Point()
int SegmentCount() const
Function SegmentCount()
Definition: seg.h:39
VECTOR2< T > Resize(T aNewLength) const
Function Resize returns a vector of the same direction, but length specified in aNewLength.
Definition: vector2d.h:392
const SEG CSegment(int aIndex) const
Function CSegment()
VECTOR2I A
Definition: seg.h:47
VECTOR2I B
Definition: seg.h:48

References SEG::A, SEG::B, CPoint(), CSegment(), SEG::Length(), VECTOR2< T >::Resize(), and SegmentCount().

◆ PointCount()

int SHAPE_LINE_CHAIN::PointCount ( ) const
inline

Function PointCount()

Returns the number of points (vertices) in this line chain

Returns
number of points

Definition at line 241 of file shape_line_chain.h.

242  {
243  return m_points.size();
244  }
std::vector< VECTOR2I > m_points
array of vertices

References m_points.

Referenced by POLYGON_GEOM_MANAGER::AddPoint(), SHAPE_LINE_CHAIN::POINT_INSIDE_TRACKER::AddPolyline(), BOARD_ADAPTER::AddSolidAreasShapesToContainer(), CLAYER_TRIANGLES::AddToMiddleContourns(), Append(), PNS::LINE::AppendVia(), ArePolylineEndPointsNearCircle(), ArePolylineMidPointsNearCircle(), BOOST_AUTO_TEST_CASE(), BuildConvexHull(), D_PAD::BuildEffectiveShapes(), BOARD_ADAPTER::buildPadShapeThickOutlineAsPolygon(), BOARD_ADAPTER::buildPadShapeThickOutlineAsSegments(), DRAWSEGMENT::BuildPolyPointsList(), PNS::LINE::ChangedArea(), PNS::KEEP_TOPOLOGY_CONSTRAINT::Check(), CheckClearance(), CLastPoint(), convertToClipper(), PNS::coupledBypass(), CPoint(), PolygonTriangulation::createList(), CreatePadsShapesSection(), PLACEFILE_GERBER_WRITER::CreatePlaceFile(), POLYGON_GEOM_MANAGER::DeleteLastCorner(), DIALOG_PAD_PRIMITIVE_POLY_PROPS::doValidate(), PNS::LINE::dragSegment45(), KIGFX::GERBVIEW_PAINTER::draw(), APERTURE_MACRO::DrawApertureMacroShape(), KIGFX::CAIRO_GAL_BASE::drawPoly(), KIGFX::OPENGL_GAL::DrawPolygon(), KIGFX::OPENGL_GAL::DrawPolyline(), KIGFX::PREVIEW::POLYGON_ITEM::drawPreviewShape(), export_vrml_board(), export_vrml_padshape(), export_vrml_polygon(), export_vrml_zones(), DSN::SPECCTRA_DB::fillBOUNDARY(), AR_AUTOPLACER::fillMatrix(), Find(), PNS::LINE_PLACER::FixRoute(), HPGL_PLOTTER::FlashPadCustom(), PSLIKE_PLOTTER::FlashPadCustom(), GERBER_PLOTTER::FlashPadCustom(), DXF_PLOTTER::FlashPadCustom(), HPGL_PLOTTER::FlashPadRoundRect(), PSLIKE_PLOTTER::FlashPadRoundRect(), GERBER_PLOTTER::FlashPadRoundRect(), DXF_PLOTTER::FlashPadRoundRect(), PCB_IO::format(), Format(), PNS::MEANDER_SHAPE::genMeanderShape(), CADSTAR_PCB_ARCHIVE_LOADER::getLineChainFromDrawsegments(), SHAPE_SIMPLE::GetPointCount(), GetPointCount(), CADSTAR_PCB_ARCHIVE_LOADER::getPolySetFromCadstarShape(), PNS::POSTURE_SOLVER::GetPosture(), SHAPE_POLY_SET::GetRelativeIndices(), PNS::LINE_PLACER::handlePullback(), PNS::LINE_PLACER::handleSelfIntersections(), WS_DRAW_ITEM_POLYPOLYGONS::HitTest(), Intersect(), POLYGON_GEOM_MANAGER::IsPolygonInProgress(), DRAWSEGMENT::IsPolyShapeValid(), POLYGON_GEOM_MANAGER::IsSelfIntersecting(), DSN::SPECCTRA_DB::makePADSTACK(), PNS::OPTIMIZER::mergeObtuse(), NearestPoint(), POLYGON_GEOM_MANAGER::NewPointClosesOutline(), operator!=(), BOOST_TEST_PRINT_NAMESPACE_OPEN::print_log_value< SHAPE_LINE_CHAIN >::operator()(), PNS::LINE_PLACER::optimizeTailHeadTransition(), BITMAPCONV_INFO::outputOnePolygon(), BRDITEMS_PLOTTER::PlotFilledAreas(), PlotLayerOutlines(), PLOTTER::PlotPoly(), DXF_PLOTTER::PlotPoly(), PlotSolderMaskLayer(), PlotWorkSheet(), SHAPE_SIMPLE::PointCount(), PNS::LINE::PointCount(), PNS::pointInside2(), polygon_Convert(), GERBER_DRAW_ITEM::PrintGerberPoly(), WS_DRAW_ITEM_POLYPOLYGONS::PrintWsItem(), PNS::SHOVE::processHullSet(), Remove(), Replace(), PNS::OPTIMIZER::runSmartPads(), SetPoint(), KIGFX::PREVIEW::POLYGON_ITEM::SetPoints(), PNS::shovedArea(), Simplify(), Slice(), DXF_PLOTTER::ThickSegment(), POLYGON_GEOM_MANAGER::updateLeaderPoints(), PNS::LINE::Walkaround(), PNS::SHOVE::walkaroundLoneVia(), HYPERLYNX_EXPORTER::writeNetObjects(), GBR_TO_PCB_EXPORTER::writePcbPolygon(), and GBR_TO_PCB_EXPORTER::writePcbZoneItem().

◆ PointInside()

bool SHAPE_LINE_CHAIN_BASE::PointInside ( const VECTOR2I aPt,
int  aAccuracy = 0,
bool  aUseBBoxCache = false 
) const
inherited

Function PointInside()

Checks if point aP lies inside a polygon (any type) defined by the line chain. For closed shapes only.

Parameters
aPtpoint to check
aUseBBoxCachegives better peformance if the bounding box caches have been generated.
Returns
true if the point is inside the shape (edge is not treated as being inside).

To check for interior points, we draw a line in the positive x direction from the point. If it intersects an even number of segments, the point is outside the line chain (it had to first enter and then exit). Otherwise, it is inside the chain.

Note: slope might be denormal here in the case of a horizontal line but we require our y to move from above to below the point (or vice versa)

Note: we open-code CPoint() here so that we don't end up calculating the size of the vector number-of-points times. This has a non-trivial impact on zone fill times.

Definition at line 606 of file shape_line_chain.cpp.

607 {
608  /*
609  * Don't check the bounding box unless it's cached. Building it is about the same speed as
610  * the rigorous test below and so just slows things down by doing potentially two tests.
611  */
612  //if( aUseBBoxCache && !m_bbox.Contains( aPt ) )
613  //return false;
614 
615  // fixme: bbox cache...
616 
617  if( !IsClosed() || GetPointCount() < 3 )
618  return false;
619 
620  bool inside = false;
621 
633  int pointCount = GetPointCount();
634 
635  for( int i = 0; i < pointCount; )
636  {
637  const auto p1 = GetPoint( i++ );
638  const auto p2 = GetPoint( i == pointCount ? 0 : i );
639  const auto diff = p2 - p1;
640 
641  if( diff.y != 0 )
642  {
643  const int d = rescale( diff.x, ( aPt.y - p1.y ), diff.y );
644 
645  if( ( ( p1.y > aPt.y ) != ( p2.y > aPt.y ) ) && ( aPt.x - p1.x < d ) )
646  inside = !inside;
647  }
648  }
649 
650  // If accuracy is <= 1 (nm) then we skip the accuracy test for performance. Otherwise
651  // we use "OnEdge(accuracy)" as a proxy for "Inside(accuracy)".
652  if( aAccuracy <= 1 )
653  return inside;
654  else
655  return inside || PointOnEdge( aPt, aAccuracy );
656 }
virtual bool IsClosed() const =0
virtual size_t GetPointCount() const =0
bool PointOnEdge(const VECTOR2I &aP, int aAccuracy=0) const
Function PointOnEdge()
T rescale(T aNumerator, T aValue, T aDenominator)
Function rescale()
Definition: util.h:95
virtual const VECTOR2I GetPoint(int aIndex) const =0

References SHAPE_LINE_CHAIN_BASE::GetPoint(), SHAPE_LINE_CHAIN_BASE::GetPointCount(), SHAPE_LINE_CHAIN_BASE::IsClosed(), SHAPE_LINE_CHAIN_BASE::PointOnEdge(), rescale(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by SHAPE_POLY_SET::containsSingle(), LIB_POLYLINE::HitTest(), ZONE_CONTAINER::HitTestCutout(), MARKER_BASE::HitTestMarker(), SHAPE_LINE_CHAIN_BASE::SquaredDistance(), and PNS::LINE::Walkaround().

◆ PointOnEdge()

bool SHAPE_LINE_CHAIN_BASE::PointOnEdge ( const VECTOR2I aP,
int  aAccuracy = 0 
) const
inherited

Function PointOnEdge()

Checks if point aP lies on an edge or vertex of the line chain.

Parameters
aPpoint to check
Returns
true if the point lies on the edge.

Definition at line 659 of file shape_line_chain.cpp.

660 {
661  return EdgeContainingPoint( aPt, aAccuracy ) >= 0;
662 }
int EdgeContainingPoint(const VECTOR2I &aP, int aAccuracy=0) const
Function EdgeContainingPoint()

References SHAPE_LINE_CHAIN_BASE::EdgeContainingPoint().

Referenced by LIB_POLYLINE::HitTest(), and SHAPE_LINE_CHAIN_BASE::PointInside().

◆ Remove() [1/2]

void SHAPE_LINE_CHAIN::Remove ( int  aStartIndex,
int  aEndIndex 
)

Function Remove()

Removes the range of points [start_index, end_index] from the line chain.

Parameters
aStartIndexstart of the point range to be replaced (inclusive)
aEndIndexend of the point range to be replaced (inclusive)

Definition at line 260 of file shape_line_chain.cpp.

261 {
262  assert( m_shapes.size() == m_points.size() );
263  if( aEndIndex < 0 )
264  aEndIndex += PointCount();
265 
266  if( aStartIndex < 0 )
267  aStartIndex += PointCount();
268 
269  if( aStartIndex >= PointCount() )
270  return;
271 
272  aEndIndex = std::min( aEndIndex, PointCount() );
273  std::set<size_t> extra_arcs;
274 
275  // Remove any overlapping arcs in the point range
276  for( int i = aStartIndex; i < aEndIndex; i++ )
277  {
278  if( m_shapes[i] != SHAPE_IS_PT )
279  extra_arcs.insert( m_shapes[i] );
280  }
281 
282  for( auto arc : extra_arcs )
283  convertArc( arc );
284 
285  m_shapes.erase( m_shapes.begin() + aStartIndex, m_shapes.begin() + aEndIndex + 1 );
286  m_points.erase( m_points.begin() + aStartIndex, m_points.begin() + aEndIndex + 1 );
287  assert( m_shapes.size() == m_points.size() );
288 }
void convertArc(ssize_t aArcIndex)
Converts an arc to only a point chain by removing the arc and references.
int PointCount() const
Function PointCount()
std::vector< VECTOR2I > m_points
array of vertices
std::vector< ssize_t > m_shapes
Array of indices that refer to the index of the shape if the point is part of a larger shape,...
static constexpr ssize_t SHAPE_IS_PT

References convertArc(), m_points, m_shapes, PointCount(), and SHAPE_IS_PT.

Referenced by POLYGON_GEOM_MANAGER::AddPoint(), PNS::LINE_PLACER::buildInitialLine(), PNS::LINE::ClipToNearestObstacle(), POLYGON_GEOM_MANAGER::DeleteLastCorner(), PNS::DIFF_PAIR_PLACER::FixRoute(), PNS::LINE_PLACER::handlePullback(), PNS::LINE_PLACER::handleSelfIntersections(), PNS::LINE_PLACER::mergeHead(), PNS::LINE_PLACER::reduceTail(), Remove(), Replace(), and PNS::WALKAROUND::Route().

◆ Remove() [2/2]

void SHAPE_LINE_CHAIN::Remove ( int  aIndex)
inline

Function Remove() removes the aIndex-th point from the line chain.

Parameters
aIndexis the index of the point to be removed.

Definition at line 487 of file shape_line_chain.h.

488  {
489  Remove( aIndex, aIndex );
490  }
void Remove(int aStartIndex, int aEndIndex)
Function Remove()

References Remove().

◆ Replace() [1/2]

void SHAPE_LINE_CHAIN::Replace ( int  aStartIndex,
int  aEndIndex,
const VECTOR2I aP 
)

Function Replace()

Replaces points with indices in range [start_index, end_index] with a single point aP.

Parameters
aStartIndexstart of the point range to be replaced (inclusive)
aEndIndexend of the point range to be replaced (inclusive)
aPreplacement point

Definition at line 204 of file shape_line_chain.cpp.

205 {
206  if( aEndIndex < 0 )
207  aEndIndex += PointCount();
208 
209  if( aStartIndex < 0 )
210  aStartIndex += PointCount();
211 
212  aEndIndex = std::min( aEndIndex, PointCount() - 1 );
213 
214  // N.B. This works because convertArc changes m_shapes on the first run
215  for( int ind = aStartIndex; ind <= aEndIndex; ind++ )
216  {
217  if( m_shapes[ind] != SHAPE_IS_PT )
218  convertArc( ind );
219  }
220 
221  if( aStartIndex == aEndIndex )
222  m_points[aStartIndex] = aP;
223  else
224  {
225  m_points.erase( m_points.begin() + aStartIndex + 1, m_points.begin() + aEndIndex + 1 );
226  m_points[aStartIndex] = aP;
227 
228  m_shapes.erase( m_shapes.begin() + aStartIndex + 1, m_shapes.begin() + aEndIndex + 1 );
229  }
230 
231  assert( m_shapes.size() == m_points.size() );
232 }
void convertArc(ssize_t aArcIndex)
Converts an arc to only a point chain by removing the arc and references.
int PointCount() const
Function PointCount()
std::vector< VECTOR2I > m_points
array of vertices
std::vector< ssize_t > m_shapes
Array of indices that refer to the index of the shape if the point is part of a larger shape,...
static constexpr ssize_t SHAPE_IS_PT

References convertArc(), m_points, m_shapes, PointCount(), and SHAPE_IS_PT.

Referenced by PNS::coupledBypass(), PNS::LINE::dragSegment45(), PNS::OPTIMIZER::mergeDpStep(), PNS::OPTIMIZER::mergeObtuse(), PNS::OPTIMIZER::mergeStep(), PNS::LINE_PLACER::optimizeTailHeadTransition(), and PNS::Tighten().

◆ Replace() [2/2]

void SHAPE_LINE_CHAIN::Replace ( int  aStartIndex,
int  aEndIndex,
const SHAPE_LINE_CHAIN aLine 
)

Function Replace()

Replaces points with indices in range [start_index, end_index] with the points from line chain aLine.

Parameters
aStartIndexstart of the point range to be replaced (inclusive)
aEndIndexend of the point range to be replaced (inclusive)
aLinereplacement line chain.

Definition at line 235 of file shape_line_chain.cpp.

236 {
237  if( aEndIndex < 0 )
238  aEndIndex += PointCount();
239 
240  if( aStartIndex < 0 )
241  aStartIndex += PointCount();
242 
243  Remove( aStartIndex, aEndIndex );
244 
245  // The total new arcs index is added to the new arc indices
246  size_t prev_arc_count = m_arcs.size();
247  auto new_shapes = aLine.m_shapes;
248 
249  for( auto& shape : new_shapes )
250  shape += prev_arc_count;
251 
252  m_shapes.insert( m_shapes.begin() + aStartIndex, new_shapes.begin(), new_shapes.end() );
253  m_points.insert( m_points.begin() + aStartIndex, aLine.m_points.begin(), aLine.m_points.end() );
254  m_arcs.insert( m_arcs.end(), aLine.m_arcs.begin(), aLine.m_arcs.end() );
255 
256  assert( m_shapes.size() == m_points.size() );
257 }
int PointCount() const
Function PointCount()
std::vector< SHAPE_ARC > m_arcs
std::vector< VECTOR2I > m_points
array of vertices
void Remove(int aStartIndex, int aEndIndex)
Function Remove()
std::vector< ssize_t > m_shapes
Array of indices that refer to the index of the shape if the point is part of a larger shape,...

References m_arcs, m_points, m_shapes, PointCount(), and Remove().

◆ Reverse()

const SHAPE_LINE_CHAIN SHAPE_LINE_CHAIN::Reverse ( ) const

Function Reverse()

Reverses point order in the line chain.

Returns
line chain with reversed point order (original A-B-C-D: returned D-C-B-A)

Definition at line 156 of file shape_line_chain.cpp.

157 {
158  SHAPE_LINE_CHAIN a( *this );
159 
160  reverse( a.m_points.begin(), a.m_points.end() );
161  reverse( a.m_shapes.begin(), a.m_shapes.end() );
162  reverse( a.m_arcs.begin(), a.m_arcs.end() );
163 
164  for( auto& sh : a.m_shapes )
165  {
166  if( sh != SHAPE_IS_PT )
167  sh = a.m_arcs.size() - sh - 1;
168  }
169 
170 
171  a.m_closed = m_closed;
172 
173  return a;
174 }
bool m_closed
is the line chain closed?
static constexpr ssize_t SHAPE_IS_PT
SHAPE_LINE_CHAIN.

References m_arcs, m_closed, m_points, m_shapes, and SHAPE_IS_PT.

Referenced by PNS::ArcHull(), PNS::KEEP_TOPOLOGY_CONSTRAINT::Check(), PNS::SHOVE::checkBumpDirection(), PNS::coupledBypass(), PNS::MEANDER_PLACER_BASE::cutTunedLine(), PNS::LINE::dragCorner45(), PNS::POSTURE_SOLVER::GetPosture(), PNS::DP_GATEWAY::Reverse(), PNS::LINE::Reverse(), PNS::SegmentHull(), and PNS::OPTIMIZER::smartPadsSingle().

◆ Rotate()

void SHAPE_LINE_CHAIN::Rotate ( double  aAngle,
const VECTOR2I aCenter = VECTOR2I( 0, 0 ) 
)
overridevirtual

Function Rotate rotates all vertices by a given angle.

Parameters
aCenteris the rotation center
aAnglerotation angle in radians

Implements SHAPE.

Definition at line 116 of file shape_line_chain.cpp.

117 {
118  for( auto& pt : m_points )
119  {
120  pt -= aCenter;
121  pt = pt.Rotate( aAngle );
122  pt += aCenter;
123  }
124 
125  for( auto& arc : m_arcs )
126  arc.Rotate( aAngle, aCenter );
127 }
std::vector< SHAPE_ARC > m_arcs
std::vector< VECTOR2I > m_points
array of vertices
VECTOR2< T > Rotate(double aAngle) const
Function Rotate rotates the vector by a given angle.
Definition: vector2d.h:377

References m_arcs, m_points, and VECTOR2< T >::Rotate().

Referenced by D_PAD::BuildEffectiveShapes(), ZONE_FILLER::buildThermalSpokes(), and PLACEFILE_GERBER_WRITER::CreatePlaceFile().

◆ Segment()

SEG SHAPE_LINE_CHAIN::Segment ( int  aIndex)
inline

Function Segment()

Returns a copy of the aIndex-th segment in the line chain.

Parameters
aIndexindex of the segment in the line chain. Negative values are counted from the end (i.e. -1 means the last segment in the line chain)
Returns
SEG - aIndex-th segment in the line chain

Definition at line 254 of file shape_line_chain.h.

255  {
256  if( aIndex < 0 )
257  aIndex += SegmentCount();
258 
259  if( aIndex == (int)( m_points.size() - 1 ) && m_closed )
260  return SEG( m_points[aIndex], m_points[0], aIndex );
261  else
262  return SEG( m_points[aIndex], m_points[aIndex + 1], aIndex );
263  }
bool m_closed
is the line chain closed?
std::vector< VECTOR2I > m_points
array of vertices
int SegmentCount() const
Function SegmentCount()
Definition: seg.h:39

References m_closed, m_points, and SegmentCount().

Referenced by POLY_GRID_PARTITION::build(), POLY_GRID_PARTITION::checkClearance(), PNS::DIFF_PAIR::CoupledSegmentPairs(), DRAWSEGMENT::MakeEffectiveShapes(), PNS::WALKAROUND::Route(), and unfracture().

◆ SegmentCount()

int SHAPE_LINE_CHAIN::SegmentCount ( ) const
inline

Function SegmentCount()

Returns number of segments in this line chain.

Returns
number of segments

Definition at line 226 of file shape_line_chain.h.

227  {
228  int c = m_points.size() - 1;
229  if( m_closed )
230  c++;
231 
232  return std::max( 0, c );
233  }
bool m_closed
is the line chain closed?
std::vector< VECTOR2I > m_points
array of vertices

References m_closed, and m_points.

Referenced by PNS::POSTURE_SOLVER::AddTrailPoint(), POLY_GRID_PARTITION::build(), PNS::LINE_PLACER::buildInitialLine(), PNS::PRESERVE_VERTEX_CONSTRAINT::Check(), CheckClearance(), PNS::NODE::CheckColliding(), PNS::DIFF_PAIR::CheckConnectionAngle(), PNS::checkGap(), PNS::MEANDERED_LINE::CheckSelfIntersections(), PNS::closestProjectedPoint(), PNS::COST_ESTIMATOR::CornerCost(), PNS::LINE::CountCorners(), PNS::DIFF_PAIR::CoupledLength(), PNS::DIFF_PAIR::CoupledSegmentPairs(), CSegment(), PNS::LINE::dragCorner45(), PNS::dragCornerInternal(), PNS::LINE::dragSegment45(), ROUTER_PREVIEW_ITEM::drawLineChain(), KIGFX::OPENGL_GAL::DrawPolygon(), PNS::DIFF_PAIR::Empty(), PNS::findCoupledVertices(), FindSegment(), PNS::DIFF_PAIR_PLACER::FixRoute(), PNS::LINE_PLACER::FixRoute(), DRAWSEGMENT::GetLength(), SHAPE_SIMPLE::GetSegmentCount(), GetSegmentCount(), PNS::LINE_PLACER::handlePullback(), PNS::DP_MEANDER_PLACER::HasPlacedAnything(), PNS::DIFF_PAIR_PLACER::HasPlacedAnything(), Intersect(), PNS::LINE::Is45Degree(), Length(), DRAWSEGMENT::MakeEffectiveShapes(), PNS::OPTIMIZER::mergeDpSegments(), PNS::OPTIMIZER::mergeDpStep(), PNS::OPTIMIZER::mergeFull(), PNS::LINE_PLACER::mergeHead(), PNS::OPTIMIZER::mergeObtuse(), PNS::OPTIMIZER::mergeStep(), PNS::NODE::NearestObstacle(), NearestPoint(), NearestSegment(), PNS::LINE_PLACER::optimizeTailHeadTransition(), PathLength(), PointAlong(), PNS::pointInside2(), PNS::LINE_PLACER::reduceTail(), PNS::WALKAROUND::Route(), Segment(), PNS::LINE::SegmentCount(), SelfIntersecting(), PNS::OPTIMIZER::smartPadsSingle(), PNS::LINE::snapDraggedCorner(), PNS::LINE::snapToNeighbourSegments(), Split(), POLYGON_GEOM_MANAGER::updateLeaderPoints(), PNS::LINE::Walkaround(), and HYPERLYNX_EXPORTER::writeBoardInfo().

◆ SelfIntersecting()

const OPT< SHAPE_LINE_CHAIN::INTERSECTION > SHAPE_LINE_CHAIN::SelfIntersecting ( ) const

Function SelfIntersecting()

Checks if the line chain is self-intersecting.

Returns
(optional) first found self-intersection point.

Definition at line 713 of file shape_line_chain.cpp.

714 {
715  for( int s1 = 0; s1 < SegmentCount(); s1++ )
716  {
717  for( int s2 = s1 + 1; s2 < SegmentCount(); s2++ )
718  {
719  const VECTOR2I s2a = CSegment( s2 ).A, s2b = CSegment( s2 ).B;
720 
721  if( s1 + 1 != s2 && CSegment( s1 ).Contains( s2a ) )
722  {
723  INTERSECTION is;
724  is.our = CSegment( s1 );
725  is.their = CSegment( s2 );
726  is.p = s2a;
727  return is;
728  }
729  else if( CSegment( s1 ).Contains( s2b ) &&
730  // for closed polylines, the ending point of the
731  // last segment == starting point of the first segment
732  // this is a normal case, not self intersecting case
733  !( IsClosed() && s1 == 0 && s2 == SegmentCount()-1 ) )
734  {
735  INTERSECTION is;
736  is.our = CSegment( s1 );
737  is.their = CSegment( s2 );
738  is.p = s2b;
739  return is;
740  }
741  else
742  {
743  OPT_VECTOR2I p = CSegment( s1 ).Intersect( CSegment( s2 ), true );
744 
745  if( p )
746  {
747  INTERSECTION is;
748  is.our = CSegment( s1 );
749  is.their = CSegment( s2 );
750  is.p = *p;
751  return is;
752  }
753  }
754  }
755  }
756 
758 }
OPT_VECTOR2I Intersect(const SEG &aSeg, bool aIgnoreEndpoints=false, bool aLines=false) const
Function Intersect()
Definition: seg.cpp:93
VECTOR2 defines a general 2D-vector/point.
Definition: vector2d.h:61
bool IsClosed() const override
Function IsClosed()
OPT< VECTOR2I > OPT_VECTOR2I
Definition: seg.h:37
int SegmentCount() const
Function SegmentCount()
const SEG CSegment(int aIndex) const
Function CSegment()
VECTOR2I A
Definition: seg.h:47
boost::optional< T > OPT
Definition: optional.h:7
VECTOR2I B
Definition: seg.h:48

References SEG::A, SEG::B, CSegment(), SEG::Intersect(), IsClosed(), SHAPE_LINE_CHAIN::INTERSECTION::our, SHAPE_LINE_CHAIN::INTERSECTION::p, SegmentCount(), and SHAPE_LINE_CHAIN::INTERSECTION::their.

Referenced by PNS::DIFF_PAIR::BuildInitial(), PNS::clipToLoopStart(), DIALOG_PAD_PRIMITIVE_POLY_PROPS::doValidate(), and PNS::SHOVE::processHullSet().

◆ SetClosed()

void SHAPE_LINE_CHAIN::SetClosed ( bool  aClosed)
inline

Function SetClosed()

Marks the line chain as closed (i.e. with a segment connecting the last point with the first point).

Parameters
aClosedwhether the line chain is to be closed or not.

Definition at line 187 of file shape_line_chain.h.

188  {
189  m_closed = aClosed;
190  }
bool m_closed
is the line chain closed?

References m_closed.

Referenced by ZONE_FILLER::addHatchFillTypeOnZone(), ZONE_CONTAINER::AddPolygon(), PNS::ArcHull(), POLY_GRID_PARTITION::build(), KI_TEST::BuildRectChain(), ZONE_FILLER::buildThermalSpokes(), SHAPE_POLY_SET::chamferFilletPolygon(), PNS::KEEP_TOPOLOGY_CONSTRAINT::Check(), CN_ZONE::CN_ZONE(), KI_TEST::CommonTestData::CommonTestData(), GRID_HELPER::computeAnchors(), Convert_path_polygon_to_polygon_blocks_and_dummy_blocks(), PNS::ConvexHull(), PLACEFILE_GERBER_WRITER::CreatePlaceFile(), KIGFX::GERBVIEW_PAINTER::draw(), SHAPE_POLY_SET::fractureSingle(), CADSTAR_PCB_ARCHIVE_LOADER::getLineChainFromDrawsegments(), PNS::POSTURE_SOLVER::GetPosture(), LIB_POLYLINE::HitTest(), IteratorFixture::IteratorFixture(), CONVERT_TOOL::makePolysFromRects(), CONVERT_TOOL::makePolysFromSegs(), GEOM_TEST::MakeSquarePolyLine(), SHAPE_POLY_SET::NewHole(), SHAPE_POLY_SET::NewOutline(), PNS::OctagonalHull(), SHAPE_RECT::Outline(), EAGLE_PLUGIN::packagePolygon(), SHAPE_POLY_SET::Parse(), ALTIUM_PCB::ParseRegions6Data(), BRDITEMS_PLOTTER::PlotFootprintGraphicItem(), polygonArea(), CONVERT_TOOL::PolyToLines(), PNS::SegmentHull(), SHAPE_SIMPLE::SHAPE_SIMPLE(), MARKER_BASE::ShapeToPolygon(), TestConcaveSquareFillet(), TransformCircleToPolygon(), unfracture(), SHAPE_POLY_SET::unfractureSingle(), and PNS::LINE::Walkaround().

◆ SetPoint()

void SHAPE_LINE_CHAIN::SetPoint ( int  aIndex,
const VECTOR2I aPos 
)
inline

Accessor Function to move a point to a specific location.

Parameters
aIndexIndex (wrapping) of the point to move
aPosNew absolute location of the point

Definition at line 291 of file shape_line_chain.h.

292  {
293  if( aIndex < 0 )
294  aIndex += PointCount();
295  else if( aIndex >= PointCount() )
296  aIndex -= PointCount();
297 
298  m_points[aIndex] = aPos;
299 
300  if( m_shapes[aIndex] != SHAPE_IS_PT )
301  convertArc( m_shapes[aIndex] );
302  }
void convertArc(ssize_t aArcIndex)
Converts an arc to only a point chain by removing the arc and references.
int PointCount() const
Function PointCount()
std::vector< VECTOR2I > m_points
array of vertices
std::vector< ssize_t > m_shapes
Array of indices that refer to the index of the shape if the point is part of a larger shape,...
static constexpr ssize_t SHAPE_IS_PT

References convertArc(), m_points, m_shapes, PointCount(), and SHAPE_IS_PT.

Referenced by PNS::LINE_PLACER::buildInitialLine(), PNS::LINE::dragCornerFree(), and PNS::MEANDER_SHAPE::genMeanderShape().

◆ SetWidth()

void SHAPE_LINE_CHAIN::SetWidth ( int  aWidth)
inline

Sets the width of all segments in the chain.

Parameters
aWidthwidth in internal units

Definition at line 206 of file shape_line_chain.h.

207  {
208  m_width = aWidth;
209  }
int m_width
Width of the segments (for BBox calculations in RTree) TODO Adjust usage of SHAPE_LINE_CHAIN to accou...

References m_width.

Referenced by PNS::LINE::SetShape(), and PNS::LINE::SetWidth().

◆ Simplify()

SHAPE_LINE_CHAIN & SHAPE_LINE_CHAIN::Simplify ( )

Function Simplify()

Simplifies the line chain by removing colinear adjacent segments and duplicate vertices.

Returns
reference to self.

Definition at line 761 of file shape_line_chain.cpp.

762 {
763  std::vector<VECTOR2I> pts_unique;
764  std::vector<ssize_t> shapes_unique;
765 
766  if( PointCount() < 2 )
767  {
768  return *this;
769  }
770  else if( PointCount() == 2 )
771  {
772  if( m_points[0] == m_points[1] )
773  m_points.pop_back();
774 
775  return *this;
776  }
777 
778  int i = 0;
779  int np = PointCount();
780 
781  // stage 1: eliminate duplicate vertices
782  while( i < np )
783  {
784  int j = i + 1;
785 
786  while( j < np && m_points[i] == m_points[j] && m_shapes[i] == m_shapes[j] )
787  j++;
788 
789  pts_unique.push_back( CPoint( i ) );
790  shapes_unique.push_back( m_shapes[i] );
791 
792  i = j;
793  }
794 
795  m_points.clear();
796  m_shapes.clear();
797  np = pts_unique.size();
798 
799  i = 0;
800 
801  // stage 1: eliminate collinear segments
802  while( i < np - 2 )
803  {
804  const VECTOR2I p0 = pts_unique[i];
805  const VECTOR2I p1 = pts_unique[i + 1];
806  int n = i;
807 
808  while( n < np - 2
809  && ( SEG( p0, p1 ).LineDistance( pts_unique[n + 2] ) <= 1
810  || SEG( p0, p1 ).Collinear( SEG( p1, pts_unique[n + 2] ) ) ) )
811  n++;
812 
813  m_points.push_back( p0 );
814  m_shapes.push_back( shapes_unique[i] );
815 
816  if( n > i )
817  i = n;
818 
819  if( n == np )
820  {
821  m_points.push_back( pts_unique[n - 1] );
822  m_shapes.push_back( shapes_unique[n - 1] );
823  return *this;
824  }
825 
826  i++;
827  }
828 
829  if( np > 1 )
830  {
831  m_points.push_back( pts_unique[np - 2] );
832  m_shapes.push_back( shapes_unique[np - 2] );
833  }
834 
835  m_points.push_back( pts_unique[np - 1] );
836  m_shapes.push_back( shapes_unique[np - 1] );
837 
838  assert( m_points.size() == m_shapes.size() );
839 
840  return *this;
841 }
VECTOR2 defines a general 2D-vector/point.
Definition: vector2d.h:61
int PointCount() const
Function PointCount()
const VECTOR2I & CPoint(int aIndex) const
Function Point()
std::vector< VECTOR2I > m_points
array of vertices
Definition: seg.h:39
std::vector< ssize_t > m_shapes
Array of indices that refer to the index of the shape if the point is part of a larger shape,...

References CPoint(), m_points, m_shapes, and PointCount().

Referenced by PNS::POSTURE_SOLVER::AddTrailPoint(), PNS::DIFF_PAIR_PLACER::attemptWalk(), DIRECTION_45::BuildInitialTrace(), PNS::LINE::ChangedArea(), CN_ZONE::CN_ZONE(), CompareGeometry(), PNS::DIFF_PAIR::CoupledSegmentPairs(), PNS::MEANDER_PLACER_BASE::cutTunedLine(), PNS::MEANDER_PLACER::doMove(), DIALOG_PAD_PRIMITIVE_POLY_PROPS::doValidate(), PNS::LINE::dragCorner45(), PNS::LINE::dragCornerFree(), PNS::LINE::dragSegment45(), PNS::OPTIMIZER::mergeDpStep(), PNS::OPTIMIZER::mergeFull(), PNS::LINE_PLACER::mergeHead(), PNS::OPTIMIZER::mergeStep(), PNS::DP_MEANDER_PLACER::Move(), PNS::SHOVE::onCollidingSolid(), PNS::LINE_PLACER::optimizeTailHeadTransition(), PNS::SHOVE::processHullSet(), PNS::LINE_PLACER::rhShoveOnly(), PNS::LINE_PLACER::rhStopAtNearestObstacle(), PNS::WALKAROUND::Route(), PNS::OPTIMIZER::runSmartPads(), PNS::TOPOLOGY::SimplifyLine(), PNS::LINE_PLACER::simplifyNewLine(), PNS::OPTIMIZER::smartPadsSingle(), PNS::Tighten(), PNS::LINE_PLACER::Trace(), and PNS::LINE::Walkaround().

◆ Slice()

const SHAPE_LINE_CHAIN SHAPE_LINE_CHAIN::Slice ( int  aStartIndex,
int  aEndIndex = -1 
) const

Function Slice()

Returns a subset of this line chain containing the [start_index, end_index] range of points.

Parameters
aStartIndexstart of the point range to be returned (inclusive)
aEndIndexend of the point range to be returned (inclusive)
Returns
cut line chain.

Definition at line 370 of file shape_line_chain.cpp.

371 {
372  SHAPE_LINE_CHAIN rv;
373 
374  if( aEndIndex < 0 )
375  aEndIndex += PointCount();
376 
377  if( aStartIndex < 0 )
378  aStartIndex += PointCount();
379 
380  for( int i = aStartIndex; i <= aEndIndex && static_cast<size_t>( i ) < m_points.size(); i++ )
381  rv.Append( m_points[i] );
382 
383  return rv;
384 }
int PointCount() const
Function PointCount()
void Append(int aX, int aY, bool aAllowDuplication=false)
Function Append()
std::vector< VECTOR2I > m_points
array of vertices
SHAPE_LINE_CHAIN.

References Append(), m_points, and PointCount().

Referenced by PNS::POSTURE_SOLVER::AddTrailPoint(), PNS::KEEP_TOPOLOGY_CONSTRAINT::Check(), PNS::clipToLoopStart(), PNS::LINE::ClipVertexRange(), PNS::MEANDER_PLACER_BASE::cutTunedLine(), PNS::LINE::dragCorner45(), PNS::dragCornerInternal(), PNS::LINE_PLACER::optimizeTailHeadTransition(), PNS::LINE_PLACER::reduceToNearestObstacle(), PNS::Tighten(), and PNS::LINE::Walkaround().

◆ Split()

int SHAPE_LINE_CHAIN::Split ( const VECTOR2I aP)

Function Split()

Inserts the point aP belonging to one of the our segments, splitting the adjacent segment in two.

Parameters
aPthe point to be inserted
Returns
index of the newly inserted point (or a negative value if aP does not lie on our line)

Definition at line 311 of file shape_line_chain.cpp.

312 {
313  int ii = -1;
314  int min_dist = 2;
315 
316  int found_index = Find( aP );
317 
318  for( int s = 0; s < SegmentCount(); s++ )
319  {
320  const SEG seg = CSegment( s );
321  int dist = seg.Distance( aP );
322 
323  // make sure we are not producing a 'slightly concave' primitive. This might happen
324  // if aP lies very close to one of already existing points.
325  if( dist < min_dist && seg.A != aP && seg.B != aP )
326  {
327  min_dist = dist;
328  if( found_index < 0 )
329  ii = s;
330  else if( s < found_index )
331  ii = s;
332  }
333  }
334 
335  if( ii < 0 )
336  ii = found_index;
337 
338  if( ii >= 0 )
339  {
340  m_points.insert( m_points.begin() + ii + 1, aP );
341  m_shapes.insert( m_shapes.begin() + ii + 1, ssize_t( SHAPE_IS_PT ) );
342 
343  return ii + 1;
344  }
345 
346  return -1;
347 }
int Find(const VECTOR2I &aP) const
Function Find()
int Distance(const SEG &aSeg) const
Function Distance()
Definition: seg.h:207
std::vector< VECTOR2I > m_points
array of vertices
int SegmentCount() const
Function SegmentCount()
Definition: seg.h:39
std::vector< ssize_t > m_shapes
Array of indices that refer to the index of the shape if the point is part of a larger shape,...
const SEG CSegment(int aIndex) const
Function CSegment()
static constexpr ssize_t SHAPE_IS_PT
VECTOR2I A
Definition: seg.h:47
VECTOR2I B
Definition: seg.h:48

References SEG::A, SEG::B, CSegment(), SEG::Distance(), Find(), m_points, m_shapes, SegmentCount(), and SHAPE_IS_PT.

Referenced by PNS::clipToLoopStart(), PNS::LINE::ClipToNearestObstacle(), PNS::MEANDER_PLACER_BASE::cutTunedLine(), PNS::LINE_PLACER::reduceToNearestObstacle(), and PNS::LINE::Walkaround().

◆ SquaredDistance()

SEG::ecoord SHAPE_LINE_CHAIN_BASE::SquaredDistance ( const VECTOR2I aP,
bool  aOutlineOnly = false 
) const
inherited

Definition at line 297 of file shape_line_chain.cpp.

298 {
300 
301  if( IsClosed() && PointInside( aP ) && !aOutlineOnly )
302  return 0;
303 
304  for( int s = 0; s < GetSegmentCount(); s++ )
305  d = std::min( d, GetSegment( s ).SquaredDistance( aP ) );
306 
307  return d;
308 }
virtual bool IsClosed() const =0
ecoord SquaredDistance(const SEG &aSeg) const
Definition: seg.cpp:37
virtual size_t GetSegmentCount() const =0
static constexpr extended_type ECOORD_MAX
Definition: vector2d.h:80
VECTOR2I::extended_type ecoord
bool PointInside(const VECTOR2I &aPt, int aAccuracy=0, bool aUseBBoxCache=false) const
Function PointInside()
virtual const SEG GetSegment(int aIndex) const =0

References VECTOR2< T >::ECOORD_MAX, SHAPE_LINE_CHAIN_BASE::GetSegment(), SHAPE_LINE_CHAIN_BASE::GetSegmentCount(), SHAPE_LINE_CHAIN_BASE::IsClosed(), SHAPE_LINE_CHAIN_BASE::PointInside(), and SEG::SquaredDistance().

Referenced by Collide(), and Distance().

◆ Type()

SHAPE_TYPE SHAPE_BASE::Type ( ) const
inlineinherited

Function Type()

Returns the type of the shape.

Return values
thetype

Definition at line 96 of file shape.h.

97  {
98  return m_type;
99  }
SHAPE_TYPE m_type
type of our shape
Definition: shape.h:108

References SHAPE_BASE::m_type.

Referenced by PNS::DP_GATEWAYS::BuildFromPrimitivePair(), collideShapes(), collideSingleShapes(), PNS::OPTIMIZER::computeBreakouts(), ROUTER_PREVIEW_ITEM::ViewDraw(), and SHAPE_FILE_IO::Write().

◆ Width()

int SHAPE_LINE_CHAIN::Width ( ) const
inline

Gets the current width of the segments in the chain.

Returns
width in internal units

Definition at line 215 of file shape_line_chain.h.

216  {
217  return m_width;
218  }
int m_width
Width of the segments (for BBox calculations in RTree) TODO Adjust usage of SHAPE_LINE_CHAIN to accou...

References m_width.

Member Data Documentation

◆ m_arcs

std::vector<SHAPE_ARC> SHAPE_LINE_CHAIN::m_arcs
private

◆ m_bbox

BOX2I SHAPE_LINE_CHAIN::m_bbox
private

cached bounding box

Definition at line 754 of file shape_line_chain.h.

Referenced by Append(), BBoxFromCache(), and GenerateBBoxCache().

◆ m_closed

bool SHAPE_LINE_CHAIN::m_closed
private

is the line chain closed?

Definition at line 744 of file shape_line_chain.h.

Referenced by Area(), Clear(), CSegment(), Format(), IsClosed(), Parse(), Reverse(), Segment(), SegmentCount(), and SetClosed().

◆ m_points

◆ m_shapes

std::vector<ssize_t> SHAPE_LINE_CHAIN::m_shapes
private

Array of indices that refer to the index of the shape if the point is part of a larger shape, e.g.

arc or spline. If the value is -1, the point is just a point.

Definition at line 739 of file shape_line_chain.h.

Referenced by Append(), ArcIndex(), Clear(), convertArc(), CShapes(), Format(), Insert(), isArc(), Parse(), Remove(), Replace(), Reverse(), SetPoint(), SHAPE_LINE_CHAIN(), Simplify(), and Split().

◆ m_type

SHAPE_TYPE SHAPE_BASE::m_type
protectedinherited

type of our shape

Definition at line 108 of file shape.h.

Referenced by SHAPE::IsNull(), and SHAPE_BASE::Type().

◆ m_width

int SHAPE_LINE_CHAIN::m_width
private

Width of the segments (for BBox calculations in RTree) TODO Adjust usage of SHAPE_LINE_CHAIN to account for where we need a width and where not Alternatively, we could split the class into a LINE_CHAIN (no width) and SHAPE_LINE_CHAIN that derives from SHAPE as well that does have a width.

Not sure yet on the correct path. TODO Note that we also have SHAPE_SIMPLE which is a closed, filled SHAPE_LINE_CHAIN.

Definition at line 751 of file shape_line_chain.h.

Referenced by BBox(), GenerateBBoxCache(), SetWidth(), and Width().

◆ SHAPE_IS_PT

constexpr ssize_t SHAPE_LINE_CHAIN::SHAPE_IS_PT = -1
staticprivate

The documentation for this class was generated from the following files: