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 ()
 
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...
 
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 &aP) const
 Function PointInside() More...
 
bool PointOnEdge (const VECTOR2I &aP) const
 Function PointOnEdge() 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...
 
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 47 of file shape_line_chain.h.

Member Typedef Documentation

typedef VECTOR2I::extended_type SHAPE::ecoord
protectedinherited

Definition at line 61 of file shape.h.

Definition at line 69 of file shape_line_chain.h.

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

Definition at line 51 of file shape_line_chain.h.

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

Definition at line 50 of file shape_line_chain.h.

Constructor & Destructor Documentation

SHAPE_LINE_CHAIN::SHAPE_LINE_CHAIN ( )
inline

Constructor Initializes an empty line chain.

Definition at line 75 of file shape_line_chain.h.

Referenced by Clone().

75  :
76  SHAPE( SH_LINE_CHAIN ), m_closed( false )
77  {}
SHAPE(SHAPE_TYPE aType)
Constructor.
Definition: shape.h:70
bool m_closed
is the line chain closed?
line segment
Definition: shape.h:45
SHAPE_LINE_CHAIN::SHAPE_LINE_CHAIN ( const SHAPE_LINE_CHAIN aShape)
inline

Copy Constructor.

Definition at line 82 of file shape_line_chain.h.

82  :
83  SHAPE( SH_LINE_CHAIN ), m_points( aShape.m_points ), m_closed( aShape.m_closed )
84  {}
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::SHAPE_LINE_CHAIN ( const VECTOR2I aA,
const VECTOR2I aB 
)
inline

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

Definition at line 90 of file shape_line_chain.h.

References m_points.

90  :
91  SHAPE( SH_LINE_CHAIN ), m_closed( false )
92  {
93  m_points.resize( 2 );
94  m_points[0] = aA;
95  m_points[1] = aB;
96  }
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::SHAPE_LINE_CHAIN ( const VECTOR2I aA,
const VECTOR2I aB,
const VECTOR2I aC 
)
inline

Definition at line 98 of file shape_line_chain.h.

References m_points.

98  :
99  SHAPE( SH_LINE_CHAIN ), m_closed( false )
100  {
101  m_points.resize( 3 );
102  m_points[0] = aA;
103  m_points[1] = aB;
104  m_points[2] = aC;
105  }
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::SHAPE_LINE_CHAIN ( const VECTOR2I aA,
const VECTOR2I aB,
const VECTOR2I aC,
const VECTOR2I aD 
)
inline

Definition at line 107 of file shape_line_chain.h.

References m_points.

107  :
108  SHAPE( SH_LINE_CHAIN ), m_closed( false )
109  {
110  m_points.resize( 4 );
111  m_points[0] = aA;
112  m_points[1] = aB;
113  m_points[2] = aC;
114  m_points[3] = aD;
115  }
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::SHAPE_LINE_CHAIN ( const VECTOR2I aV,
int  aCount 
)
inline

Definition at line 118 of file shape_line_chain.h.

References i, and m_points.

118  :
119  SHAPE( SH_LINE_CHAIN ),
120  m_closed( false )
121  {
122  m_points.resize( aCount );
123 
124  for( int i = 0; i < aCount; i++ )
125  m_points[i] = *aV++;
126  }
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
SHAPE_LINE_CHAIN::~SHAPE_LINE_CHAIN ( )
inline

Definition at line 128 of file shape_line_chain.h.

References Clone().

129  {}

Member Function Documentation

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

Referenced by PNS_PCBNEW_DEBUG_DECORATOR::AddBox(), POLYGON_GEOM_MANAGER::AddPoint(), PNS_PCBNEW_DEBUG_DECORATOR::AddPoint(), ZONE_CONTAINER::AddPolygon(), PNS_PCBNEW_DEBUG_DECORATOR::AddSegment(), SHAPE_SIMPLE::Append(), PNS::ApproximateSegmentAsRect(), 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_POLY_SET::convertFromClipper(), SHAPE_ARC::ConvertToPolyline(), PNS::ConvexHull(), PNS::OPTIMIZER::customBreakouts(), PNS::MEANDER_PLACER::doMove(), PNS::LINE::dragCorner45(), PNS::dragCornerInternal(), PNS::LINE::dragSegment45(), ZONE_FILLER::fillZoneWithSegments(), 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(), PNS::WALKAROUND::singleStep(), Slice(), PNS::OPTIMIZER::smartPadsSingle(), PNS::MEANDER_SHAPE::start(), PNS::LINE_PLACER::Trace(), SHAPE_POLY_SET::unfractureSingle(), DIALOG_PAD_PRIMITIVE_POLY_PROPS::Validate(), and PNS::LINE::Walkaround().

347  {
348  VECTOR2I v( aX, aY );
349  Append( v, aAllowDuplication );
350  }
void Append(int aX, int aY, bool aAllowDuplication=false)
Function Append()
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 361 of file shape_line_chain.h.

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

362  {
363  if( m_points.size() == 0 )
364  m_bbox = BOX2I( aP, VECTOR2I( 0, 0 ) );
365 
366  if( m_points.size() == 0 || aAllowDuplication || CPoint( -1 ) != aP )
367  {
368  m_points.push_back( aP );
369  m_bbox.Merge( aP );
370  }
371  }
BOX2I m_bbox
cached bounding box
BOX2< VECTOR2I > BOX2I
Definition: box2.h:468
VECTOR2< int > VECTOR2I
Definition: vector2d.h:589
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:350
const VECTOR2I & CPoint(int aIndex) const
Function CPoint()
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 379 of file shape_line_chain.h.

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

