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

Referenced by PNS_PCBNEW_DEBUG_DECORATOR::AddBox(), PNS_PCBNEW_DEBUG_DECORATOR::AddPoint(), ZONE_CONTAINER::AddPolygon(), PNS_PCBNEW_DEBUG_DECORATOR::AddSegment(), SHAPE_CONVEX::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::OPTIMIZER::convexBreakouts(), PNS::ConvexHull(), 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(), KIGFX::PREVIEW::POLYGON_ITEM::SetPoints(), 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().

331  {
332  VECTOR2I v( aX, aY );
333  Append( v, aAllowDuplication );
334  }
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 345 of file shape_line_chain.h.

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

346  {
347  if( m_points.size() == 0 )
348  m_bbox = BOX2I( aP, VECTOR2I( 0, 0 ) );
349 
350  if( m_points.size() == 0 || aAllowDuplication || CPoint( -1 ) != aP )
351  {
352  m_points.push_back( aP );
353  m_bbox.Merge( aP );
354  }
355  }
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 363 of file shape_line_chain.h.

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

364  {
365  if( aOtherLine.PointCount() == 0 )
366  return;
367 
368  else if( PointCount() == 0 || aOtherLine.CPoint( 0 ) != CPoint( -1 ) )
369  {
370  const VECTOR2I p = aOtherLine.CPoint( 0 );
371  m_points.push_back( p );
372  m_bbox.Merge( p );
373  }
374 
375  for( int i = 1; i < aOtherLine.PointCount(); i++ )
376  {
377  const VECTOR2I p = aOtherLine.CPoint( i );
378  m_points.push_back( p );
379  m_bbox.Merge( p );
380  }
381  }
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
const VECTOR2I & CPoint(int aIndex) const
Function CPoint()
double SHAPE_LINE_CHAIN::Area ( ) const

Definition at line 627 of file shape_line_chain.cpp.

References m_closed, and m_points.

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

628 {
629  // see https://www.mathopenref.com/coordpolygonarea2.html
630 
631  if( !m_closed )
632  return 0.0;
633 
634  double area = 0.0;
635  int size = m_points.size();
636 
637  for( int i = 0, j = size - 1; i < size; ++i )
638  {
639  area += ( (double) m_points[j].x + m_points[i].x ) * ( (double) m_points[j].y - m_points[i].y );
640  j = i;
641  }
642 
643  return -area * 0.5;
644 }
bool m_closed
is the line chain closed?
std::vector< VECTOR2I > m_points
array of vertices
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 264 of file shape_line_chain.h.

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

Referenced by SHAPE_CONVEX::BBox(), POLY_GRID_PARTITION::build(), ZONE_FILLER::fillPolygonWithHorizontalSegments(), Intersect(), and SHAPE_POLY_SET::pointInPolygon().

265  {
266  BOX2I bbox;
267  bbox.Compute( m_points );
268 
269  if( aClearance != 0 )
270  bbox.Inflate( aClearance );
271 
272  return bbox;
273  }
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
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 573 of file shape_line_chain.cpp.

References SHAPE_LINE_CHAIN().

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

574 {
575  return new SHAPE_LINE_CHAIN( *this );
576 }
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 30 of file shape_line_chain.cpp.

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

31 {
32  // fixme: ugly!
33  SEG s( aP, aP );
34  return this->Collide( s, aClearance );
35 }
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 49 of file shape_line_chain.cpp.

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

50 {
51  BOX2I box_a( aSeg.A, aSeg.B - aSeg.A );
52  BOX2I::ecoord_type dist_sq = (BOX2I::ecoord_type) aClearance * aClearance;
53 
54  for( int i = 0; i < SegmentCount(); i++ )
55  {
56  const SEG& s = CSegment( i );
57  BOX2I box_b( s.A, s.B - s.A );
58 
59  BOX2I::ecoord_type d = box_a.SquaredDistance( box_b );
60 
61  if( d < dist_sq )
62  {
63  if( s.Collide( aSeg, aClearance ) )
64  return true;
65  }
66  }
67 
68  return false;
69 }
const SEG CSegment(int aIndex) const
Function CSegment()
VECTOR2I::extended_type ecoord_type
Definition: box2.h:49
Definition: seg.h:36
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 550 of file shape_line_chain.cpp.

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

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

551 {
552  SHAPE_LINE_CHAIN a(*this), b( aOther );
553  a.Simplify();
554  b.Simplify();
555 
556  if( a.m_points.size() != b.m_points.size() )
557  return false;
558 
559  for( int i = 0; i < a.PointCount(); i++)
560  if( a.CPoint( i ) != b.CPoint( i ) )
561  return false;
562  return true;
563 }
Class SHAPE_LINE_CHAIN.
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(), 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_CONVEX::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_drawsegment(), export_vrml_edge_module(), 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(), DSN::SPECCTRA_DB::makePADSTACK(), PNS::LINE_PLACER::mergeHead(), PNS::MEANDER_SHAPE::miter(), PNS::LINE_PLACER::Move(), NearestPoint(), operator!=(), PNS::LINE_PLACER::optimizeTailHeadTransition(), PlotLayerOutlines(), PLOTTER::PlotPoly(), DXF_PLOTTER::PlotPoly(), PointAlong(), SHAPE_POLY_SET::pointInPolygon(), Polygon_Calc_BBox_3DU(), polygon_Convert(), PNS::SHOVE::processHullSet(), PNS::LINE_PLACER::removeLoops(), PNS::DIFF_PAIR_PLACER::routeHead(), PNS::OPTIMIZER::runSmartPads(), 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(), 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(), PointInside(), PointOnEdge(), 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 137 of file shape_line_chain.cpp.

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

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

138 {
139  int d = INT_MAX;
140 
141  if( IsClosed() && PointInside( aP ) && !aOutlineOnly )
142  return 0;
143 
144  for( int s = 0; s < SegmentCount(); s++ )
145  d = std::min( d, CSegment( s ).Distance( aP ) );
146 
147  return d;
148 }
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 189 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().

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

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

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

200 {
201  for( int s = 0; s < SegmentCount(); s++ )
202  if( CSegment( s ).Distance( aP ) <= 1 )
203  return s;
204 
205  return -1;
206 }
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 537 of file shape_line_chain.cpp.

References m_closed, m_points, and PointCount().

538 {
539  std::stringstream ss;
540 
541  ss << m_points.size() << " " << ( m_closed ? 1 : 0 ) << " ";
542 
543  for( int i = 0; i < PointCount(); i++ )
544  ss << m_points[i].x << " " << m_points[i].y << " "; // Format() << " ";
545 
546  return ss.str();
547 }
int PointCount() const
Function PointCount()
bool m_closed
is the line chain closed?
std::vector< VECTOR2I > m_points
array of vertices
void SHAPE_LINE_CHAIN::Insert ( int  aVertex,
const VECTOR2I aP 
)
inline

Definition at line 383 of file shape_line_chain.h.

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

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

384  {
385  m_points.insert( m_points.begin() + aVertex, aP );
386  }
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 241 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::convexBreakouts(), PNS::LINE_PLACER::handleSelfIntersections(), Intersects(), PNS::NODE::NearestObstacle(), and PNS::LINE::Walkaround().

242 {
243  for( int s = 0; s < SegmentCount(); s++ )
244  {
245  OPT_VECTOR2I p = CSegment( s ).Intersect( aSeg );
246 
247  if( p )
248  {
249  INTERSECTION is;
250  is.our = CSegment( s );
251  is.their = aSeg;
252  is.p = *p;
253  aIp.push_back( is );
254  }
255  }
256 
257  compareOriginDistance comp( aSeg.A );
258  sort( aIp.begin(), aIp.end(), comp );
259 
260  return aIp.size();
261 }
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 264 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.

265 {
266  BOX2I bb_other = aChain.BBox();
267 
268  for( int s1 = 0; s1 < SegmentCount(); s1++ )
269  {
270  const SEG& a = CSegment( s1 );
271  const BOX2I bb_cur( a.A, a.B - a.A );
272 
273  if( !bb_other.Intersects( bb_cur ) )
274  continue;
275 
276  for( int s2 = 0; s2 < aChain.SegmentCount(); s2++ )
277  {
278  const SEG& b = aChain.CSegment( s2 );
279  INTERSECTION is;
280 
281  if( a.Collinear( b ) )
282  {
283  is.our = a;
284  is.their = b;
285 
286  if( a.Contains( b.A ) ) { is.p = b.A; aIp.push_back( is ); }
287  if( a.Contains( b.B ) ) { is.p = b.B; aIp.push_back( is ); }
288  if( b.Contains( a.A ) ) { is.p = a.A; aIp.push_back( is ); }
289  if( b.Contains( a.B ) ) { is.p = a.B; aIp.push_back( is ); }
290  }
291  else
292  {
293  OPT_VECTOR2I p = a.Intersect( b );
294 
295  if( p )
296  {
297  is.p = *p;
298  is.our = a;
299  is.their = b;
300  aIp.push_back( is );
301  }
302  }
303  }
304  }
305 
306  return aIp.size();
307 }
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 566 of file shape_line_chain.cpp.

References dummy(), and Intersect().

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

567 {
569  return Intersect( aChain, dummy ) != 0;
570 }
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 606 of file shape_line_chain.h.

References Area(), and PointAlong().

607  {
608  return false;
609  }
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 83 of file shape_line_chain.cpp.

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

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

Implements SHAPE.

Definition at line 592 of file shape_line_chain.h.

References m_points, and Rotate().

Referenced by SHAPE_CONVEX::Move().

593  {
594  for( std::vector<VECTOR2I>::iterator i = m_points.begin(); i != m_points.end(); ++i )
595  (*i) += aVector;
596  }
std::vector< VECTOR2I > m_points
array of vertices
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 497 of file shape_line_chain.cpp.

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

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

498 {
499  int min_d = INT_MAX;
500  int nearest = 0;
501 
502  for( int i = 0; i < SegmentCount(); i++ )
503  {
504  int d = CSegment( i ).Distance( aP );
505 
506  if( d < min_d )
507  {
508  min_d = d;
509  nearest = i;
510  }
511  }
512 
513  return CSegment( nearest ).NearestPoint( aP );
514 }
const SEG CSegment(int aIndex) const
Function CSegment()
const VECTOR2I NearestPoint(const VECTOR2I &aP) const
Function NearestPoint()
Definition: seg.h:364
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 517 of file shape_line_chain.cpp.

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

518 {
519  int nearest = 0;
520 
521  dist = INT_MAX;
522  for( int i = 0; i < PointCount(); i++ )
523  {
524  int d = aSeg.LineDistance( CPoint( i ) );
525 
526  if( d < dist )
527  {
528  dist = d;
529  nearest = i;
530  }
531  }
532 
533  return CPoint( nearest );
534 }
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:347
const VECTOR2I & CPoint(int aIndex) const
Function CPoint()
bool SHAPE_LINE_CHAIN::operator!= ( const SHAPE_LINE_CHAIN aRhs) const
inline

Definition at line 576 of file shape_line_chain.h.

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

577  {
578  if( PointCount() != aRhs.PointCount() )
579  return true;
580 
581  for( int i = 0; i < PointCount(); i++ )
582  {
583  if( CPoint( i ) != aRhs.CPoint( i ) )
584  return true;
585  }
586 
587  return false;
588  }
int PointCount() const
Function PointCount()
const VECTOR2I & CPoint(int aIndex) const
Function CPoint()
bool SHAPE_LINE_CHAIN::Parse ( std::stringstream &  aStream)
overridevirtual

Reimplemented from SHAPE.

Definition at line 578 of file shape_line_chain.cpp.

References m_closed, and m_points.

579 {
580  int n_pts;
581 
582  m_points.clear();
583  aStream >> n_pts;
584 
585  // Rough sanity check, just make sure the loop bounds aren't absolutely outlandish
586  if( n_pts < 0 || n_pts > int( aStream.str().size() ) )
587  return false;
588 
589  aStream >> m_closed;
590 
591  for( int i = 0; i < n_pts; i++ )
592  {
593  int x, y;
594  aStream >> x;
595  aStream >> y;
596  m_points.push_back( VECTOR2I( x, y ) );
597  }
598 
599  return true;
600 }
VECTOR2< int > VECTOR2I
Definition: vector2d.h:589
bool m_closed
is the line chain closed?
std::vector< VECTOR2I > m_points
array of vertices
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 310 of file shape_line_chain.cpp.

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

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

311 {
312  int sum = 0;
313 
314  for( int i = 0; i < SegmentCount(); i++ )
315  {
316  const SEG seg = CSegment( i );
317  int d = seg.Distance( aP );
318 
319  if( d <= 1 )
320  {
321  sum += ( aP - seg.A ).EuclideanNorm();
322  return sum;
323  }
324  else
325  sum += seg.Length();
326  }
327 
328  return -1;
329 }
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
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 603 of file shape_line_chain.cpp.

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

Referenced by IsSolid().

604 {
605  int total = 0;
606 
607  if( aPathLength == 0 )
608  return CPoint( 0 );
609 
610  for( int i = 0; i < SegmentCount(); i++ )
611  {
612  const SEG& s = CSegment( i );
613  int l = s.Length();
614 
615  if( total + l >= aPathLength )
616  {
617  VECTOR2I d( s.B - s.A );
618  return s.A + d.Resize( aPathLength - total );
619  }
620 
621  total += l;
622  }
623 
624  return CPoint( -1 );
625 }
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
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(), 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(), DRC::checkClearancePadToPad(), DRC::checkClearanceSegmToPad(), Convert_shape_line_polygon_to_triangles(), ConvertPolySetToPolyList(), SHAPE_POLY_SET::convertToClipper(), PNS::coupledBypass(), CPoint(), CreatePadsShapesSection(), D_PAD::CustomShapeAsPolygonToBoardPosition(), 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_drawsegment(), export_vrml_edge_module(), 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(), DRAWSEGMENT::IsPolyShapeValid(), DRAWING_TOOL::make45DegLine(), DSN::SPECCTRA_DB::makePADSTACK(), PNS::OPTIMIZER::mergeObtuse(), NearestPoint(), operator!=(), PNS::LINE_PLACER::optimizeTailHeadTransition(), PlotLayerOutlines(), PLOTTER::PlotPoly(), DXF_PLOTTER::PlotPoly(), Point(), SHAPE_CONVEX::PointCount(), PNS::LINE::PointCount(), SHAPE_POLY_SET::pointInPolygon(), PointOnEdge(), Polygon_Calc_BBox_3DU(), polygon_Convert(), PNS::SHOVE::processHullSet(), Remove(), Replace(), PNS::OPTIMIZER::runSmartPads(), 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(), and PNS::SHOVE::walkaroundLoneVia().

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 convex polygon 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).

Definition at line 332 of file shape_line_chain.cpp.

References SEG::A, SEG::B, CSegment(), m_closed, SegmentCount(), and SEG::Side().

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

333 {
334  if( !m_closed || SegmentCount() < 3 )
335  return false;
336 
337  int cur = CSegment( 0 ).Side( aP );
338 
339  if( cur == 0 )
340  return false;
341 
342  for( int i = 1; i < SegmentCount(); i++ )
343  {
344  const SEG s = CSegment( i );
345 
346  if( aP == s.A || aP == s.B ) // edge does not belong to the interior!
347  return false;
348 
349  if( s.Side( aP ) != cur )
350  return false;
351  }
352 
353  return true;
354 }
int Side(const VECTOR2I &aP) const
Function Side()
Definition: seg.h:132
const SEG CSegment(int aIndex) const
Function CSegment()
bool m_closed
is the line chain closed?
Definition: seg.h:36
VECTOR2I A
Definition: seg.h:46
int SegmentCount() const
Function SegmentCount()
VECTOR2I B
Definition: seg.h:47
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 357 of file shape_line_chain.cpp.

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

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

358 {
359  if( !PointCount() )
360  return false;
361 
362  else if( PointCount() == 1 )
363  return m_points[0] == aP;
364 
365  for( int i = 0; i < SegmentCount(); i++ )
366  {
367  const SEG s = CSegment( i );
368 
369  if( s.A == aP || s.B == aP )
370  return true;
371 
372  if( s.Distance( aP ) <= 1 )
373  return true;
374  }
375 
376  return false;
377 }
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
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
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 125 of file shape_line_chain.cpp.

References m_points, and PointCount().

Referenced by PNS::LINE_PLACER::buildInitialLine(), PNS::LINE::ClipToNearestObstacle(), 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().

126 {
127  if( aEndIndex < 0 )
128  aEndIndex += PointCount();
129 
130  if( aStartIndex < 0 )
131  aStartIndex += PointCount();
132 
133  m_points.erase( m_points.begin() + aStartIndex, m_points.begin() + aEndIndex + 1 );
134 }
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 424 of file shape_line_chain.h.

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

425  {
426  Remove( aIndex, aIndex );
427  }
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 94 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().

95 {
96  if( aEndIndex < 0 )
97  aEndIndex += PointCount();
98 
99  if( aStartIndex < 0 )
100  aStartIndex += PointCount();
101 
102  if( aStartIndex == aEndIndex )
103  m_points[aStartIndex] = aP;
104  else
105  {
106  m_points.erase( m_points.begin() + aStartIndex + 1, m_points.begin() + aEndIndex + 1 );
107  m_points[aStartIndex] = aP;
108  }
109 }
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 112 of file shape_line_chain.cpp.

References m_points, and PointCount().

113 {
114  if( aEndIndex < 0 )
115  aEndIndex += PointCount();
116 
117  if( aStartIndex < 0 )
118  aStartIndex += PointCount();
119 
120  m_points.erase( m_points.begin() + aStartIndex, m_points.begin() + aEndIndex + 1 );
121  m_points.insert( m_points.begin() + aStartIndex, aLine.m_points.begin(), aLine.m_points.end() );
122 }
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 72 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().

73 {
74  SHAPE_LINE_CHAIN a( *this );
75 
76  reverse( a.m_points.begin(), a.m_points.end() );
77  a.m_closed = m_closed;
78 
79  return a;
80 }
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 38 of file shape_line_chain.cpp.

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

Referenced by Move().

39 {
40  for( std::vector<VECTOR2I>::iterator i = m_points.begin(); i != m_points.end(); ++i )
41  {
42  (*i) -= aCenter;
43  (*i) = (*i).Rotate( aAngle );
44  (*i) += aCenter;
45  }
46 }
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
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(), 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(), PointInside(), PointOnEdge(), 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 380 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().

381 {
382  for( int s1 = 0; s1 < SegmentCount(); s1++ )
383  {
384  for( int s2 = s1 + 1; s2 < SegmentCount(); s2++ )
385  {
386  const VECTOR2I s2a = CSegment( s2 ).A, s2b = CSegment( s2 ).B;
387 
388  if( s1 + 1 != s2 && CSegment( s1 ).Contains( s2a ) )
389  {
390  INTERSECTION is;
391  is.our = CSegment( s1 );
392  is.their = CSegment( s2 );
393  is.p = s2a;
394  return is;
395  }
396  else if( CSegment( s1 ).Contains( s2b ) &&
397  // for closed polylines, the ending point of the
398  // last segment == starting point of the first segment
399  // this is a normal case, not self intersecting case
400  !( IsClosed() && s1 == 0 && s2 == SegmentCount()-1 ) )
401  {
402  INTERSECTION is;
403  is.our = CSegment( s1 );
404  is.their = CSegment( s2 );
405  is.p = s2b;
406  return is;
407  }
408  else
409  {
410  OPT_VECTOR2I p = CSegment( s1 ).Intersect( CSegment( s2 ), true );
411 
412  if( p )
413  {
414  INTERSECTION is;
415  is.our = CSegment( s1 );
416  is.their = CSegment( s2 );
417  is.p = *p;
418  return is;
419  }
420  }
421  }
422  }
423 
425 }
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 428 of file shape_line_chain.cpp.

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

429 {
430  std::vector<VECTOR2I> pts_unique;
431 
432  if( PointCount() < 2 )
433  {
434  return *this;
435  }
436  else if( PointCount() == 2 )
437  {
438  if( m_points[0] == m_points[1] )
439  m_points.pop_back();
440 
441  return *this;
442  }
443 
444  int i = 0;
445  int np = PointCount();
446 
447  // stage 1: eliminate duplicate vertices
448  while( i < np )
449  {
450  int j = i + 1;
451 
452  while( j < np && CPoint( i ) == CPoint( j ) )
453  j++;
454 
455  pts_unique.push_back( CPoint( i ) );
456  i = j;
457  }
458 
459  m_points.clear();
460  np = pts_unique.size();
461 
462  i = 0;
463 
464  // stage 1: eliminate collinear segments
465  while( i < np - 2 )
466  {
467  const VECTOR2I p0 = pts_unique[i];
468  const VECTOR2I p1 = pts_unique[i + 1];
469  int n = i;
470 
471  while( n < np - 2 && SEG( p0, p1 ).LineDistance( pts_unique[n + 2] ) <= 1 )
472  n++;
473 
474  m_points.push_back( p0 );
475 
476  if( n > i )
477  i = n;
478 
479  if( n == np )
480  {
481  m_points.push_back( pts_unique[n - 1] );
482  return *this;
483  }
484 
485  i++;
486  }
487 
488  if( np > 1 )
489  m_points.push_back( pts_unique[np - 2] );
490 
491  m_points.push_back( pts_unique[np - 1] );
492 
493  return *this;
494 }
int PointCount() const
Function PointCount()
std::vector< VECTOR2I > m_points
array of vertices
Definition: seg.h:36
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 209 of file shape_line_chain.cpp.

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

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

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

Referenced by Append().

bool SHAPE_LINE_CHAIN::m_closed
private

is the line chain closed?

Definition at line 620 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: