KiCad PCB EDA Suite
SHAPE_LINE_CHAIN Class Reference

Class SHAPE_LINE_CHAIN. More...

#include <shape_line_chain.h>

Inheritance diagram for SHAPE_LINE_CHAIN:
SHAPE

Classes

struct  compareOriginDistance
 
struct  INTERSECTION
 Struct INTERSECTION. 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 VECTOR2I &aA, const VECTOR2I &aB)
 Constructor Initializes a 2-point line chain (a single segment) More...
 
 SHAPE_LINE_CHAIN (const VECTOR2I &aA, const VECTOR2I &aB, const VECTOR2I &aC)
 
 SHAPE_LINE_CHAIN (const VECTOR2I &aA, const VECTOR2I &aB, const VECTOR2I &aC, const VECTOR2I &aD)
 
 SHAPE_LINE_CHAIN (const VECTOR2I *aV, int aCount)
 
 SHAPE_LINE_CHAIN (const ClipperLib::Path &aPath)
 
 ~SHAPE_LINE_CHAIN ()
 
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
 Function IsClosed() 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...
 
VECTOR2IPoint (int aIndex)
 Function Point() More...
 
const VECTOR2ICPoint (int aIndex) const
 Function CPoint() More...
 
const std::vector< VECTOR2I > & CPoints () const
 
VECTOR2ILastPoint ()
 Returns the last point in the line chain. More...
 
const VECTOR2ICLastPoint () const
 Returns the last point in the line chain. More...
 
const BOX2I BBox (int aClearance=0) const override
 Function BBox() More...
 
bool Collide (const VECTOR2I &aP, int aClearance=0) const override
 Function Collide() More...
 
bool Collide (const SEG &aSeg, int aClearance=0) const override
 Function Collide() More...
 
int Distance (const VECTOR2I &aP, bool aOutlineOnly=false) const
 Function Distance() More...
 
const SHAPE_LINE_CHAIN Reverse () const
 Function Reverse() More...
 
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 Insert (int aVertex, const VECTOR2I &aP)
 
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 PointInside (const VECTOR2I &aPt, int aAccuracy=0) 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 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 convertFromClipper (const ClipperLib::Path &aPath)
 Function convertFromClipper() Appends the Clipper path to the current SHAPE_LINE_CHAIN. More...
 
ClipperLib::Path convertToClipper (bool aRequiredOrientation) const
 Creates a new Clipper path from the SHAPE_LINE_CHAIN in a given orientation. 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 Rotate (double aAngle, const VECTOR2I &aCenter)
 Function Rotate rotates all vertices by a given angle. More...
 
bool IsSolid () const override
 
const VECTOR2I PointAlong (int aPathLength) const
 
double Area () const
 
SHAPE_TYPE Type () const
 Function Type() More...
 
virtual bool Collide (const SHAPE *aShape, int aClearance, VECTOR2I &aMTV) const
 Function Collide() More...
 
virtual bool Collide (const SHAPE *aShape, int aClearance=0) const
 
virtual VECTOR2I Centre () const
 Function Centre() More...
 

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...
 
bool m_closed
 is the line chain closed? More...
 
BOX2I m_bbox
 cached bounding box More...
 

Detailed Description

Class 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 class in pcbnew.

SHAPE_LINE_CHAIN class shall not be used for polygons!

Definition at line 49 of file shape_line_chain.h.

Member Typedef Documentation

◆ ecoord

typedef VECTOR2I::extended_type SHAPE::ecoord
protectedinherited

Definition at line 61 of file shape.h.

◆ INTERSECTIONS

Definition at line 71 of file shape_line_chain.h.

◆ point_citer

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

Definition at line 53 of file shape_line_chain.h.

◆ point_iter

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

Definition at line 52 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 77 of file shape_line_chain.h.

77  :
78  SHAPE( SH_LINE_CHAIN ), m_closed( false )
79  {}
SHAPE(SHAPE_TYPE aType)
Constructor.
Definition: shape.h:70
bool m_closed
is the line chain closed?
line segment
Definition: shape.h:45

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 84 of file shape_line_chain.h.

84  :
85  SHAPE( SH_LINE_CHAIN ), m_points( aShape.m_points ), m_closed( aShape.m_closed )
86  {}
SHAPE(SHAPE_TYPE aType)
Constructor.
Definition: shape.h:70
bool m_closed
is the line chain closed?
std::vector< VECTOR2I > m_points
array of vertices
line segment
Definition: shape.h:45

◆ SHAPE_LINE_CHAIN() [3/7]

SHAPE_LINE_CHAIN::SHAPE_LINE_CHAIN ( const VECTOR2I aA,
const VECTOR2I aB 
)
inline

Constructor Initializes a 2-point line chain (a single segment)

Definition at line 92 of file shape_line_chain.h.

92  :
93  SHAPE( SH_LINE_CHAIN ), m_closed( false )
94  {
95  m_points.resize( 2 );
96  m_points[0] = aA;
97  m_points[1] = aB;
98  }
SHAPE(SHAPE_TYPE aType)
Constructor.
Definition: shape.h:70
bool m_closed
is the line chain closed?
std::vector< VECTOR2I > m_points
array of vertices
line segment
Definition: shape.h:45

References m_points.

◆ SHAPE_LINE_CHAIN() [4/7]

SHAPE_LINE_CHAIN::SHAPE_LINE_CHAIN ( const VECTOR2I aA,
const VECTOR2I aB,
const VECTOR2I aC 
)
inline

Definition at line 100 of file shape_line_chain.h.

100  :
101  SHAPE( SH_LINE_CHAIN ), m_closed( false )
102  {
103  m_points.resize( 3 );
104  m_points[0] = aA;
105  m_points[1] = aB;
106  m_points[2] = aC;
107  }
SHAPE(SHAPE_TYPE aType)
Constructor.
Definition: shape.h:70
bool m_closed
is the line chain closed?
std::vector< VECTOR2I > m_points
array of vertices
line segment
Definition: shape.h:45

References m_points.

◆ SHAPE_LINE_CHAIN() [5/7]

SHAPE_LINE_CHAIN::SHAPE_LINE_CHAIN ( const VECTOR2I aA,
const VECTOR2I aB,
const VECTOR2I aC,
const VECTOR2I aD 
)
inline

Definition at line 109 of file shape_line_chain.h.

109  :
110  SHAPE( SH_LINE_CHAIN ), m_closed( false )
111  {
112  m_points.resize( 4 );
113  m_points[0] = aA;
114  m_points[1] = aB;
115  m_points[2] = aC;
116  m_points[3] = aD;
117  }
SHAPE(SHAPE_TYPE aType)
Constructor.
Definition: shape.h:70
bool m_closed
is the line chain closed?
std::vector< VECTOR2I > m_points
array of vertices
line segment
Definition: shape.h:45

References m_points.

◆ SHAPE_LINE_CHAIN() [6/7]

SHAPE_LINE_CHAIN::SHAPE_LINE_CHAIN ( const VECTOR2I aV,
int  aCount 
)
inline

Definition at line 120 of file shape_line_chain.h.

120  :
121  SHAPE( SH_LINE_CHAIN ),
122  m_closed( false )
123  {
124  m_points.resize( aCount );
125 
126  for( int i = 0; i < aCount; i++ )
127  m_points[i] = *aV++;
128  }
SHAPE(SHAPE_TYPE aType)
Constructor.
Definition: shape.h:70
bool m_closed
is the line chain closed?
std::vector< VECTOR2I > m_points
array of vertices
size_t i
Definition: json11.cpp:597
line segment
Definition: shape.h:45

References i, and m_points.

◆ SHAPE_LINE_CHAIN() [7/7]

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

Definition at line 130 of file shape_line_chain.h.

130  :
131  SHAPE( SH_LINE_CHAIN ),
132  m_closed( true )
133  {
134  m_points.reserve( aPath.size() );
135 
136  for( const auto& point : aPath )
137  m_points.emplace_back( point.X, point.Y );
138  }
SHAPE(SHAPE_TYPE aType)
Constructor.
Definition: shape.h:70
bool m_closed
is the line chain closed?
std::vector< VECTOR2I > m_points
array of vertices
line segment
Definition: shape.h:45

References m_points.

◆ ~SHAPE_LINE_CHAIN()

SHAPE_LINE_CHAIN::~SHAPE_LINE_CHAIN ( )
inline

Definition at line 140 of file shape_line_chain.h.

141  {}

Member Function Documentation

◆ Append() [1/3]

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 363 of file shape_line_chain.h.

364  {
365  VECTOR2I v( aX, aY );
366  Append( v, aAllowDuplication );
367  }
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(), SHAPE_SIMPLE::Append(), PNS::DIFF_PAIR::Append(), PNS::NODE::AssembleLine(), PNS::DIFF_PAIR::BuildInitial(), DIRECTION_45::BuildInitialTrace(), CINFO3D_VISU::buildPadShapePolygon(), ZONE_FILLER::buildUnconnectedThermalStubsPolygonList(), SHAPE_POLY_SET::chamferFilletPolygon(), PNS::OPTIMIZER::circleBreakouts(), GRID_HELPER::computeAnchors(), SHAPE_ARC::ConvertToPolyline(), PNS::ConvexHull(), PNS::OPTIMIZER::customBreakouts(), PNS::MEANDER_PLACER::doMove(), DIALOG_PAD_PRIMITIVE_POLY_PROPS::doValidate(), PNS::LINE::dragCorner45(), PNS::dragCornerInternal(), PNS::LINE::dragSegment45(), PNS::MEANDER_SHAPE::forward(), SHAPE_POLY_SET::fractureSingle(), PNS::MEANDER_SHAPE::genMeanderShape(), PNS::TOPOLOGY::LeadingRatLine(), PNS::MEANDER_SHAPE::MakeCorner(), PNS::MEANDER_SHAPE::makeMiterShape(), PNS::LINE_PLACER::mergeHead(), PNS::OPTIMIZER::mergeObtuse(), PNS::MEANDER_SHAPE::miter(), PNS::DP_MEANDER_PLACER::Move(), PNS::OctagonalHull(), PNS::LINE_PLACER::optimizeTailHeadTransition(), SHAPE_RECT::Outline(), SHAPE_POLY_SET::Parse(), PNS::LINE_PLACER::rhShoveOnly(), PNS::LINE_PLACER::rhStopAtNearestObstacle(), PNS::WALKAROUND::Route(), PNS::SegmentHull(), MARKER_BASE::ShapeToPolygon(), PNS::WALKAROUND::singleStep(), Slice(), PNS::OPTIMIZER::smartPadsSingle(), PNS::MEANDER_SHAPE::start(), PNS::LINE_PLACER::Trace(), TransformCircleToPolygon(), SHAPE_POLY_SET::unfractureSingle(), and PNS::LINE::Walkaround().

◆ Append() [2/3]

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 378 of file shape_line_chain.h.

379  {
380  if( m_points.size() == 0 )
381  m_bbox = BOX2I( aP, VECTOR2I( 0, 0 ) );
382 
383  if( m_points.size() == 0 || aAllowDuplication || CPoint( -1 ) != aP )
384  {
385  m_points.push_back( aP );
386  m_bbox.Merge( aP );
387  }
388  }
BOX2I m_bbox
cached bounding box
BOX2< VECTOR2I > BOX2I
Definition: box2.h:520
VECTOR2< int > VECTOR2I
Definition: vector2d.h:587
const VECTOR2I & CPoint(int aIndex) const
Function CPoint()
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:384

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

◆ Append() [3/3]

void SHAPE_LINE_CHAIN::Append ( const SHAPE_LINE_CHAIN aOtherLine)
inline

Function Append()

Appends another line chain at the end.

Parameters
aOtherLinethe line chain to be appended.

Definition at line 396 of file shape_line_chain.h.

397  {
398  if( aOtherLine.PointCount() == 0 )
399  return;
400 
401  else if( PointCount() == 0 || aOtherLine.CPoint( 0 ) != CPoint( -1 ) )
402  {
403  const VECTOR2I p = aOtherLine.CPoint( 0 );
404  m_points.push_back( p );
405  m_bbox.Merge( p );
406  }
407 
408  for( int i = 1; i < aOtherLine.PointCount(); i++ )
409  {
410  const VECTOR2I p = aOtherLine.CPoint( i );
411  m_points.push_back( p );
412  m_bbox.Merge( p );
413  }
414  }
BOX2I m_bbox
cached bounding box
int PointCount() const
Function PointCount()
const VECTOR2I & CPoint(int aIndex) const
Function CPoint()
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:384
size_t i
Definition: json11.cpp:597

References CPoint(), i, m_bbox, m_points, BOX2< Vec >::Merge(), and PointCount().

◆ Area()

double SHAPE_LINE_CHAIN::Area ( ) const

Definition at line 689 of file shape_line_chain.cpp.

690 {
691  // see https://www.mathopenref.com/coordpolygonarea2.html
692 
693  if( !m_closed )
694  return 0.0;
695 
696  double area = 0.0;
697  int size = m_points.size();
698 
699  for( int i = 0, j = size - 1; i < size; ++i )
700  {
701  area += ( (double) m_points[j].x + m_points[i].x ) * ( (double) m_points[j].y - m_points[i].y );
702  j = i;
703  }
704 
705  return -area * 0.5;
706 }
bool m_closed
is the line chain closed?
std::vector< VECTOR2I > m_points
array of vertices
size_t i
Definition: json11.cpp:597

References i, m_closed, and m_points.

Referenced by ZONE_FILLER::addHatchFillTypeOnZone(), polygonArea(), 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 297 of file shape_line_chain.h.

298  {
299  BOX2I bbox;
300  bbox.Compute( m_points );
301 
302  if( aClearance != 0 )
303  bbox.Inflate( aClearance );
304 
305  return bbox;
306  }
void Compute(const Container &aPointList)
Compute the bounding box from a given list of points.
Definition: box2.h:89
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:300

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

Referenced by SHAPE_SIMPLE::BBox(), POLY_GRID_PARTITION::build(), AR_AUTOPLACER::fillMatrix(), Intersect(), PointInside(), and PolygonTriangulation::TesselatePolygon().

◆ 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 151 of file shape.h.

152  {
153  return BBox( 0 ).Centre(); // if nothing better is available....
154  }
virtual const BOX2I BBox(int aClearance=0) const =0
Function BBox()
Vec Centre() const
Definition: box2.h:77

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

◆ 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 419 of file shape_line_chain.cpp.

420 {
421  if( !PointCount() )
422  return false;
423 
424  else if( PointCount() == 1 )
425  return m_points[0] == aP;
426 
427  for( int i = 0; i < SegmentCount(); i++ )
428  {
429  const SEG s = CSegment( i );
430 
431  if( s.A == aP || s.B == aP )
432  return true;
433 
434  if( s.Distance( aP ) <= aDist )
435  return true;
436  }
437 
438  return false;
439 }
int Distance(const SEG &aSeg) const
Function Distance()
Definition: seg.h:199
int PointCount() const
Function PointCount()
std::vector< VECTOR2I > m_points
array of vertices
int SegmentCount() const
Function SegmentCount()
Definition: seg.h:36
const SEG CSegment(int aIndex) const
Function CSegment()
size_t i
Definition: json11.cpp:597
VECTOR2I A
Definition: seg.h:44
VECTOR2I B
Definition: seg.h:45

References SEG::A, SEG::B, CSegment(), SEG::Distance(), i, 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 291 of file shape_line_chain.h.

292  {
293  return m_points[PointCount() - 1];
294  }
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()

◆ 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 635 of file shape_line_chain.cpp.

636 {
637  return new SHAPE_LINE_CHAIN( *this );
638 }
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
Returns
true, if there is a collision.

Definition at line 545 of file shape_collisions.cpp.

546 {
547  return CollideShapes( this, aShape, aClearance, true, aMTV );
548 }
bool CollideShapes(const SHAPE *aA, const SHAPE *aB, int aClearance, bool aNeedMTV, VECTOR2I &aMTV)

References CollideShapes().

◆ Collide() [2/4]

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

Definition at line 551 of file shape_collisions.cpp.

552 {
553  VECTOR2I dummy;
554 
555  return CollideShapes( this, aShape, aClearance, false, dummy );
556 }
static LIB_PART * dummy()
Used when a LIB_PART is not found in library to draw a dummy shape This component is a 400 mils squar...
bool CollideShapes(const SHAPE *aA, const SHAPE *aB, int aClearance, bool aNeedMTV, VECTOR2I &aMTV)

References CollideShapes(), and dummy().

◆ Collide() [3/4]

bool SHAPE_LINE_CHAIN::Collide ( const VECTOR2I aP,
int  aClearance = 0 
) const
overridevirtual

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.
Returns
true, when a collision has been found

Reimplemented from SHAPE.

Definition at line 50 of file shape_line_chain.cpp.

51 {
52  // fixme: ugly!
53  SEG s( aP, aP );
54  return this->Collide( s, aClearance );
55 }
bool Collide(const VECTOR2I &aP, int aClearance=0) const override
Function Collide()
Definition: seg.h:36

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

◆ Collide() [4/4]

bool SHAPE_LINE_CHAIN::Collide ( const SEG aSeg,
int  aClearance = 0 
) const
overridevirtual

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.
Returns
true, when a collision has been found

Implements SHAPE.

Definition at line 69 of file shape_line_chain.cpp.

70 {
71  BOX2I box_a( aSeg.A, aSeg.B - aSeg.A );
72  BOX2I::ecoord_type dist_sq = (BOX2I::ecoord_type) aClearance * aClearance;
73 
74  for( int i = 0; i < SegmentCount(); i++ )
75  {
76  const SEG& s = CSegment( i );
77  BOX2I box_b( s.A, s.B - s.A );
78 
79  BOX2I::ecoord_type d = box_a.SquaredDistance( box_b );
80 
81  if( d < dist_sq )
82  {
83  if( s.Collide( aSeg, aClearance ) )
84  return true;
85  }
86  }
87 
88  return false;
89 }
VECTOR2I ::extended_type ecoord_type
Definition: box2.h:49
int SegmentCount() const
Function SegmentCount()
Definition: seg.h:36
const SEG CSegment(int aIndex) const
Function CSegment()
size_t i
Definition: json11.cpp:597
VECTOR2I A
Definition: seg.h:44
bool Collide(const SEG &aSeg, int aClearance) const
Definition: seg.cpp:167
VECTOR2I B
Definition: seg.h:45

References SEG::A, SEG::B, SEG::Collide(), CSegment(), i, SegmentCount(), and BOX2< Vec >::SquaredDistance().

◆ CompareGeometry()

bool SHAPE_LINE_CHAIN::CompareGeometry ( const SHAPE_LINE_CHAIN aOther) const

Definition at line 612 of file shape_line_chain.cpp.

613 {
614  SHAPE_LINE_CHAIN a(*this), b( aOther );
615  a.Simplify();
616  b.Simplify();
617 
618  if( a.m_points.size() != b.m_points.size() )
619  return false;
620 
621  for( int i = 0; i < a.PointCount(); i++)
622  if( a.CPoint( i ) != b.CPoint( i ) )
623  return false;
624  return true;
625 }
Class SHAPE_LINE_CHAIN.
size_t i
Definition: json11.cpp:597

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

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

◆ convertFromClipper()

void SHAPE_LINE_CHAIN::convertFromClipper ( const ClipperLib::Path &  aPath)

Function convertFromClipper() Appends the Clipper path to the current SHAPE_LINE_CHAIN.

◆ 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 33 of file shape_line_chain.cpp.

34 {
35  ClipperLib::Path c_path;
36 
37  for( int i = 0; i < PointCount(); i++ )
38  {
39  const VECTOR2I& vertex = CPoint( i );
40  c_path.push_back( ClipperLib::IntPoint( vertex.x, vertex.y ) );
41  }
42 
43  if( Orientation( c_path ) != aRequiredOrientation )
44  ReversePath( c_path );
45 
46  return c_path;
47 }
int PointCount() const
Function PointCount()
const VECTOR2I & CPoint(int aIndex) const
Function CPoint()
size_t i
Definition: json11.cpp:597

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

◆ CPoint()

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

Function CPoint()

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 265 of file shape_line_chain.h.

266  {
267  if( aIndex < 0 )
268  aIndex += PointCount();
269  else if( aIndex >= PointCount() )
270  aIndex -= PointCount();
271 
272  return m_points[aIndex];
273  }
int PointCount() const
Function PointCount()
std::vector< VECTOR2I > m_points
array of vertices

References m_points, and PointCount().

Referenced by POLYGON_GEOM_MANAGER::AddPoint(), CINFO3D_VISU::AddSolidAreasShapesToContainer(), CLAYER_TRIANGLES::AddToMiddleContourns(), Append(), PNS::LINE::AppendVia(), D_PAD::boundingRadius(), PNS::LINE_RESTRICTIONS::Build(), BuildConvexHull(), PNS::LINE_PLACER::buildInitialLine(), CINFO3D_VISU::buildPadShapeThickOutlineAsPolygon(), CINFO3D_VISU::buildPadShapeThickOutlineAsSegments(), ZONE_FILLER::buildUnconnectedThermalStubsPolygonList(), PNS::LINE::ChangedArea(), DRC::checkClearancePadToPad(), DRC::checkClearanceSegmToPad(), CompareGeometry(), convertToClipper(), PNS::coupledBypass(), SHAPE_SIMPLE::CPoint(), PNS::LINE::CPoint(), PolygonTriangulation::createList(), CreatePadsShapesSection(), DIALOG_PAD_PRIMITIVE_POLY_PROPS::doValidate(), PNS::dragCornerInternal(), PNS::LINE::dragSegment45(), ZONE_CONTAINER::DrawFilledArea(), KIGFX::CAIRO_GAL_BASE::drawPoly(), KIGFX::OPENGL_GAL::DrawPolygon(), KIGFX::OPENGL_GAL::DrawPolyline(), PNS::LOGGER::dumpShape(), export_vrml_board(), export_vrml_polygon(), export_vrml_zones(), AR_AUTOPLACER::fillMatrix(), Find(), PNS::LINE_PLACER::FixRoute(), PNS::TOPOLOGY::followTrivialPath(), PCB_IO::format(), FractureEdge::FractureEdge(), PNS::MEANDER_SHAPE::genMeanderShape(), D_PAD::GetBoundingBox(), PNS::LINE_PLACER::handlePullback(), PNS::LINE_PLACER::handleSelfIntersections(), D_PAD::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!=(), PNS::LINE_PLACER::optimizeTailHeadTransition(), PlotLayerOutlines(), PLOTTER::PlotPoly(), DXF_PLOTTER::PlotPoly(), PointAlong(), PointInside(), Polygon_Calc_BBox_3DU(), polygon_Convert(), PNS::SHOVE::processHullSet(), PNS::LINE_PLACER::removeLoops(), PNS::DIFF_PAIR_PLACER::routeHead(), PNS::OPTIMIZER::runSmartPads(), KIGFX::PREVIEW::POLYGON_ITEM::SetPoints(), Simplify(), DXF_PLOTTER::ThickSegment(), ZONE_CONTAINER::TransformSolidAreasShapesToPolygonSet(), SHAPE_POLY_SET::unfractureSingle(), PNS::MEANDER_SHAPE::updateBaseSegment(), PNS::LINE::Walkaround(), PNS::SHOVE::walkaroundLoneVia(), and HYPERLYNX_EXPORTER::writeNetObjects().

◆ CPoints()

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

Definition at line 275 of file shape_line_chain.h.

276  {
277  return m_points;
278  }
std::vector< VECTOR2I > m_points
array of vertices

References m_points.

◆ 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 230 of file shape_line_chain.h.

231  {
232  if( aIndex < 0 )
233  aIndex += SegmentCount();
234 
235  if( aIndex == (int)( m_points.size() - 1 ) && m_closed )
236  return SEG( const_cast<VECTOR2I&>( m_points[aIndex] ),
237  const_cast<VECTOR2I&>( m_points[0] ), aIndex );
238  else
239  return SEG( const_cast<VECTOR2I&>( m_points[aIndex] ),
240  const_cast<VECTOR2I&>( m_points[aIndex + 1] ), aIndex );
241  }
bool m_closed
is the line chain closed?
std::vector< VECTOR2I > m_points
array of vertices
int SegmentCount() const
Function SegmentCount()
Definition: seg.h:36

References m_closed, m_points, and SegmentCount().

Referenced by POLY_GRID_PARTITION::build(), PNS::LINE_RESTRICTIONS::Build(), PNS::LINE_PLACER::buildInitialLine(), PNS::LINE_RESTRICTIONS::Check(), POLY_GRID_PARTITION::checkClearance(), CheckClearance(), PNS::NODE::CheckColliding(), PNS::DIFF_PAIR::CheckConnectionAngle(), PNS::checkGap(), PNS::MEANDERED_LINE::CheckSelfIntersections(), Collide(), Collide(), PNS::COST_ESTIMATOR::CornerCost(), PNS::LINE::CountCorners(), PNS::coupledBypass(), PNS::DIFF_PAIR::CoupledLength(), PNS::DIFF_PAIR::CoupledSegmentPairs(), PNS::LINE::CSegment(), PNS::MEANDER_PLACER_BASE::cutTunedLine(), Distance(), PNS::dragCornerInternal(), PNS::LINE::dragSegment45(), ROUTER_PREVIEW_ITEM::drawLineChain(), EdgeContainingPoint(), PNS::findCoupledVertices(), FindSegment(), PNS::LINE_PLACER::FixRoute(), PNS::DIFF_PAIR_PLACER::FixRoute(), 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(), 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(), SHAPE_POLY_SET::unfractureSingle(), PNS::LINE::Walkaround(), and HYPERLYNX_EXPORTER::writeBoardInfo().

◆ 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 157 of file shape_line_chain.cpp.

158 {
159  int d = INT_MAX;
160 
161  if( IsClosed() && PointInside( aP ) && !aOutlineOnly )
162  return 0;
163 
164  for( int s = 0; s < SegmentCount(); s++ )
165  d = std::min( d, CSegment( s ).Distance( aP ) );
166 
167  return d;
168 }
int Distance(const SEG &aSeg) const
Function Distance()
Definition: seg.h:199
int SegmentCount() const
Function SegmentCount()
const SEG CSegment(int aIndex) const
Function CSegment()
bool PointInside(const VECTOR2I &aPt, int aAccuracy=0) const
Function PointInside()
bool IsClosed() const
Function IsClosed()
#define min(a, b)
Definition: auxiliary.h:85

References CSegment(), SEG::Distance(), IsClosed(), min, PointInside(), and SegmentCount().

Referenced by Collide(), and D_PAD::GetBestAnchorPosition().

◆ EdgeContainingPoint()

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

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 393 of file shape_line_chain.cpp.

394 {
395  if( !PointCount() )
396  return -1;
397 
398  else if( PointCount() == 1 )
399  {
400  VECTOR2I dist = m_points[0] - aPt;
401  return ( hypot( dist.x, dist.y ) <= aAccuracy + 1 ) ? 0 : -1;
402  }
403 
404  for( int i = 0; i < SegmentCount(); i++ )
405  {
406  const SEG s = CSegment( i );
407 
408  if( s.A == aPt || s.B == aPt )
409  return i;
410 
411  if( s.Distance( aPt ) <= aAccuracy + 1 )
412  return i;
413  }
414 
415  return -1;
416 }
int Distance(const SEG &aSeg) const
Function Distance()
Definition: seg.h:199
static const int dist[10][10]
Definition: ar_matrix.cpp:320
int PointCount() const
Function PointCount()
std::vector< VECTOR2I > m_points
array of vertices
int SegmentCount() const
Function SegmentCount()
Definition: seg.h:36
const SEG CSegment(int aIndex) const
Function CSegment()
size_t i
Definition: json11.cpp:597
VECTOR2I A
Definition: seg.h:44
VECTOR2I B
Definition: seg.h:45

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

Referenced by 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 209 of file shape_line_chain.cpp.

210 {
211  for( int s = 0; s < PointCount(); s++ )
212  if( CPoint( s ) == aP )
213  return s;
214 
215  return -1;
216 }
int PointCount() const
Function PointCount()
const VECTOR2I & CPoint(int aIndex) const
Function CPoint()

References CPoint(), and PointCount().

Referenced by PNS::MEANDER_PLACER_BASE::cutTunedLine(), PNS::DRAGGER::dumbDragVia(), 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 219 of file shape_line_chain.cpp.

220 {
221  for( int s = 0; s < SegmentCount(); s++ )
222  if( CSegment( s ).Distance( aP ) <= 1 )
223  return s;
224 
225  return -1;
226 }
int Distance(const SEG &aSeg) const
Function Distance()
Definition: seg.h:199
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 599 of file shape_line_chain.cpp.

600 {
601  std::stringstream ss;
602 
603  ss << m_points.size() << " " << ( m_closed ? 1 : 0 ) << " ";
604 
605  for( int i = 0; i < PointCount(); i++ )
606  ss << m_points[i].x << " " << m_points[i].y << " "; // Format() << " ";
607 
608  return ss.str();
609 }
int PointCount() const
Function PointCount()
bool m_closed
is the line chain closed?
std::vector< VECTOR2I > m_points
array of vertices
size_t i
Definition: json11.cpp:597

References i, m_closed, m_points, and PointCount().

◆ Insert()

void SHAPE_LINE_CHAIN::Insert ( int  aVertex,
const VECTOR2I aP 
)
inline

Definition at line 416 of file shape_line_chain.h.

417  {
418  m_points.insert( m_points.begin() + aVertex, aP );
419  }
std::vector< VECTOR2I > m_points
array of vertices

References m_points.

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

◆ 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 261 of file shape_line_chain.cpp.

262 {
263  for( int s = 0; s < SegmentCount(); s++ )
264  {
265  OPT_VECTOR2I p = CSegment( s ).Intersect( aSeg );
266 
267  if( p )
268  {
269  INTERSECTION is;
270  is.our = CSegment( s );
271  is.their = aSeg;
272  is.p = *p;
273  aIp.push_back( is );
274  }
275  }
276 
277  compareOriginDistance comp( aSeg.A );
278  sort( aIp.begin(), aIp.end(), comp );
279 
280  return aIp.size();
281 }
OPT_VECTOR2I Intersect(const SEG &aSeg, bool aIgnoreEndpoints=false, bool aLines=false) const
Function Intersect()
Definition: seg.cpp:132
OPT< VECTOR2I > OPT_VECTOR2I
Definition: seg.h:34
int SegmentCount() const
Function SegmentCount()
const SEG CSegment(int aIndex) const
Function CSegment()
VECTOR2I A
Definition: seg.h:44

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(), PNS::LINE_PLACER::handleSelfIntersections(), Intersects(), PNS::NODE::NearestObstacle(), 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 284 of file shape_line_chain.cpp.

285 {
286  BOX2I bb_other = aChain.BBox();
287 
288  for( int s1 = 0; s1 < SegmentCount(); s1++ )
289  {
290  const SEG& a = CSegment( s1 );
291  const BOX2I bb_cur( a.A, a.B - a.A );
292 
293  if( !bb_other.Intersects( bb_cur ) )
294  continue;
295 
296  for( int s2 = 0; s2 < aChain.SegmentCount(); s2++ )
297  {
298  const SEG& b = aChain.CSegment( s2 );
299  INTERSECTION is;
300 
301  if( a.Collinear( b ) )
302  {
303  is.our = a;
304  is.their = b;
305 
306  if( a.Contains( b.A ) ) { is.p = b.A; aIp.push_back( is ); }
307  if( a.Contains( b.B ) ) { is.p = b.B; aIp.push_back( is ); }
308  if( b.Contains( a.A ) ) { is.p = a.A; aIp.push_back( is ); }
309  if( b.Contains( a.B ) ) { is.p = a.B; aIp.push_back( is ); }
310  }
311  else
312  {
313  OPT_VECTOR2I p = a.Intersect( b );
314 
315  if( p )
316  {
317  is.p = *p;
318  is.our = a;
319  is.their = b;
320  aIp.push_back( is );
321  }
322  }
323  }
324  }
325 
326  return aIp.size();
327 }
OPT_VECTOR2I Intersect(const SEG &aSeg, bool aIgnoreEndpoints=false, bool aLines=false) const
Function Intersect()
Definition: seg.cpp:132
bool Intersects(const BOX2< Vec > &aRect) const
Function Intersects.
Definition: box2.h:234
const BOX2I BBox(int aClearance=0) const override
Function BBox()
OPT< VECTOR2I > OPT_VECTOR2I
Definition: seg.h:34
bool Contains(const VECTOR2I &aP) const
Definition: seg.cpp:188
int SegmentCount() const
Function SegmentCount()
bool Collinear(const SEG &aSeg) const
Function Collinear()
Definition: seg.h:235
Definition: seg.h:36
const SEG CSegment(int aIndex) const
Function CSegment()
VECTOR2I A
Definition: seg.h:44
VECTOR2I B
Definition: seg.h:45

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

◆ Intersects()

bool SHAPE_LINE_CHAIN::Intersects ( const SHAPE_LINE_CHAIN aChain) const

Definition at line 628 of file shape_line_chain.cpp.

629 {
631  return Intersect( aChain, dummy ) != 0;
632 }
int Intersect(const SEG &aSeg, INTERSECTIONS &aIp) const
Function Intersect()
std::vector< INTERSECTION > INTERSECTIONS
static LIB_PART * dummy()
Used when a LIB_PART is not found in library to draw a dummy shape This component is a 400 mils squar...

References dummy(), and Intersect().

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

◆ IsClosed()

bool SHAPE_LINE_CHAIN::IsClosed ( ) const
inline

Function IsClosed()

Returns
aClosed: true, when our line is closed.

Definition at line 172 of file shape_line_chain.h.

173  {
174  return m_closed;
175  }
bool m_closed
is the line chain closed?

References m_closed.

Referenced by SHAPE_POLY_SET::AddOutline(), Distance(), ROUTER_PREVIEW_ITEM::drawLineChain(), KIGFX::CAIRO_GAL_BASE::drawPoly(), KIGFX::OPENGL_GAL::DrawPolyline(), PNS::LOGGER::dumpShape(), and SelfIntersecting().

◆ IsSolid()

bool SHAPE_LINE_CHAIN::IsSolid ( ) const
inlineoverridevirtual

Implements SHAPE.

Definition at line 671 of file shape_line_chain.h.

672  {
673  return false;
674  }

◆ LastPoint()

VECTOR2I& SHAPE_LINE_CHAIN::LastPoint ( )
inline

Returns the last point in the line chain.

Definition at line 283 of file shape_line_chain.h.

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

References m_points, and PointCount().

◆ Length()

int SHAPE_LINE_CHAIN::Length ( ) const

Function Length()

Returns length of the line chain in Euclidean metric.

Returns
length of the line chain

Definition at line 103 of file shape_line_chain.cpp.

104 {
105  int l = 0;
106 
107  for( int i = 0; i < SegmentCount(); i++ )
108  l += CSegment( i ).Length();
109 
110  return l;
111 }
int Length() const
Function Length()
Definition: seg.h:296
int SegmentCount() const
Function SegmentCount()
const SEG CSegment(int aIndex) const
Function CSegment()
size_t i
Definition: json11.cpp:597

References CSegment(), i, SEG::Length(), and SegmentCount().

Referenced by PNS::COST_ESTIMATOR::Add(), PNS::LINE::dragSegment45(), PNS::OPTIMIZER::fanoutCleanup(), PNS::MEANDER_SHAPE::MaxTunableLength(), PNS::NODE::NearestObstacle(), PNS::SHOVE::onCollidingSegment(), PNS::LINE_PLACER::reduceToNearestObstacle(), PNS::COST_ESTIMATOR::Remove(), PNS::COST_ESTIMATOR::Replace(), PNS::LINE_PLACER::rhMarkObstacles(), PNS::LINE_PLACER::rhStopAtNearestObstacle(), PNS::WALKAROUND::Route(), PNS::WALKAROUND::singleStep(), PNS::DIFF_PAIR::Skew(), PNS::DIFF_PAIR::TotalLength(), and PNS::SHOVE::walkaroundLoneVia().

◆ Move()

void SHAPE_LINE_CHAIN::Move ( const VECTOR2I aVector)
inlineoverridevirtual

Implements SHAPE.

Definition at line 657 of file shape_line_chain.h.

658  {
659  for( std::vector<VECTOR2I>::iterator i = m_points.begin(); i != m_points.end(); ++i )
660  (*i) += aVector;
661  }
std::vector< VECTOR2I > m_points
array of vertices
size_t i
Definition: json11.cpp:597

References i, and m_points.

Referenced by ZONE_FILLER::addHatchFillTypeOnZone(), 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 559 of file shape_line_chain.cpp.

560 {
561  int min_d = INT_MAX;
562  int nearest = 0;
563 
564  for( int i = 0; i < SegmentCount(); i++ )
565  {
566  int d = CSegment( i ).Distance( aP );
567 
568  if( d < min_d )
569  {
570  min_d = d;
571  nearest = i;
572  }
573  }
574 
575  return CSegment( nearest ).NearestPoint( aP );
576 }
int Distance(const SEG &aSeg) const
Function Distance()
Definition: seg.h:199
const VECTOR2I NearestPoint(const VECTOR2I &aP) const
Function NearestPoint()
Definition: seg.h:374
int SegmentCount() const
Function SegmentCount()
const SEG CSegment(int aIndex) const
Function CSegment()
size_t i
Definition: json11.cpp:597

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

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

◆ 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 579 of file shape_line_chain.cpp.

580 {
581  int nearest = 0;
582 
583  dist = INT_MAX;
584  for( int i = 0; i < PointCount(); i++ )
585  {
586  int d = aSeg.LineDistance( CPoint( i ) );
587 
588  if( d < dist )
589  {
590  dist = d;
591  nearest = i;
592  }
593  }
594 
595  return CPoint( nearest );
596 }
static const int dist[10][10]
Definition: ar_matrix.cpp:320
int LineDistance(const VECTOR2I &aP, bool aDetermineSide=false) const
Function LineDistance()
Definition: seg.h:357
int PointCount() const
Function PointCount()
const VECTOR2I & CPoint(int aIndex) const
Function CPoint()
size_t i
Definition: json11.cpp:597

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

◆ operator!=()

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

Definition at line 641 of file shape_line_chain.h.

642  {
643  if( PointCount() != aRhs.PointCount() )
644  return true;
645 
646  for( int i = 0; i < PointCount(); i++ )
647  {
648  if( CPoint( i ) != aRhs.CPoint( i ) )
649  return true;
650  }
651 
652  return false;
653  }
int PointCount() const
Function PointCount()
const VECTOR2I & CPoint(int aIndex) const
Function CPoint()
size_t i
Definition: json11.cpp:597

References CPoint(), i, and PointCount().

◆ Parse()

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

Reimplemented from SHAPE.

Definition at line 640 of file shape_line_chain.cpp.

641 {
642  int n_pts;
643 
644  m_points.clear();
645  aStream >> n_pts;
646 
647  // Rough sanity check, just make sure the loop bounds aren't absolutely outlandish
648  if( n_pts < 0 || n_pts > int( aStream.str().size() ) )
649  return false;
650 
651  aStream >> m_closed;
652 
653  for( int i = 0; i < n_pts; i++ )
654  {
655  int x, y;
656  aStream >> x;
657  aStream >> y;
658  m_points.push_back( VECTOR2I( x, y ) );
659  }
660 
661  return true;
662 }
VECTOR2< int > VECTOR2I
Definition: vector2d.h:587
bool m_closed
is the line chain closed?
std::vector< VECTOR2I > m_points
array of vertices
size_t i
Definition: json11.cpp:597

References i, m_closed, and m_points.

◆ 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 negative if aP does not belong to the line chain.

Definition at line 330 of file shape_line_chain.cpp.

331 {
332  int sum = 0;
333 
334  for( int i = 0; i < SegmentCount(); i++ )
335  {
336  const SEG seg = CSegment( i );
337  int d = seg.Distance( aP );
338 
339  if( d <= 1 )
340  {
341  sum += ( aP - seg.A ).EuclideanNorm();
342  return sum;
343  }
344  else
345  sum += seg.Length();
346  }
347 
348  return -1;
349 }
double EuclideanNorm(const wxPoint &vector)
Euclidean norm of a 2D vector.
Definition: trigo.h:121
int Length() const
Function Length()
Definition: seg.h:296
int Distance(const SEG &aSeg) const
Function Distance()
Definition: seg.h:199
int SegmentCount() const
Function SegmentCount()
Definition: seg.h:36
const SEG CSegment(int aIndex) const
Function CSegment()
size_t i
Definition: json11.cpp:597
VECTOR2I A
Definition: seg.h:44

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

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

◆ Point()

◆ PointAlong()

const VECTOR2I SHAPE_LINE_CHAIN::PointAlong ( int  aPathLength) const

Definition at line 665 of file shape_line_chain.cpp.

666 {
667  int total = 0;
668 
669  if( aPathLength == 0 )
670  return CPoint( 0 );
671 
672  for( int i = 0; i < SegmentCount(); i++ )
673  {
674  const SEG& s = CSegment( i );
675  int l = s.Length();
676 
677  if( total + l >= aPathLength )
678  {
679  VECTOR2I d( s.B - s.A );
680  return s.A + d.Resize( aPathLength - total );
681  }
682 
683  total += l;
684  }
685 
686  return CPoint( -1 );
687 }
int Length() const
Function Length()
Definition: seg.h:296
const VECTOR2I & CPoint(int aIndex) const
Function CPoint()
int SegmentCount() const
Function SegmentCount()
Definition: seg.h:36
VECTOR2< T > Resize(T aNewLength) const
Function Resize returns a vector of the same direction, but length specified in aNewLength.
Definition: vector2d.h:385
const SEG CSegment(int aIndex) const
Function CSegment()
size_t i
Definition: json11.cpp:597
VECTOR2I A
Definition: seg.h:44
VECTOR2I B
Definition: seg.h:45

References SEG::A, SEG::B, CPoint(), CSegment(), i, 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 198 of file shape_line_chain.h.

199  {
200  return m_points.size();
201  }
std::vector< VECTOR2I > m_points
array of vertices

References m_points.

Referenced by POLYGON_GEOM_MANAGER::AddPoint(), CINFO3D_VISU::AddSolidAreasShapesToContainer(), CLAYER_TRIANGLES::AddToMiddleContourns(), Append(), PNS::LINE::AppendVia(), D_PAD::boundingRadius(), PNS::LINE_RESTRICTIONS::Build(), BuildConvexHull(), CINFO3D_VISU::buildPadShapeThickOutlineAsPolygon(), CINFO3D_VISU::buildPadShapeThickOutlineAsSegments(), DRAWSEGMENT::BuildPolyPointsList(), ZONE_FILLER::buildUnconnectedThermalStubsPolygonList(), PNS::LINE::ChangedArea(), CheckClearance(), DRC::checkClearancePadToPad(), DRC::checkClearanceSegmToPad(), CLastPoint(), convertToClipper(), PNS::coupledBypass(), CPoint(), PolygonTriangulation::createList(), CreatePadsShapesSection(), D_PAD::CustomShapeAsPolygonToBoardPosition(), POLYGON_GEOM_MANAGER::DeleteLastCorner(), DIALOG_PAD_PRIMITIVE_POLY_PROPS::doValidate(), PNS::LINE::dragSegment45(), KIGFX::GERBVIEW_PAINTER::draw(), DRAWSEGMENT::Draw(), APERTURE_MACRO::DrawApertureMacroShape(), ZONE_CONTAINER::DrawFilledArea(), GERBER_DRAW_ITEM::DrawGbrPoly(), KIGFX::CAIRO_GAL_BASE::drawPoly(), KIGFX::OPENGL_GAL::DrawPolyline(), D_PAD::DrawShape(), PNS::LOGGER::dumpShape(), EdgeContainingPoint(), 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(), D_PAD::FlipPrimitives(), PCB_IO::format(), Format(), PNS::MEANDER_SHAPE::genMeanderShape(), D_PAD::GetBoundingBox(), SHAPE_POLY_SET::GetRelativeIndices(), PNS::LINE_PLACER::handlePullback(), PNS::LINE_PLACER::handleSelfIntersections(), D_PAD::HitTest(), POLYGON_GEOM_MANAGER::IsPolygonInProgress(), DRAWSEGMENT::IsPolyShapeValid(), POLYGON_GEOM_MANAGER::IsSelfIntersecting(), LastPoint(), DSN::SPECCTRA_DB::makePADSTACK(), PNS::OPTIMIZER::mergeObtuse(), D_PAD::MirrorXPrimitives(), NearestPoint(), POLYGON_GEOM_MANAGER::NewPointClosesOutline(), operator!=(), PNS::LINE_PLACER::optimizeTailHeadTransition(), PlotLayerOutlines(), PLOTTER::PlotPoly(), DXF_PLOTTER::PlotPoly(), Point(), SHAPE_SIMPLE::PointCount(), PNS::LINE::PointCount(), PointInside(), Polygon_Calc_BBox_3DU(), polygon_Convert(), PNS::SHOVE::processHullSet(), Remove(), Replace(), PNS::OPTIMIZER::runSmartPads(), KIGFX::PREVIEW::POLYGON_ITEM::SetPoints(), Simplify(), Slice(), PNS_KICAD_IFACE::syncPad(), DXF_PLOTTER::ThickSegment(), ZONE_CONTAINER::TransformSolidAreasShapesToPolygonSet(), POLYGON_GEOM_MANAGER::updateLeaderPoints(), PNS::LINE::Walkaround(), PNS::SHOVE::walkaroundLoneVia(), and GBR_TO_PCB_EXPORTER::writePcbPolygonItem().

◆ PointInside()

bool SHAPE_LINE_CHAIN::PointInside ( const VECTOR2I aPt,
int  aAccuracy = 0 
) const

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
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)

Definition at line 352 of file shape_line_chain.cpp.

353 {
354  BOX2I bbox = BBox();
355  bbox.Inflate( aAccuracy );
356 
357  if( !m_closed || PointCount() < 3 || !BBox().Contains( aPt ) )
358  return false;
359 
360  bool inside = false;
361 
370  for( int i = 0; i < PointCount(); i++ )
371  {
372  const auto p1 = CPoint( i );
373  const auto p2 = CPoint( i + 1 ); // CPoint wraps, so ignore counts
374  const auto diff = p2 - p1;
375 
376  if( diff.y != 0 )
377  {
378  const int d = rescale( diff.x, ( aPt.y - p1.y ), diff.y );
379 
380  if( ( ( p1.y > aPt.y ) != ( p2.y > aPt.y ) ) && ( aPt.x - p1.x < d ) )
381  inside = !inside;
382  }
383  }
384  return inside && !PointOnEdge( aPt, aAccuracy );
385 }
bool PointOnEdge(const VECTOR2I &aP, int aAccuracy=0) const
Function PointOnEdge()
int PointCount() const
Function PointCount()
const VECTOR2I & CPoint(int aIndex) const
Function CPoint()
bool m_closed
is the line chain closed?
const BOX2I BBox(int aClearance=0) const override
Function BBox()
BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Function Inflate inflates the rectangle horizontally by dx and vertically by dy.
Definition: box2.h:300
T rescale(T aNumerator, T aValue, T aDenominator)
Function rescale()
size_t i
Definition: json11.cpp:597

References BBox(), CPoint(), i, BOX2< Vec >::Inflate(), m_closed, PointCount(), PointOnEdge(), numEval::rescale(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by Distance(), MARKER_BASE::HitTestMarker(), SHAPE_POLY_SET::pointInPolygon(), and PNS::LINE::Walkaround().

◆ PointOnEdge()

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

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 388 of file shape_line_chain.cpp.

389 {
390  return EdgeContainingPoint( aPt, aAccuracy ) >= 0;
391 }
int EdgeContainingPoint(const VECTOR2I &aP, int aAccuracy=0) const
Function EdgeContainingPoint()

References EdgeContainingPoint().

Referenced by PNS::SHOVE::checkBumpDirection(), SHAPE_POLY_SET::containsSingle(), and 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 145 of file shape_line_chain.cpp.

146 {
147  if( aEndIndex < 0 )
148  aEndIndex += PointCount();
149 
150  if( aStartIndex < 0 )
151  aStartIndex += PointCount();
152 
153  m_points.erase( m_points.begin() + aStartIndex, m_points.begin() + aEndIndex + 1 );
154 }
int PointCount() const
Function PointCount()
std::vector< VECTOR2I > m_points
array of vertices

References m_points, and PointCount().

Referenced by POLYGON_GEOM_MANAGER::AddPoint(), PNS::LINE_PLACER::buildInitialLine(), PNS::LINE::ClipToNearestObstacle(), POLYGON_GEOM_MANAGER::DeleteLastCorner(), PNS::LINE::dragSegment45(), PNS::DIFF_PAIR_PLACER::FixRoute(), PNS::LINE_PLACER::handlePullback(), PNS::LINE_PLACER::handleSelfIntersections(), PNS::LINE_PLACER::mergeHead(), PNS::LINE_PLACER::reduceTail(), Remove(), 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 457 of file shape_line_chain.h.

458  {
459  Remove( aIndex, aIndex );
460  }
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 114 of file shape_line_chain.cpp.

115 {
116  if( aEndIndex < 0 )
117  aEndIndex += PointCount();
118 
119  if( aStartIndex < 0 )
120  aStartIndex += PointCount();
121 
122  if( aStartIndex == aEndIndex )
123  m_points[aStartIndex] = aP;
124  else
125  {
126  m_points.erase( m_points.begin() + aStartIndex + 1, m_points.begin() + aEndIndex + 1 );
127  m_points[aStartIndex] = aP;
128  }
129 }
int PointCount() const
Function PointCount()
std::vector< VECTOR2I > m_points
array of vertices

References m_points, and PointCount().

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

◆ 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 132 of file shape_line_chain.cpp.

133 {
134  if( aEndIndex < 0 )
135  aEndIndex += PointCount();
136 
137  if( aStartIndex < 0 )
138  aStartIndex += PointCount();
139 
140  m_points.erase( m_points.begin() + aStartIndex, m_points.begin() + aEndIndex + 1 );
141  m_points.insert( m_points.begin() + aStartIndex, aLine.m_points.begin(), aLine.m_points.end() );
142 }
int PointCount() const
Function PointCount()
std::vector< VECTOR2I > m_points
array of vertices

References m_points, and PointCount().

◆ 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 92 of file shape_line_chain.cpp.

93 {
94  SHAPE_LINE_CHAIN a( *this );
95 
96  reverse( a.m_points.begin(), a.m_points.end() );
97  a.m_closed = m_closed;
98 
99  return a;
100 }
bool m_closed
is the line chain closed?
Class SHAPE_LINE_CHAIN.
static void reverse(privcurve_t *curve)
Definition: trace.cpp:1025

References m_closed, m_points, and reverse().

Referenced by PNS::coupledBypass(), PNS::MEANDER_PLACER_BASE::cutTunedLine(), PNS::LINE::dragCorner45(), PNS::DP_GATEWAY::Reverse(), PNS::LINE::Reverse(), PNS::SegmentHull(), and PNS::OPTIMIZER::smartPadsSingle().

◆ Rotate()

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

Function Rotate rotates all vertices by a given angle.

Parameters
aCenteris the rotation center
aAnglerotation angle in radians

Definition at line 58 of file shape_line_chain.cpp.

59 {
60  for( std::vector<VECTOR2I>::iterator i = m_points.begin(); i != m_points.end(); ++i )
61  {
62  (*i) -= aCenter;
63  (*i) = (*i).Rotate( aAngle );
64  (*i) += aCenter;
65  }
66 }
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:370
size_t i
Definition: json11.cpp:597

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

◆ 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 211 of file shape_line_chain.h.

212  {
213  if( aIndex < 0 )
214  aIndex += SegmentCount();
215 
216  if( aIndex == (int)( m_points.size() - 1 ) && m_closed )
217  return SEG( m_points[aIndex], m_points[0], aIndex );
218  else
219  return SEG( m_points[aIndex], m_points[aIndex + 1], aIndex );
220  }
bool m_closed
is the line chain closed?
std::vector< VECTOR2I > m_points
array of vertices
int SegmentCount() const
Function SegmentCount()
Definition: seg.h:36

References m_closed, m_points, and SegmentCount().

Referenced by DRC::doEdgeZoneDrc(), and PNS::WALKAROUND::Route().

◆ 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 183 of file shape_line_chain.h.

184  {
185  int c = m_points.size() - 1;
186  if( m_closed )
187  c++;
188 
189  return std::max( 0, c );
190  }
bool m_closed
is the line chain closed?
std::vector< VECTOR2I > m_points
array of vertices
#define max(a, b)
Definition: auxiliary.h:86

References m_closed, m_points, and max.

Referenced by POLY_GRID_PARTITION::build(), PNS::LINE_PLACER::buildInitialLine(), PNS::LINE_RESTRICTIONS::Check(), CheckClearance(), PNS::NODE::CheckColliding(), PNS::DIFF_PAIR::CheckConnectionAngle(), PNS::checkGap(), PNS::MEANDERED_LINE::CheckSelfIntersections(), Collide(), Collide(), PNS::COST_ESTIMATOR::CornerCost(), PNS::LINE::CountCorners(), PNS::DIFF_PAIR::CoupledLength(), PNS::DIFF_PAIR::CoupledSegmentPairs(), CSegment(), Distance(), PNS::LINE::dragCorner45(), PNS::dragCornerInternal(), PNS::LINE::dragSegment45(), ROUTER_PREVIEW_ITEM::drawLineChain(), KIGFX::OPENGL_GAL::DrawPolygon(), EdgeContainingPoint(), PNS::DIFF_PAIR::Empty(), PNS::findCoupledVertices(), FindSegment(), PNS::LINE_PLACER::FixRoute(), PNS::DIFF_PAIR_PLACER::FixRoute(), PNS::LINE_PLACER::handlePullback(), Intersect(), PNS::LINE::Is45Degree(), Length(), PNS::OPTIMIZER::mergeDpSegments(), PNS::OPTIMIZER::mergeDpStep(), PNS::OPTIMIZER::mergeFull(), PNS::LINE_PLACER::mergeHead(), PNS::OPTIMIZER::mergeObtuse(), PNS::OPTIMIZER::mergeStep(), PNS::NODE::NearestObstacle(), NearestPoint(), PNS::LINE_PLACER::optimizeTailHeadTransition(), PathLength(), PointAlong(), PNS::LINE_PLACER::reduceTail(), PNS::WALKAROUND::Route(), Segment(), PNS::LINE::SegmentCount(), SelfIntersecting(), PNS::OPTIMIZER::smartPadsSingle(), PNS::LINE::snapDraggedCorner(), PNS::LINE::snapToNeighbourSegments(), Split(), and PNS::LINE::Walkaround().

◆ 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 442 of file shape_line_chain.cpp.

443 {
444  for( int s1 = 0; s1 < SegmentCount(); s1++ )
445  {
446  for( int s2 = s1 + 1; s2 < SegmentCount(); s2++ )
447  {
448  const VECTOR2I s2a = CSegment( s2 ).A, s2b = CSegment( s2 ).B;
449 
450  if( s1 + 1 != s2 && CSegment( s1 ).Contains( s2a ) )
451  {
452  INTERSECTION is;
453  is.our = CSegment( s1 );
454  is.their = CSegment( s2 );
455  is.p = s2a;
456  return is;
457  }
458  else if( CSegment( s1 ).Contains( s2b ) &&
459  // for closed polylines, the ending point of the
460  // last segment == starting point of the first segment
461  // this is a normal case, not self intersecting case
462  !( IsClosed() && s1 == 0 && s2 == SegmentCount()-1 ) )
463  {
464  INTERSECTION is;
465  is.our = CSegment( s1 );
466  is.their = CSegment( s2 );
467  is.p = s2b;
468  return is;
469  }
470  else
471  {
472  OPT_VECTOR2I p = CSegment( s1 ).Intersect( CSegment( s2 ), true );
473 
474  if( p )
475  {
476  INTERSECTION is;
477  is.our = CSegment( s1 );
478  is.their = CSegment( s2 );
479  is.p = *p;
480  return is;
481  }
482  }
483  }
484  }
485 
487 }
OPT_VECTOR2I Intersect(const SEG &aSeg, bool aIgnoreEndpoints=false, bool aLines=false) const
Function Intersect()
Definition: seg.cpp:132
OPT< VECTOR2I > OPT_VECTOR2I
Definition: seg.h:34
int SegmentCount() const
Function SegmentCount()
const SEG CSegment(int aIndex) const
Function CSegment()
VECTOR2I A
Definition: seg.h:44
boost::optional< T > OPT
Definition: optional.h:7
bool IsClosed() const
Function IsClosed()
VECTOR2I B
Definition: seg.h:45

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(), DIALOG_PAD_PRIMITIVE_POLY_PROPS::doValidate(), and PNS::SHOVE::processHullSet().

◆ SetClosed()

◆ 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 490 of file shape_line_chain.cpp.

491 {
492  std::vector<VECTOR2I> pts_unique;
493 
494  if( PointCount() < 2 )
495  {
496  return *this;
497  }
498  else if( PointCount() == 2 )
499  {
500  if( m_points[0] == m_points[1] )
501  m_points.pop_back();
502 
503  return *this;
504  }
505 
506  int i = 0;
507  int np = PointCount();
508 
509  // stage 1: eliminate duplicate vertices
510  while( i < np )
511  {
512  int j = i + 1;
513 
514  while( j < np && CPoint( i ) == CPoint( j ) )
515  j++;
516 
517  pts_unique.push_back( CPoint( i ) );
518  i = j;
519  }
520 
521  m_points.clear();
522  np = pts_unique.size();
523 
524  i = 0;
525 
526  // stage 1: eliminate collinear segments
527  while( i < np - 2 )
528  {
529  const VECTOR2I p0 = pts_unique[i];
530  const VECTOR2I p1 = pts_unique[i + 1];
531  int n = i;
532 
533  while( n < np - 2 && SEG( p0, p1 ).LineDistance( pts_unique[n + 2] ) <= 1 )
534  n++;
535 
536  m_points.push_back( p0 );
537 
538  if( n > i )
539  i = n;
540 
541  if( n == np )
542  {
543  m_points.push_back( pts_unique[n - 1] );
544  return *this;
545  }
546 
547  i++;
548  }
549 
550  if( np > 1 )
551  m_points.push_back( pts_unique[np - 2] );
552 
553  m_points.push_back( pts_unique[np - 1] );
554 
555  return *this;
556 }
int PointCount() const
Function PointCount()
const VECTOR2I & CPoint(int aIndex) const
Function CPoint()
std::vector< VECTOR2I > m_points
array of vertices
Definition: seg.h:36
size_t i
Definition: json11.cpp:597

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

Referenced by 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::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 229 of file shape_line_chain.cpp.

230 {
231  SHAPE_LINE_CHAIN rv;
232 
233  if( aEndIndex < 0 )
234  aEndIndex += PointCount();
235 
236  if( aStartIndex < 0 )
237  aStartIndex += PointCount();
238 
239  for( int i = aStartIndex; i <= aEndIndex; i++ )
240  rv.Append( m_points[i] );
241 
242  return rv;
243 }
int PointCount() const
Function PointCount()
void Append(int aX, int aY, bool aAllowDuplication=false)
Function Append()
std::vector< VECTOR2I > m_points
array of vertices
Class SHAPE_LINE_CHAIN.
size_t i
Definition: json11.cpp:597

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

Referenced by PNS::LINE::ClipVertexRange(), PNS::MEANDER_PLACER_BASE::cutTunedLine(), PNS::LINE::dragCorner45(), PNS::dragCornerInternal(), PNS::LINE_PLACER::optimizeTailHeadTransition(), PNS::LINE_PLACER::reduceToNearestObstacle(), 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 171 of file shape_line_chain.cpp.

172 {
173  int ii = -1;
174  int min_dist = 2;
175 
176  int found_index = Find( aP );
177 
178  for( int s = 0; s < SegmentCount(); s++ )
179  {
180  const SEG seg = CSegment( s );
181  int dist = seg.Distance( aP );
182 
183  // make sure we are not producing a 'slightly concave' primitive. This might happen
184  // if aP lies very close to one of already existing points.
185  if( dist < min_dist && seg.A != aP && seg.B != aP )
186  {
187  min_dist = dist;
188  if( found_index < 0 )
189  ii = s;
190  else if( s < found_index )
191  ii = s;
192  }
193  }
194 
195  if( ii < 0 )
196  ii = found_index;
197 
198  if( ii >= 0 )
199  {
200  m_points.insert( m_points.begin() + ii + 1, aP );
201 
202  return ii + 1;
203  }
204 
205  return -1;
206 }
int Find(const VECTOR2I &aP) const
Function Find()
int Distance(const SEG &aSeg) const
Function Distance()
Definition: seg.h:199
static const int dist[10][10]
Definition: ar_matrix.cpp:320
std::vector< VECTOR2I > m_points
array of vertices
int SegmentCount() const
Function SegmentCount()
Definition: seg.h:36
const SEG CSegment(int aIndex) const
Function CSegment()
VECTOR2I A
Definition: seg.h:44
VECTOR2I B
Definition: seg.h:45

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

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

◆ Type()

SHAPE_TYPE SHAPE::Type ( ) const
inlineinherited

Function Type()

Returns the type of the shape.

Return values
thetype

Definition at line 83 of file shape.h.

84  {
85  return m_type;
86  }
SHAPE_TYPE m_type
type of our shape
Definition: shape.h:166

References SHAPE::m_type.

Referenced by PNS::DP_GATEWAYS::BuildFromPrimitivePair(), CollideShapes(), PNS::OPTIMIZER::computeBreakouts(), PNS::LOGGER::dumpShape(), PNS::SOLID::Hull(), ROUTER_PREVIEW_ITEM::ViewDraw(), and SHAPE_FILE_IO::Write().

Member Data Documentation

◆ m_bbox

BOX2I SHAPE_LINE_CHAIN::m_bbox
private

cached bounding box

Definition at line 688 of file shape_line_chain.h.

Referenced by Append().

◆ m_closed

bool SHAPE_LINE_CHAIN::m_closed
private

is the line chain closed?

Definition at line 685 of file shape_line_chain.h.

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

◆ m_points

◆ m_type

SHAPE_TYPE SHAPE::m_type
protectedinherited

type of our shape

Definition at line 166 of file shape.h.

Referenced by SHAPE::Type().


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