380  {
381  if( aOtherLine.PointCount() == 0 )
382  return;
383 
384  else if( PointCount() == 0 || aOtherLine.CPoint( 0 ) != CPoint( -1 ) )
385  {
386  const VECTOR2I p = aOtherLine.CPoint( 0 );
387  m_points.push_back( p );
388  m_bbox.Merge( p );
389  }
390 
391  for( int i = 1; i < aOtherLine.PointCount(); i++ )
392  {
393  const VECTOR2I p = aOtherLine.CPoint( i );
394  m_points.push_back( p );
395  m_bbox.Merge( p );
396  }
397  }
BOX2I m_bbox
cached bounding box
int PointCount() const
Function PointCount()
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:350
size_t i
Definition: json11.cpp:597
const VECTOR2I & CPoint(int aIndex) const
Function CPoint()
double SHAPE_LINE_CHAIN::Area ( ) const

Definition at line 663 of file shape_line_chain.cpp.

References i, m_closed, and m_points.

Referenced by IsSolid(), polygonArea(), and SHAPE_POLY_SET::unfractureSingle().

664 {
665  // see https://www.mathopenref.com/coordpolygonarea2.html
666 
667  if( !m_closed )
668  return 0.0;
669 
670  double area = 0.0;
671  int size = m_points.size();
672 
673  for( int i = 0, j = size - 1; i < size; ++i )
674  {
675  area += ( (double) m_points[j].x + m_points[i].x ) * ( (double) m_points[j].y - m_points[i].y );
676  j = i;
677  }
678 
679  return -area * 0.5;
680 }
bool m_closed
is the line chain closed?
std::vector< VECTOR2I > m_points
array of vertices
size_t i
Definition: json11.cpp:597
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 280 of file shape_line_chain.h.

References Collide(), BOX2< Vec >::Compute(), Distance(), BOX2< Vec >::Inflate(), Length(), m_points, and Reverse().

Referenced by SHAPE_SIMPLE::BBox(), POLY_GRID_PARTITION::build(), ZONE_FILLER::fillPolygonWithHorizontalSegments(), Intersect(), and PointInside().

281  {
282  BOX2I bbox;
283  bbox.Compute( m_points );
284 
285  if( aClearance != 0 )
286  bbox.Inflate( aClearance );
287 
288  return bbox;
289  }
void Compute(const Container &aPointList)
Compute the bounding box from a given list of points.
Definition: box2.h:79
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:266
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.

References SHAPE::BBox(), BOX2< Vec >::Centre(), SHAPE::Format(), SHAPE::IsSolid(), SHAPE::Move(), and SHAPE::Parse().

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

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

394 {
395  if( !PointCount() )
396  return false;
397 
398  else if( PointCount() == 1 )
399  return m_points[0] == aP;
400 
401  for( int i = 0; i < SegmentCount(); i++ )
402  {
403  const SEG s = CSegment( i );
404 
405  if( s.A == aP || s.B == aP )
406  return true;
407 
408  if( s.Distance( aP ) <= aDist )
409  return true;
410  }
411 
412  return false;
413 }
int PointCount() const
Function PointCount()
const SEG CSegment(int aIndex) const
Function CSegment()
std::vector< VECTOR2I > m_points
array of vertices
Definition: seg.h:36
size_t i
Definition: json11.cpp:597
VECTOR2I A
Definition: seg.h:46
int Distance(const SEG &aSeg) const
Function Distance()
Definition: seg.h:195
int SegmentCount() const
Function SegmentCount()
VECTOR2I B
Definition: seg.h:47
const VECTOR2I& SHAPE_LINE_CHAIN::CLastPoint ( ) const
inline

Returns the last point in the line chain.

Definition at line 274 of file shape_line_chain.h.

References m_points, and PointCount().

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

275  {
276  return m_points[PointCount() - 1];
277  }
int PointCount() const
Function PointCount()
std::vector< VECTOR2I > m_points
array of vertices
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 609 of file shape_line_chain.cpp.

References SHAPE_LINE_CHAIN().

Referenced by ROUTER_PREVIEW_ITEM::Line(), and ~SHAPE_LINE_CHAIN().

610 {
611  return new SHAPE_LINE_CHAIN( *this );
612 }
SHAPE_LINE_CHAIN()
Constructor Initializes an empty line chain.
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 456 of file shape_collisions.cpp.

References CollideShapes().

457 {
458  return CollideShapes( this, aShape, aClerance, true, aMTV );
459 }
bool CollideShapes(const SHAPE *aA, const SHAPE *aB, int aClearance, bool aNeedMTV, VECTOR2I &aMTV)
bool SHAPE::Collide ( const SHAPE aShape,
int  aClearance = 0 
) const
virtualinherited

Definition at line 462 of file shape_collisions.cpp.

References CollideShapes(), and dummy().

463 {
464  VECTOR2I dummy;
465 
466  return CollideShapes( this, aShape, aClerance, false, dummy );
467 }
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)
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 31 of file shape_line_chain.cpp.

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

32 {
33  // fixme: ugly!
34  SEG s( aP, aP );
35  return this->Collide( s, aClearance );
36 }
bool Collide(const VECTOR2I &aP, int aClearance=0) const override
Function Collide()
Definition: seg.h:36
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 50 of file shape_line_chain.cpp.

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

51 {
52  BOX2I box_a( aSeg.A, aSeg.B - aSeg.A );
53  BOX2I::ecoord_type dist_sq = (BOX2I::ecoord_type) aClearance * aClearance;
54 
55  for( int i = 0; i < SegmentCount(); i++ )
56  {
57  const SEG& s = CSegment( i );
58  BOX2I box_b( s.A, s.B - s.A );
59 
60  BOX2I::ecoord_type d = box_a.SquaredDistance( box_b );
61 
62  if( d < dist_sq )
63  {
64  if( s.Collide( aSeg, aClearance ) )
65  return true;
66  }
67  }
68 
69  return false;
70 }
const SEG CSegment(int aIndex) const
Function CSegment()
VECTOR2I::extended_type ecoord_type
Definition: box2.h:49
Definition: seg.h:36
size_t i
Definition: json11.cpp:597
VECTOR2I A
Definition: seg.h:46
bool Collide(const SEG &aSeg, int aClearance) const
Definition: seg.cpp:134
int SegmentCount() const
Function SegmentCount()
VECTOR2I B
Definition: seg.h:47
bool SHAPE_LINE_CHAIN::CompareGeometry ( const SHAPE_LINE_CHAIN aOther) const

Definition at line 586 of file shape_line_chain.cpp.

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

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

587 {
588  SHAPE_LINE_CHAIN a(*this), b( aOther );
589  a.Simplify();
590  b.Simplify();
591 
592  if( a.m_points.size() != b.m_points.size() )
593  return false;
594 
595  for( int i = 0; i < a.PointCount(); i++)
596  if( a.CPoint( i ) != b.CPoint( i ) )
597  return false;
598  return true;
599 }
Class SHAPE_LINE_CHAIN.
size_t i
Definition: json11.cpp:597
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 253 of file shape_line_chain.h.

References m_points, and PointCount().

Referenced by SHAPE_POLY_SET::TRIANGULATION_CONTEXT::AddOutline(), 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(), Convert_shape_line_polygon_to_triangles(), ConvertPolySetToPolyList(), SHAPE_POLY_SET::convertToClipper(), PNS::coupledBypass(), SHAPE_SIMPLE::CPoint(), PNS::LINE::CPoint(), CreatePadsShapesSection(), PNS::dragCornerInternal(), PNS::LINE::dragSegment45(), ZONE_CONTAINER::DrawFilledArea(), KIGFX::CAIRO_GAL::drawPoly(), KIGFX::OPENGL_GAL::DrawPolygon(), KIGFX::OPENGL_GAL::DrawPolyline(), PNS::LOGGER::dumpShape(), export_vrml_board(), export_vrml_polygon(), export_vrml_zones(), ZONE_FILLER::fillPolygonWithHorizontalSegments(), Find(), PNS::LINE_PLACER::FixRoute(), PNS::TOPOLOGY::followTrivialPath(), PCB_IO::format(), FractureEdge::FractureEdge(), PNS::MEANDER_SHAPE::genMeanderShape(), CN_ZONE::GetAnchor(), 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(), PointOnEdge(), 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(), DIALOG_PAD_PRIMITIVE_POLY_PROPS::Validate(), PNS::LINE::Walkaround(), and PNS::SHOVE::walkaroundLoneVia().

254  {
255  if( aIndex < 0 )
256  aIndex += PointCount();
257  else if( aIndex >= PointCount() )
258  aIndex -= PointCount();
259 
260  return m_points[aIndex];
261  }
int PointCount() const
Function PointCount()
std::vector< VECTOR2I > m_points
array of vertices
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 218 of file shape_line_chain.h.

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(), 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(), and SHAPE_POLY_SET::unfractureSingle().

219  {
220  if( aIndex < 0 )
221  aIndex += SegmentCount();
222 
223  if( aIndex == (int)( m_points.size() - 1 ) && m_closed )
224  return SEG( const_cast<VECTOR2I&>( m_points[aIndex] ),
225  const_cast<VECTOR2I&>( m_points[0] ), aIndex );
226  else
227  return SEG( const_cast<VECTOR2I&>( m_points[aIndex] ),
228  const_cast<VECTOR2I&>( m_points[aIndex + 1] ), aIndex );
229  }
bool m_closed
is the line chain closed?
std::vector< VECTOR2I > m_points
array of vertices
Definition: seg.h:36
int SegmentCount() const
Function SegmentCount()
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 138 of file shape_line_chain.cpp.

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

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

139 {
140  int d = INT_MAX;
141 
142  if( IsClosed() && PointInside( aP ) && !aOutlineOnly )
143  return 0;
144 
145  for( int s = 0; s < SegmentCount(); s++ )
146  d = std::min( d, CSegment( s ).Distance( aP ) );
147 
148  return d;
149 }
bool PointInside(const VECTOR2I &aP) const
Function PointInside()
const SEG CSegment(int aIndex) const
Function CSegment()
bool IsClosed() const
Function IsClosed()
int Distance(const SEG &aSeg) const
Function Distance()
Definition: seg.h:195
int SegmentCount() const
Function SegmentCount()
#define min(a, b)
Definition: auxiliary.h:85
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 190 of file shape_line_chain.cpp.

References CPoint(), and PointCount().

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

191 {
192  for( int s = 0; s < PointCount(); s++ )
193  if( CPoint( s ) == aP )
194  return s;
195 
196  return -1;
197 }
int PointCount() const
Function PointCount()
const VECTOR2I & CPoint(int aIndex) const
Function CPoint()
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 200 of file shape_line_chain.cpp.

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

Referenced by PNS::MEANDER_PLACER_BASE::cutTunedLine(), and Remove().

201 {
202  for( int s = 0; s < SegmentCount(); s++ )
203  if( CSegment( s ).Distance( aP ) <= 1 )
204  return s;
205 
206  return -1;
207 }
const SEG CSegment(int aIndex) const
Function CSegment()
int Distance(const SEG &aSeg) const
Function Distance()
Definition: seg.h:195
int SegmentCount() const
Function SegmentCount()
const std::string SHAPE_LINE_CHAIN::Format ( ) const
overridevirtual

Reimplemented from SHAPE.

Definition at line 573 of file shape_line_chain.cpp.

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

574 {
575  std::stringstream ss;
576 
577  ss << m_points.size() << " " << ( m_closed ? 1 : 0 ) << " ";
578 
579  for( int i = 0; i < PointCount(); i++ )
580  ss << m_points[i].x << " " << m_points[i].y << " "; // Format() << " ";
581 
582  return ss.str();
583 }
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
void SHAPE_LINE_CHAIN::Insert ( int  aVertex,
const VECTOR2I aP 
)
inline

Definition at line 399 of file shape_line_chain.h.

References m_points, Remove(), and Replace().

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

400  {
401  m_points.insert( m_points.begin() + aVertex, aP );
402  }
std::vector< VECTOR2I > m_points
array of vertices
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 242 of file shape_line_chain.cpp.

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

243 {
244  for( int s = 0; s < SegmentCount(); s++ )
245  {
246  OPT_VECTOR2I p = CSegment( s ).Intersect( aSeg );
247 
248  if( p )
249  {
250  INTERSECTION is;
251  is.our = CSegment( s );
252  is.their = aSeg;
253  is.p = *p;
254  aIp.push_back( is );
255  }
256  }
257 
258  compareOriginDistance comp( aSeg.A );
259  sort( aIp.begin(), aIp.end(), comp );
260 
261  return aIp.size();
262 }
OPT_VECTOR2I Intersect(const SEG &aSeg, bool aIgnoreEndpoints=false, bool aLines=false) const
Function Intersect()
Definition: seg.cpp:99
const SEG CSegment(int aIndex) const
Function CSegment()
OPT< VECTOR2I > OPT_VECTOR2I
Definition: seg.h:34
VECTOR2I A
Definition: seg.h:46
int SegmentCount() const
Function SegmentCount()
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 265 of file shape_line_chain.cpp.

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.

266 {
267  BOX2I bb_other = aChain.BBox();
268 
269  for( int s1 = 0; s1 < SegmentCount(); s1++ )
270  {
271  const SEG& a = CSegment( s1 );
272  const BOX2I bb_cur( a.A, a.B - a.A );
273 
274  if( !bb_other.Intersects( bb_cur ) )
275  continue;
276 
277  for( int s2 = 0; s2 < aChain.SegmentCount(); s2++ )
278  {
279  const SEG& b = aChain.CSegment( s2 );
280  INTERSECTION is;
281 
282  if( a.Collinear( b ) )
283  {
284  is.our = a;
285  is.their = b;
286 
287  if( a.Contains( b.A ) ) { is.p = b.A; aIp.push_back( is ); }
288  if( a.Contains( b.B ) ) { is.p = b.B; aIp.push_back( is ); }
289  if( b.Contains( a.A ) ) { is.p = a.A; aIp.push_back( is ); }
290  if( b.Contains( a.B ) ) { is.p = a.B; aIp.push_back( is ); }
291  }
292  else
293  {
294  OPT_VECTOR2I p = a.Intersect( b );
295 
296  if( p )
297  {
298  is.p = *p;
299  is.our = a;
300  is.their = b;
301  aIp.push_back( is );
302  }
303  }
304  }
305  }
306 
307  return aIp.size();
308 }
OPT_VECTOR2I Intersect(const SEG &aSeg, bool aIgnoreEndpoints=false, bool aLines=false) const
Function Intersect()
Definition: seg.cpp:99
const SEG CSegment(int aIndex) const
Function CSegment()
const BOX2I BBox(int aClearance=0) const override
Function BBox()
OPT< VECTOR2I > OPT_VECTOR2I
Definition: seg.h:34
bool Intersects(const BOX2< Vec > &aRect) const
Function Intersects.
Definition: box2.h:224
Definition: seg.h:36
VECTOR2I A
Definition: seg.h:46
bool Collinear(const SEG &aSeg) const
Function Collinear()
Definition: seg.h:231
bool Contains(const VECTOR2I &aP) const
Definition: seg.cpp:155
int SegmentCount() const
Function SegmentCount()
VECTOR2I B
Definition: seg.h:47
bool SHAPE_LINE_CHAIN::Intersects ( const SHAPE_LINE_CHAIN aChain) const

Definition at line 602 of file shape_line_chain.cpp.

References dummy(), and Intersect().

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

603 {
605  return Intersect( aChain, dummy ) != 0;
606 }
std::vector< INTERSECTION > INTERSECTIONS
int Intersect(const SEG &aSeg, INTERSECTIONS &aIp) const
Function Intersect()
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 SHAPE_LINE_CHAIN::IsClosed ( ) const
inline

Function IsClosed()

Returns
aClosed: true, when our line is closed.

Definition at line 160 of file shape_line_chain.h.

References m_closed.

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

161  {
162  return m_closed;
163  }
bool m_closed
is the line chain closed?
bool SHAPE_LINE_CHAIN::IsSolid ( ) const
inlineoverridevirtual

Implements SHAPE.

Definition at line 632 of file shape_line_chain.h.

References Area(), and PointAlong().

633  {
634  return false;
635  }
VECTOR2I& SHAPE_LINE_CHAIN::LastPoint ( )
inline

Returns the last point in the line chain.

Definition at line 266 of file shape_line_chain.h.

References m_points, and PointCount().

267  {
268  return m_points[PointCount() - 1];
269  }
int PointCount() const
Function PointCount()
std::vector< VECTOR2I > m_points
array of vertices
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 84 of file shape_line_chain.cpp.

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

Referenced by PNS::COST_ESTIMATOR::Add(), BBox(), 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::rhStopAtNearestObstacle(), PNS::WALKAROUND::Route(), PNS::WALKAROUND::singleStep(), and PNS::SHOVE::walkaroundLoneVia().

85 {
86  int l = 0;
87 
88  for( int i = 0; i < SegmentCount(); i++ )
89  l += CSegment( i ).Length();
90 
91  return l;
92 }
int Length() const
Function Length()
Definition: seg.h:292
const SEG CSegment(int aIndex) const
Function CSegment()
size_t i
Definition: json11.cpp:597
int SegmentCount() const
Function SegmentCount()
void SHAPE_LINE_CHAIN::Move ( const VECTOR2I aVector)
inlineoverridevirtual

Implements SHAPE.

Definition at line 618 of file shape_line_chain.h.

References i, m_points, and Rotate().

Referenced by SHAPE_SIMPLE::Move().

619  {
620  for( std::vector<VECTOR2I>::iterator i = m_points.begin(); i != m_points.end(); ++i )
621  (*i) += aVector;
622  }
std::vector< VECTOR2I > m_points
array of vertices
size_t i
Definition: json11.cpp:597
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 533 of file shape_line_chain.cpp.

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

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

534 {
535  int min_d = INT_MAX;
536  int nearest = 0;
537 
538  for( int i = 0; i < SegmentCount(); i++ )
539  {
540  int d = CSegment( i ).Distance( aP );
541 
542  if( d < min_d )
543  {
544  min_d = d;
545  nearest = i;
546  }
547  }
548 
549  return CSegment( nearest ).NearestPoint( aP );
550 }
const SEG CSegment(int aIndex) const
Function CSegment()
const VECTOR2I NearestPoint(const VECTOR2I &aP) const
Function NearestPoint()
Definition: seg.h:370
size_t i
Definition: json11.cpp:597
int Distance(const SEG &aSeg) const
Function Distance()
Definition: seg.h:195
int SegmentCount() const
Function SegmentCount()
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 553 of file shape_line_chain.cpp.

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

554 {
555  int nearest = 0;
556 
557  dist = INT_MAX;
558  for( int i = 0; i < PointCount(); i++ )
559  {
560  int d = aSeg.LineDistance( CPoint( i ) );
561 
562  if( d < dist )
563  {
564  dist = d;
565  nearest = i;
566  }
567  }
568 
569  return CPoint( nearest );
570 }
int PointCount() const
Function PointCount()
static const int dist[10][10]
Definition: dist.cpp:57
int LineDistance(const VECTOR2I &aP, bool aDetermineSide=false) const
Function LineDistance()
Definition: seg.h:353
size_t i
Definition: json11.cpp:597
const VECTOR2I & CPoint(int aIndex) const
Function CPoint()
bool SHAPE_LINE_CHAIN::operator!= ( const SHAPE_LINE_CHAIN aRhs) const
inline

Definition at line 602 of file shape_line_chain.h.

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

603  {
604  if( PointCount() != aRhs.PointCount() )
605  return true;
606 
607  for( int i = 0; i < PointCount(); i++ )
608  {
609  if( CPoint( i ) != aRhs.CPoint( i ) )
610  return true;
611  }
612 
613  return false;
614  }
int PointCount() const
Function PointCount()
size_t i
Definition: json11.cpp:597
const VECTOR2I & CPoint(int aIndex) const
Function CPoint()
bool SHAPE_LINE_CHAIN::Parse ( std::stringstream &  aStream)
overridevirtual

Reimplemented from SHAPE.

Definition at line 614 of file shape_line_chain.cpp.

References i, m_closed, and m_points.

615 {
616  int n_pts;
617 
618  m_points.clear();
619  aStream >> n_pts;
620 
621  // Rough sanity check, just make sure the loop bounds aren't absolutely outlandish
622  if( n_pts < 0 || n_pts > int( aStream.str().size() ) )
623  return false;
624 
625  aStream >> m_closed;
626 
627  for( int i = 0; i < n_pts; i++ )
628  {
629  int x, y;
630  aStream >> x;
631  aStream >> y;
632  m_points.push_back( VECTOR2I( x, y ) );
633  }
634 
635  return true;
636 }
VECTOR2< int > VECTOR2I
Definition: vector2d.h:589
bool m_closed
is the line chain closed?
std::vector< VECTOR2I > m_points
array of vertices
size_t i
Definition: json11.cpp:597
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 311 of file shape_line_chain.cpp.

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

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

312 {
313  int sum = 0;
314 
315  for( int i = 0; i < SegmentCount(); i++ )
316  {
317  const SEG seg = CSegment( i );
318  int d = seg.Distance( aP );
319 
320  if( d <= 1 )
321  {
322  sum += ( aP - seg.A ).EuclideanNorm();
323  return sum;
324  }
325  else
326  sum += seg.Length();
327  }
328 
329  return -1;
330 }
double EuclideanNorm(const wxPoint &vector)
Euclidean norm of a 2D vector.
Definition: trigo.h:112
int Length() const
Function Length()
Definition: seg.h:292
const SEG CSegment(int aIndex) const
Function CSegment()
Definition: seg.h:36
size_t i
Definition: json11.cpp:597
VECTOR2I A
Definition: seg.h:46
int Distance(const SEG &aSeg) const
Function Distance()
Definition: seg.h:195
int SegmentCount() const
Function SegmentCount()
VECTOR2I& SHAPE_LINE_CHAIN::Point ( int  aIndex)
inline
const VECTOR2I SHAPE_LINE_CHAIN::PointAlong ( int  aPathLength) const

Definition at line 639 of file shape_line_chain.cpp.

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

Referenced by IsSolid().

640 {
641  int total = 0;
642 
643  if( aPathLength == 0 )
644  return CPoint( 0 );
645 
646  for( int i = 0; i < SegmentCount(); i++ )
647  {
648  const SEG& s = CSegment( i );
649  int l = s.Length();
650 
651  if( total + l >= aPathLength )
652  {
653  VECTOR2I d( s.B - s.A );
654  return s.A + d.Resize( aPathLength - total );
655  }
656 
657  total += l;
658  }
659 
660  return CPoint( -1 );
661 }
VECTOR2< T > Resize(T aNewLength) const
Function Resize returns a vector of the same direction, but length specified in aNewLength.
Definition: vector2d.h:387
int Length() const
Function Length()
Definition: seg.h:292
const SEG CSegment(int aIndex) const
Function CSegment()
Definition: seg.h:36
size_t i
Definition: json11.cpp:597
VECTOR2I A
Definition: seg.h:46
const VECTOR2I & CPoint(int aIndex) const
Function CPoint()
int SegmentCount() const
Function SegmentCount()
VECTOR2I B
Definition: seg.h:47
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 186 of file shape_line_chain.h.

References m_points.

Referenced by SHAPE_POLY_SET::TRIANGULATION_CONTEXT::AddOutline(), POLYGON_GEOM_MANAGER::AddPoint(), CINFO3D_VISU::AddSolidAreasShapesToContainer(), CLAYER_TRIANGLES::AddToMiddleContourns(), CN_ZONE::AnchorCount(), 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(), Convert_shape_line_polygon_to_triangles(), ConvertPolySetToPolyList(), SHAPE_POLY_SET::convertToClipper(), PNS::coupledBypass(), CPoint(), CreatePadsShapesSection(), D_PAD::CustomShapeAsPolygonToBoardPosition(), POLYGON_GEOM_MANAGER::DeleteLastCorner(), PNS::LINE::dragSegment45(), DRAWSEGMENT::Draw(), APERTURE_MACRO::DrawApertureMacroShape(), ZONE_CONTAINER::DrawFilledArea(), GERBER_DRAW_ITEM::DrawGbrPoly(), KIGFX::CAIRO_GAL::drawPoly(), KIGFX::OPENGL_GAL::DrawPolyline(), D_PAD::DrawShape(), PNS::LOGGER::dumpShape(), export_vrml_board(), export_vrml_padshape(), export_vrml_polygon(), export_vrml_zones(), DSN::SPECCTRA_DB::fillBOUNDARY(), ZONE_FILLER::fillPolygonWithHorizontalSegments(), ZONE_FILLER::fillZoneWithSegments(), 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(), DRAWING_TOOL::make45DegLine(), DSN::SPECCTRA_DB::makePADSTACK(), PNS::OPTIMIZER::mergeObtuse(), NearestPoint(), POLYGON_GEOM_MANAGER::NewPointClosesOutline(), operator!=(), PNS::LINE_PLACER::optimizeTailHeadTransition(), PlotLayerOutlines(), PLOTTER::PlotPoly(), DXF_PLOTTER::PlotPoly(), Point(), SHAPE_SIMPLE::PointCount(), PNS::LINE::PointCount(), PointInside(), PointOnEdge(), 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(), DIALOG_PAD_PRIMITIVE_POLY_PROPS::Validate(), PNS::LINE::Walkaround(), PNS::SHOVE::walkaroundLoneVia(), and GBR_TO_PCB_EXPORTER::writePcbPolygonItem().

187  {
188  return m_points.size();
189  }
std::vector< VECTOR2I > m_points
array of vertices
bool SHAPE_LINE_CHAIN::PointInside ( const VECTOR2I aP) const

Function PointInside()

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

Parameters
aPpoint 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 333 of file shape_line_chain.cpp.

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

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

334 {
335  if( !m_closed || PointCount() < 3 || !BBox().Contains( aP ) )
336  return false;
337 
338  bool inside = false;
339 
348  for( int i = 0; i < PointCount(); i++ )
349  {
350  const VECTOR2D p1 = CPoint( i );
351  const VECTOR2D p2 = CPoint( i + 1 ); // CPoint wraps, so ignore counts
352  const VECTOR2D diff = p2 - p1;
353 
354  if( ( ( p1.y > aP.y ) != ( p2.y > aP.y ) ) &&
355  ( aP.x - p1.x < ( diff.x / diff.y ) * ( aP.y - p1.y ) ) )
356  inside = !inside;
357  }
358 
359  return inside;
360 }
int PointCount() const
Function PointCount()
bool m_closed
is the line chain closed?
const BOX2I BBox(int aClearance=0) const override
Function BBox()
size_t i
Definition: json11.cpp:597
const VECTOR2I & CPoint(int aIndex) const
Function CPoint()
bool SHAPE_LINE_CHAIN::PointOnEdge ( const VECTOR2I aP) 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 363 of file shape_line_chain.cpp.

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

Referenced by PNS::SHOVE::checkBumpDirection(), and SHAPE_POLY_SET::containsSingle().

364 {
365  if( !PointCount() )
366  return false;
367  else if( PointCount() == 1 )
368  return m_points[0] == aP;
369 
370  for( int i = 0; i < PointCount(); i++ )
371  {
372  const VECTOR2I& p1 = CPoint( i );
373  const VECTOR2I& p2 = CPoint( i + 1 );
374 
375  if( aP == p1 )
376  return true;
377 
378  if( p1.x == p2.x && p1.x == aP.x && ( p1.y > aP.y ) != ( p2.y > aP.y ) )
379  return true;
380 
381  const VECTOR2D diff = p2 - p1;
382  if( aP.x >= p1.x && aP.x <= p2.x )
383  {
384  if( KiROUND( p1.y + ( diff.y / diff.x ) * ( aP.x - p1.x ) ) == aP.y )
385  return true;
386  }
387  }
388 
389  return false;
390 }
static int KiROUND(double v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: common.h:106
int PointCount() const
Function PointCount()
std::vector< VECTOR2I > m_points
array of vertices
size_t i
Definition: json11.cpp:597
const VECTOR2I & CPoint(int aIndex) const
Function CPoint()
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 126 of file shape_line_chain.cpp.

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(), Insert(), PNS::LINE_PLACER::mergeHead(), PNS::LINE_PLACER::reduceTail(), Remove(), and PNS::WALKAROUND::Route().

127 {
128  if( aEndIndex < 0 )
129  aEndIndex += PointCount();
130 
131  if( aStartIndex < 0 )
132  aStartIndex += PointCount();
133 
134  m_points.erase( m_points.begin() + aStartIndex, m_points.begin() + aEndIndex + 1 );
135 }
int PointCount() const
Function PointCount()
std::vector< VECTOR2I > m_points
array of vertices
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 440 of file shape_line_chain.h.

References Find(), FindSegment(), Remove(), Slice(), and Split().

441  {
442  Remove( aIndex, aIndex );
443  }
void Remove(int aStartIndex, int aEndIndex)
Function Remove()
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 95 of file shape_line_chain.cpp.

References m_points, and PointCount().

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

96 {
97  if( aEndIndex < 0 )
98  aEndIndex += PointCount();
99 
100  if( aStartIndex < 0 )
101  aStartIndex += PointCount();
102 
103  if( aStartIndex == aEndIndex )
104  m_points[aStartIndex] = aP;
105  else
106  {
107  m_points.erase( m_points.begin() + aStartIndex + 1, m_points.begin() + aEndIndex + 1 );
108  m_points[aStartIndex] = aP;
109  }
110 }
int PointCount() const
Function PointCount()
std::vector< VECTOR2I > m_points
array of vertices
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 113 of file shape_line_chain.cpp.

References m_points, and PointCount().

114 {
115  if( aEndIndex < 0 )
116  aEndIndex += PointCount();
117 
118  if( aStartIndex < 0 )
119  aStartIndex += PointCount();
120 
121  m_points.erase( m_points.begin() + aStartIndex, m_points.begin() + aEndIndex + 1 );
122  m_points.insert( m_points.begin() + aStartIndex, aLine.m_points.begin(), aLine.m_points.end() );
123 }
int PointCount() const
Function PointCount()
std::vector< VECTOR2I > m_points
array of vertices
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 73 of file shape_line_chain.cpp.

References m_closed, m_points, and reverse().

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

74 {
75  SHAPE_LINE_CHAIN a( *this );
76 
77  reverse( a.m_points.begin(), a.m_points.end() );
78  a.m_closed = m_closed;
79 
80  return a;
81 }
bool m_closed
is the line chain closed?
Class SHAPE_LINE_CHAIN.
static void reverse(privcurve_t *curve)
Definition: trace.cpp:1025
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 39 of file shape_line_chain.cpp.

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

Referenced by Move().

40 {
41  for( std::vector<VECTOR2I>::iterator i = m_points.begin(); i != m_points.end(); ++i )
42  {
43  (*i) -= aCenter;
44  (*i) = (*i).Rotate( aAngle );
45  (*i) += aCenter;
46  }
47 }
VECTOR2< T > Rotate(double aAngle) const
Function Rotate rotates the vector by a given angle.
Definition: vector2d.h:372
std::vector< VECTOR2I > m_points
array of vertices
size_t i
Definition: json11.cpp:597
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 199 of file shape_line_chain.h.

References m_closed, m_points, and SegmentCount().

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

200  {
201  if( aIndex < 0 )
202  aIndex += SegmentCount();
203 
204  if( aIndex == (int)( m_points.size() - 1 ) && m_closed )
205  return SEG( m_points[aIndex], m_points[0], aIndex );
206  else
207  return SEG( m_points[aIndex], m_points[aIndex + 1], aIndex );
208  }
bool m_closed
is the line chain closed?
std::vector< VECTOR2I > m_points
array of vertices
Definition: seg.h:36
int SegmentCount() const
Function 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 171 of file shape_line_chain.h.

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(), 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().

172  {
173  int c = m_points.size() - 1;
174  if( m_closed )
175  c++;
176 
177  return std::max( 0, c );
178  }
bool m_closed
is the line chain closed?
std::vector< VECTOR2I > m_points
array of vertices
#define max(a, b)
Definition: auxiliary.h:86
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 416 of file shape_line_chain.cpp.

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

417 {
418  for( int s1 = 0; s1 < SegmentCount(); s1++ )
419  {
420  for( int s2 = s1 + 1; s2 < SegmentCount(); s2++ )
421  {
422  const VECTOR2I s2a = CSegment( s2 ).A, s2b = CSegment( s2 ).B;
423 
424  if( s1 + 1 != s2 && CSegment( s1 ).Contains( s2a ) )
425  {
426  INTERSECTION is;
427  is.our = CSegment( s1 );
428  is.their = CSegment( s2 );
429  is.p = s2a;
430  return is;
431  }
432  else if( CSegment( s1 ).Contains( s2b ) &&
433  // for closed polylines, the ending point of the
434  // last segment == starting point of the first segment
435  // this is a normal case, not self intersecting case
436  !( IsClosed() && s1 == 0 && s2 == SegmentCount()-1 ) )
437  {
438  INTERSECTION is;
439  is.our = CSegment( s1 );
440  is.their = CSegment( s2 );
441  is.p = s2b;
442  return is;
443  }
444  else
445  {
446  OPT_VECTOR2I p = CSegment( s1 ).Intersect( CSegment( s2 ), true );
447 
448  if( p )
449  {
450  INTERSECTION is;
451  is.our = CSegment( s1 );
452  is.their = CSegment( s2 );
453  is.p = *p;
454  return is;
455  }
456  }
457  }
458  }
459 
461 }
OPT_VECTOR2I Intersect(const SEG &aSeg, bool aIgnoreEndpoints=false, bool aLines=false) const
Function Intersect()
Definition: seg.cpp:99
const SEG CSegment(int aIndex) const
Function CSegment()
OPT< VECTOR2I > OPT_VECTOR2I
Definition: seg.h:34
VECTOR2I A
Definition: seg.h:46
boost::optional< T > OPT
Definition: optional.h:7
bool IsClosed() const
Function IsClosed()
int SegmentCount() const
Function SegmentCount()
VECTOR2I B
Definition: seg.h:47
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 464 of file shape_line_chain.cpp.

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(), 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::WALKAROUND::singleStep(), PNS::OPTIMIZER::smartPadsSingle(), PNS::LINE_PLACER::Trace(), DIALOG_PAD_PRIMITIVE_POLY_PROPS::Validate(), and PNS::LINE::Walkaround().

465 {
466  std::vector<VECTOR2I> pts_unique;
467 
468  if( PointCount() < 2 )
469  {
470  return *this;
471  }
472  else if( PointCount() == 2 )
473  {
474  if( m_points[0] == m_points[1] )
475  m_points.pop_back();
476 
477  return *this;
478  }
479 
480  int i = 0;
481  int np = PointCount();
482 
483  // stage 1: eliminate duplicate vertices
484  while( i < np )
485  {
486  int j = i + 1;
487 
488  while( j < np && CPoint( i ) == CPoint( j ) )
489  j++;
490 
491  pts_unique.push_back( CPoint( i ) );
492  i = j;
493  }
494 
495  m_points.clear();
496  np = pts_unique.size();
497 
498  i = 0;
499 
500  // stage 1: eliminate collinear segments
501  while( i < np - 2 )
502  {
503  const VECTOR2I p0 = pts_unique[i];
504  const VECTOR2I p1 = pts_unique[i + 1];
505  int n = i;
506 
507  while( n < np - 2 && SEG( p0, p1 ).LineDistance( pts_unique[n + 2] ) <= 1 )
508  n++;
509 
510  m_points.push_back( p0 );
511 
512  if( n > i )
513  i = n;
514 
515  if( n == np )
516  {
517  m_points.push_back( pts_unique[n - 1] );
518  return *this;
519  }
520 
521  i++;
522  }
523 
524  if( np > 1 )
525  m_points.push_back( pts_unique[np - 2] );
526 
527  m_points.push_back( pts_unique[np - 1] );
528 
529  return *this;
530 }
int PointCount() const
Function PointCount()
std::vector< VECTOR2I > m_points
array of vertices
Definition: seg.h:36
size_t i
Definition: json11.cpp:597
const VECTOR2I & CPoint(int aIndex) const
Function CPoint()
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 210 of file shape_line_chain.cpp.

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(), Remove(), and PNS::LINE::Walkaround().

211 {
212  SHAPE_LINE_CHAIN rv;
213 
214  if( aEndIndex < 0 )
215  aEndIndex += PointCount();
216 
217  if( aStartIndex < 0 )
218  aStartIndex += PointCount();
219 
220  for( int i = aStartIndex; i <= aEndIndex; i++ )
221  rv.Append( m_points[i] );
222 
223  return rv;
224 }
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
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 152 of file shape_line_chain.cpp.

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(), Remove(), and PNS::LINE::Walkaround().

153 {
154  int ii = -1;
155  int min_dist = 2;
156 
157  int found_index = Find( aP );
158 
159  for( int s = 0; s < SegmentCount(); s++ )
160  {
161  const SEG seg = CSegment( s );
162  int dist = seg.Distance( aP );
163 
164  // make sure we are not producing a 'slightly concave' primitive. This might happen
165  // if aP lies very close to one of already existing points.
166  if( dist < min_dist && seg.A != aP && seg.B != aP )
167  {
168  min_dist = dist;
169  if( found_index < 0 )
170  ii = s;
171  else if( s < found_index )
172  ii = s;
173  }
174  }
175 
176  if( ii < 0 )
177  ii = found_index;
178 
179  if( ii >= 0 )
180  {
181  m_points.insert( m_points.begin() + ii + 1, aP );
182 
183  return ii + 1;
184  }
185 
186  return -1;
187 }
static const int dist[10][10]
Definition: dist.cpp:57
const SEG CSegment(int aIndex) const
Function CSegment()
int Find(const VECTOR2I &aP) const
Function Find()
std::vector< VECTOR2I > m_points
array of vertices
Definition: seg.h:36
VECTOR2I A
Definition: seg.h:46
int Distance(const SEG &aSeg) const
Function Distance()
Definition: seg.h:195
int SegmentCount() const
Function SegmentCount()
VECTOR2I B
Definition: seg.h:47
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.

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

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

Member Data Documentation

BOX2I SHAPE_LINE_CHAIN::m_bbox
private

cached bounding box

Definition at line 649 of file shape_line_chain.h.

Referenced by Append().

bool SHAPE_LINE_CHAIN::m_closed
private

is the line chain closed?

Definition at line 646 of file shape_line_chain.h.

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

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: