KiCad PCB EDA Suite
SHAPE_LINE_CHAIN Class Reference

SHAPE_LINE_CHAIN. More...

#include <shape_line_chain.h>

Inheritance diagram for SHAPE_LINE_CHAIN:
SHAPE

Classes

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

Public Types

typedef std::vector< INTERSECTIONINTERSECTIONS
 

Public Member Functions

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

Protected Types

typedef VECTOR2I::extended_type ecoord
 

Protected Attributes

SHAPE_TYPE m_type
 

type of our shape

More...
 

Private Types

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

Private Attributes

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

Static Private Attributes

static constexpr ssize_t SHAPE_IS_PT = -1
 

Detailed Description

SHAPE_LINE_CHAIN.

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

SHAPE_LINE_CHAIN class shall not be used for polygons!

Definition at line 54 of file shape_line_chain.h.

Member Typedef Documentation

◆ ecoord

typedef VECTOR2I::extended_type SHAPE::ecoord
protectedinherited

Definition at line 77 of file shape.h.

◆ INTERSECTIONS

Definition at line 103 of file shape_line_chain.h.

◆ point_citer

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

Definition at line 58 of file shape_line_chain.h.

◆ point_iter

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

Definition at line 57 of file shape_line_chain.h.

Constructor & Destructor Documentation

◆ SHAPE_LINE_CHAIN() [1/7]

SHAPE_LINE_CHAIN::SHAPE_LINE_CHAIN ( )
inline

Constructor Initializes an empty line chain.

Definition at line 110 of file shape_line_chain.h.

110  : SHAPE( SH_LINE_CHAIN ), m_closed( false ), m_width( 0 )
111  {}
SHAPE(SHAPE_TYPE aType)
Constructor.
Definition: shape.h:86
bool m_closed
is the line chain closed?
int m_width
Width of the segments (for BBox calculations in RTree) TODO Adjust usage of SHAPE_LINE_CHAIN to accou...
line segment
Definition: shape.h:43

Referenced by Clone().

◆ SHAPE_LINE_CHAIN() [2/7]

SHAPE_LINE_CHAIN::SHAPE_LINE_CHAIN ( const SHAPE_LINE_CHAIN aShape)
inline

Copy Constructor.

Definition at line 117 of file shape_line_chain.h.

118  : SHAPE( SH_LINE_CHAIN ),
119  m_points( aShape.m_points ),
120  m_shapes( aShape.m_shapes ),
121  m_arcs( aShape.m_arcs ),
122  m_closed( aShape.m_closed ),
123  m_width( aShape.m_width ),
124  m_bbox( aShape.m_bbox )
125  {}
BOX2I m_bbox
cached bounding box
SHAPE(SHAPE_TYPE aType)
Constructor.
Definition: shape.h:86
std::vector< SHAPE_ARC > m_arcs
bool m_closed
is the line chain closed?
std::vector< VECTOR2I > m_points
array of vertices
std::vector< ssize_t > m_shapes
Array of indices that refer to the index of the shape if the point is part of a larger shape,...
int m_width
Width of the segments (for BBox calculations in RTree) TODO Adjust usage of SHAPE_LINE_CHAIN to accou...
line segment
Definition: shape.h:43

◆ SHAPE_LINE_CHAIN() [3/7]

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

Definition at line 39 of file shape_line_chain.cpp.

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

References Append().

◆ SHAPE_LINE_CHAIN() [4/7]

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

Definition at line 129 of file shape_line_chain.h.

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

References m_points, m_shapes, and SHAPE_IS_PT.

◆ SHAPE_LINE_CHAIN() [5/7]

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

Definition at line 140 of file shape_line_chain.h.

141  : SHAPE( SH_LINE_CHAIN ), m_closed( aClosed ), m_width( 0 )
142  {
143  m_points = aV;
144  m_shapes = std::vector<ssize_t>( aV.size(), ssize_t( SHAPE_IS_PT ) );
145  }
SHAPE(SHAPE_TYPE aType)
Constructor.
Definition: shape.h:86
bool m_closed
is the line chain closed?
std::vector< VECTOR2I > m_points
array of vertices
std::vector< ssize_t > m_shapes
Array of indices that refer to the index of the shape if the point is part of a larger shape,...
static constexpr ssize_t SHAPE_IS_PT
int m_width
Width of the segments (for BBox calculations in RTree) TODO Adjust usage of SHAPE_LINE_CHAIN to accou...
line segment
Definition: shape.h:43

References m_points, m_shapes, and SHAPE_IS_PT.

◆ SHAPE_LINE_CHAIN() [6/7]

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

Definition at line 147 of file shape_line_chain.h.

148  : SHAPE( SH_LINE_CHAIN ),
149  m_closed( aClosed ),
150  m_width( 0 )
151  {
153  m_arcs.emplace_back( aArc );
154  m_shapes = std::vector<ssize_t>( m_points.size(), 0 );
155  }
SHAPE(SHAPE_TYPE aType)
Constructor.
Definition: shape.h:86
std::vector< SHAPE_ARC > m_arcs
bool m_closed
is the line chain closed?
const std::vector< VECTOR2I > & CPoints() const
std::vector< VECTOR2I > m_points
array of vertices
std::vector< ssize_t > m_shapes
Array of indices that refer to the index of the shape if the point is part of a larger shape,...
int m_width
Width of the segments (for BBox calculations in RTree) TODO Adjust usage of SHAPE_LINE_CHAIN to accou...
line segment
Definition: shape.h:43
const SHAPE_LINE_CHAIN ConvertToPolyline(double aAccuracy=500.0) const
Constructs a SHAPE_LINE_CHAIN of segments from a given arc.
Definition: shape_arc.cpp:238

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

◆ SHAPE_LINE_CHAIN() [7/7]

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

Definition at line 157 of file shape_line_chain.h.

157  :
158  SHAPE( SH_LINE_CHAIN ),
159  m_closed( true ),
160  m_width( 0 )
161  {
162  m_points.reserve( aPath.size() );
163  m_shapes = std::vector<ssize_t>( aPath.size(), ssize_t( SHAPE_IS_PT ) );
164 
165  for( const auto& point : aPath )
166  m_points.emplace_back( point.X, point.Y );
167  }
SHAPE(SHAPE_TYPE aType)
Constructor.
Definition: shape.h:86
bool m_closed
is the line chain closed?
std::vector< VECTOR2I > m_points
array of vertices
std::vector< ssize_t > m_shapes
Array of indices that refer to the index of the shape if the point is part of a larger shape,...
static constexpr ssize_t SHAPE_IS_PT
int m_width
Width of the segments (for BBox calculations in RTree) TODO Adjust usage of SHAPE_LINE_CHAIN to accou...
line segment
Definition: shape.h:43

References m_points, m_shapes, and SHAPE_IS_PT.

◆ ~SHAPE_LINE_CHAIN()

virtual SHAPE_LINE_CHAIN::~SHAPE_LINE_CHAIN ( )
inlinevirtual

Definition at line 169 of file shape_line_chain.h.

170  {}

Member Function Documentation

◆ Append() [1/4]

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

Function Append()

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

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

Definition at line 443 of file shape_line_chain.h.

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

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

◆ Append() [2/4]

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

Function Append()

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

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

Definition at line 458 of file shape_line_chain.h.

459  {
460  if( m_points.size() == 0 )
461  m_bbox = BOX2I( aP, VECTOR2I( 0, 0 ) );
462 
463  if( m_points.size() == 0 || aAllowDuplication || CPoint( -1 ) != aP )
464  {
465  m_points.push_back( aP );
466  m_shapes.push_back( ssize_t( SHAPE_IS_PT ) );
467  m_bbox.Merge( aP );
468  }
469  }
BOX2I m_bbox
cached bounding box
BOX2< VECTOR2I > BOX2I
Definition: box2.h:521
VECTOR2< int > VECTOR2I
Definition: vector2d.h:594
const VECTOR2I & CPoint(int aIndex) const
Function Point()
std::vector< VECTOR2I > m_points
array of vertices
BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Function Merge modifies the position and size of the rectangle in order to contain aRect.
Definition: box2.h:385
std::vector< ssize_t > m_shapes
Array of indices that refer to the index of the shape if the point is part of a larger shape,...
static constexpr ssize_t SHAPE_IS_PT

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

◆ Append() [3/4]

void SHAPE_LINE_CHAIN::Append ( const SHAPE_LINE_CHAIN aOtherLine)

Function Append()

Appends another line chain at the end.

Parameters
aOtherLinethe line chain to be appended.

Definition at line 385 of file shape_line_chain.cpp.

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

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

◆ Append() [4/4]

void SHAPE_LINE_CHAIN::Append ( const SHAPE_ARC aArc)

Definition at line 422 of file shape_line_chain.cpp.

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

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

◆ Arc()

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

Definition at line 779 of file shape_line_chain.h.

780  {
781  return m_arcs[aArc];
782  }
std::vector< SHAPE_ARC > m_arcs

References m_arcs.

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

◆ ArcCount()

size_t SHAPE_LINE_CHAIN::ArcCount ( ) const
inline

Definition at line 766 of file shape_line_chain.h.

767  {
768  return m_arcs.size();
769  }
std::vector< SHAPE_ARC > m_arcs

References m_arcs.

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

◆ ArcIndex()

ssize_t SHAPE_LINE_CHAIN::ArcIndex ( size_t  aSegment) const
inline

Definition at line 771 of file shape_line_chain.h.

772  {
773  if( aSegment >= m_shapes.size() )
774  return SHAPE_IS_PT;
775 
776  return m_shapes[aSegment];
777  }
std::vector< ssize_t > m_shapes
Array of indices that refer to the index of the shape if the point is part of a larger shape,...
static constexpr ssize_t SHAPE_IS_PT

References m_shapes, and SHAPE_IS_PT.

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

◆ Area()

double SHAPE_LINE_CHAIN::Area ( ) const

Definition at line 1019 of file shape_line_chain.cpp.

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

References m_closed, and m_points.

Referenced by ZONE_FILLER::addHatchFillTypeOnZone(), ZONE_CONTAINER::CalculateFilledArea(), DIALOG_BOARD_STATISTICS::getDataFromPCB(), D_PAD::HitTest(), PlotSolderMaskLayer(), polygonArea(), unfracture(), and SHAPE_POLY_SET::unfractureSingle().

◆ BBox()

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

Function BBox()

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

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

Implements SHAPE.

Definition at line 359 of file shape_line_chain.h.

360  {
361  BOX2I bbox;
362  bbox.Compute( m_points );
363 
364  if( aClearance != 0 || m_width != 0 )
365  bbox.Inflate( aClearance + m_width );
366 
367  return bbox;
368  }
void Compute(const Container &aPointList)
Compute the bounding box from a given list of points.
Definition: box2.h:90
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:301
int m_width
Width of the segments (for BBox calculations in RTree) TODO Adjust usage of SHAPE_LINE_CHAIN to accou...

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

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

◆ BBoxFromCache()

const BOX2I SHAPE_LINE_CHAIN::BBoxFromCache ( ) const
inline

Definition at line 378 of file shape_line_chain.h.

379  {
380  return m_bbox;
381  }
BOX2I m_bbox
cached bounding box

References m_bbox.

◆ CalcShape()

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

Definition at line 713 of file wrlfacet.cpp.

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

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

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

◆ CArcs()

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

Definition at line 345 of file shape_line_chain.h.

346  {
347  return m_arcs;
348  }
std::vector< SHAPE_ARC > m_arcs

References m_arcs.

Referenced by ROUTER_PREVIEW_ITEM::drawLineChain().

◆ Centre()

virtual VECTOR2I SHAPE::Centre ( ) const
inlinevirtualinherited

Function Centre()

Computes a center-of-mass of the shape

Returns
the center-of-mass point

Definition at line 173 of file shape.h.

174  {
175  return BBox( 0 ).Centre(); // if nothing better is available....
176  }
virtual const BOX2I BBox(int aClearance=0) const =0
Function BBox()
Vec Centre() const
Definition: box2.h:78

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

Referenced by PNS_PCBNEW_RULE_RESOLVER::CollideHoles().

◆ CheckClearance()

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

Function CheckClearance()

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

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

Definition at line 687 of file shape_line_chain.cpp.

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

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

◆ CLastPoint()

const VECTOR2I& SHAPE_LINE_CHAIN::CLastPoint ( ) const
inline

Returns the last point in the line chain.

Definition at line 337 of file shape_line_chain.h.

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

References m_points, and PointCount().

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

◆ Clear()

void SHAPE_LINE_CHAIN::Clear ( )
inline

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

Definition at line 180 of file shape_line_chain.h.

181  {
182  m_points.clear();
183  m_arcs.clear();
184  m_shapes.clear();
185  m_closed = false;
186  }
std::vector< SHAPE_ARC > m_arcs
bool m_closed
is the line chain closed?
std::vector< VECTOR2I > m_points
array of vertices
std::vector< ssize_t > m_shapes
Array of indices that refer to the index of the shape if the point is part of a larger shape,...

References m_arcs, m_closed, m_points, and m_shapes.

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

◆ Clone()

SHAPE * SHAPE_LINE_CHAIN::Clone ( ) const
overridevirtual

Function Clone()

Returns a dynamically allocated copy of the shape

Return values
copyof the shape

Reimplemented from SHAPE.

Definition at line 942 of file shape_line_chain.cpp.

943 {
944  return new SHAPE_LINE_CHAIN( *this );
945 }
SHAPE_LINE_CHAIN()
Constructor Initializes an empty line chain.

References SHAPE_LINE_CHAIN().

Referenced by ROUTER_PREVIEW_ITEM::Line().

◆ Collide() [1/4]

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

Function Collide()

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

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

Definition at line 607 of file shape_collisions.cpp.

608 {
609  return CollideShapes( this, aShape, aClearance, nullptr, aMTV );
610 }
bool CollideShapes(const SHAPE *aA, const SHAPE *aB, int aClearance, int *aActual, VECTOR2I *aMTV)

References CollideShapes().

◆ Collide() [2/4]

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

Definition at line 613 of file shape_collisions.cpp.

614 {
615  return CollideShapes( this, aShape, aClearance, aActual, nullptr );
616 }
bool CollideShapes(const SHAPE *aA, const SHAPE *aB, int aClearance, int *aActual, VECTOR2I *aMTV)

References CollideShapes().

◆ Collide() [3/4]

bool SHAPE_LINE_CHAIN::Collide ( const VECTOR2I aP,
int  aClearance = 0,
int *  aActual = nullptr 
) 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.
aActualan optional pointer to an int to store the actual distance in the event of a collision.
Returns
true, when a collision has been found

Reimplemented from SHAPE.

Definition at line 88 of file shape_line_chain.cpp.

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

References CSegment(), VECTOR2< T >::ECOORD_MAX, SegmentCount(), SEG::Square(), and SEG::SquaredDistance().

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

◆ Collide() [4/4]

bool SHAPE_LINE_CHAIN::Collide ( const SEG aSeg,
int  aClearance = 0,
int *  aActual = nullptr 
) 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.
aActualan optional pointer to an int to store the actual distance in the event of a collision.
Returns
true, when a collision has been found

Implements SHAPE.

Definition at line 128 of file shape_line_chain.cpp.

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

References CSegment(), VECTOR2< T >::ECOORD_MAX, SegmentCount(), SEG::Square(), and SEG::SquaredDistance().

◆ CompareGeometry()

bool SHAPE_LINE_CHAIN::CompareGeometry ( const SHAPE_LINE_CHAIN aOther) const

Definition at line 919 of file shape_line_chain.cpp.

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

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

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

◆ convertArc()

void SHAPE_LINE_CHAIN::convertArc ( ssize_t  aArcIndex)

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

Parameters
aArcIndexindex of the arc to convert to points

Definition at line 66 of file shape_line_chain.cpp.

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

References m_arcs, m_shapes, and SHAPE_IS_PT.

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

◆ convertToClipper()

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

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

Definition at line 48 of file shape_line_chain.cpp.

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

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

◆ CPoint()

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

Function Point()

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

Parameters
aIndexindex of the point
Returns
const reference to the point

Definition at line 319 of file shape_line_chain.h.

320  {
321  if( aIndex < 0 )
322  aIndex += PointCount();
323  else if( aIndex >= PointCount() )
324  aIndex -= PointCount();
325 
326  return m_points[aIndex];
327  }
int PointCount() const
Function PointCount()
std::vector< VECTOR2I > m_points
array of vertices

References m_points, and PointCount().

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

◆ CPoints()

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

◆ CSegment()

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

Function CSegment()

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

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

Definition at line 281 of file shape_line_chain.h.

282  {
283  if( aIndex < 0 )
284  aIndex += SegmentCount();
285 
286  if( aIndex == (int)( m_points.size() - 1 ) && m_closed )
287  return SEG( const_cast<VECTOR2I&>( m_points[aIndex] ),
288  const_cast<VECTOR2I&>( m_points[0] ), aIndex );
289  else
290  return SEG( const_cast<VECTOR2I&>( m_points[aIndex] ),
291  const_cast<VECTOR2I&>( m_points[aIndex + 1] ), aIndex );
292  }
bool m_closed
is the line chain closed?
std::vector< VECTOR2I > m_points
array of vertices
int SegmentCount() const
Function SegmentCount()
Definition: seg.h:39

References m_closed, m_points, and SegmentCount().

Referenced by PNS::ArcHull(), PNS::LINE_PLACER::buildInitialLine(), PNS::PRESERVE_VERTEX_CONSTRAINT::Check(), CheckClearance(), PNS::NODE::CheckColliding(), PNS::DIFF_PAIR::CheckConnectionAngle(), PNS::checkGap(), PNS::MEANDERED_LINE::CheckSelfIntersections(), PNS::closestProjectedPoint(), Collide(), Collide(), PNS::COST_ESTIMATOR::CornerCost(), PNS::LINE::CountCorners(), PNS::coupledBypass(), PNS::DIFF_PAIR::CoupledLength(), PNS::LINE::CSegment(), PNS::MEANDER_PLACER_BASE::cutTunedLine(), PNS::dragCornerInternal(), PNS::LINE::dragSegment45(), ROUTER_PREVIEW_ITEM::drawLineChain(), EdgeContainingPoint(), PNS::findCoupledVertices(), FindSegment(), PNS::DIFF_PAIR_PLACER::FixRoute(), PNS::LINE_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(), NearestSegment(), PathLength(), PointAlong(), PNS::LINE_PLACER::reduceTail(), PNS::LINE_PLACER::rhStopAtNearestObstacle(), POLY_GRID_PARTITION::scanCell(), PNS::SegmentHull(), SelfIntersecting(), PNS::OPTIMIZER::smartPadsSingle(), PNS::LINE::snapDraggedCorner(), PNS::LINE::snapToNeighbourSegments(), Split(), SquaredDistance(), PNS::tightenSegment(), SHAPE_POLY_SET::unfractureSingle(), PNS::LINE::Walkaround(), and HYPERLYNX_EXPORTER::writeBoardInfo().

◆ CShapes()

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

Definition at line 353 of file shape_line_chain.h.

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

References m_shapes.

Referenced by BOOST_AUTO_TEST_CASE().

◆ Distance()

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

Function Distance()

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

Parameters
aPthe point
Returns
minimum distance.

Definition at line 289 of file shape_line_chain.cpp.

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

References SquaredDistance().

Referenced by D_PAD::GetBestAnchorPosition().

◆ EdgeContainingPoint()

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

Function EdgeContainingPoint()

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

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

Definition at line 661 of file shape_line_chain.cpp.

662 {
663  if( !PointCount() )
664  return -1;
665 
666  else if( PointCount() == 1 )
667  {
668  VECTOR2I dist = m_points[0] - aPt;
669  return ( hypot( dist.x, dist.y ) <= aAccuracy + 1 ) ? 0 : -1;
670  }
671 
672  for( int i = 0; i < SegmentCount(); i++ )
673  {
674  const SEG s = CSegment( i );
675 
676  if( s.A == aPt || s.B == aPt )
677  return i;
678 
679  if( s.Distance( aPt ) <= aAccuracy + 1 )
680  return i;
681  }
682 
683  return -1;
684 }
int Distance(const SEG &aSeg) const
Function Distance()
Definition: seg.h:207
VECTOR2 defines a general 2D-vector/point.
Definition: vector2d.h:61
int PointCount() const
Function PointCount()
double dist(const double ax, const double ay, const double bx, const double by)
Definition: delauney.h:168
std::vector< VECTOR2I > m_points
array of vertices
int SegmentCount() const
Function SegmentCount()
Definition: seg.h:39
const SEG CSegment(int aIndex) const
Function CSegment()
VECTOR2I A
Definition: seg.h:47
VECTOR2I B
Definition: seg.h:48

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

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

◆ Find()

int SHAPE_LINE_CHAIN::Find ( const VECTOR2I aP) const

Function Find()

Searches for point aP.

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

Definition at line 348 of file shape_line_chain.cpp.

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

References CPoint(), and PointCount().

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

◆ FindSegment()

int SHAPE_LINE_CHAIN::FindSegment ( const VECTOR2I aP) const

Function FindSegment()

Searches for segment containing point aP.

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

Definition at line 358 of file shape_line_chain.cpp.

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

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

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

◆ Format()

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

Reimplemented from SHAPE.

Definition at line 901 of file shape_line_chain.cpp.

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

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

◆ GenerateBBoxCache()

void SHAPE_LINE_CHAIN::GenerateBBoxCache ( )
inline

Definition at line 370 of file shape_line_chain.h.

371  {
373 
374  if( m_width != 0 )
376  }
BOX2I m_bbox
cached bounding box
void Compute(const Container &aPointList)
Compute the bounding box from a given list of points.
Definition: box2.h:90
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:301
int m_width
Width of the segments (for BBox calculations in RTree) TODO Adjust usage of SHAPE_LINE_CHAIN to accou...

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

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

◆ Insert() [1/2]

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

Definition at line 438 of file shape_line_chain.cpp.

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

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

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

◆ Insert() [2/2]

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

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

Step 2: Add the arc polyline points to the chain

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

Definition at line 450 of file shape_line_chain.cpp.

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

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

◆ Intersect() [1/2]

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

Function Intersect()

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

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

Definition at line 495 of file shape_line_chain.cpp.

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

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

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

◆ Intersect() [2/2]

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

Function Intersect()

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

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

Definition at line 536 of file shape_line_chain.cpp.

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

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

◆ Intersects()

bool SHAPE_LINE_CHAIN::Intersects ( const SHAPE_LINE_CHAIN aChain) const

Definition at line 935 of file shape_line_chain.cpp.

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

References dummy(), and Intersect().

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

◆ isArc()

bool SHAPE_LINE_CHAIN::isArc ( size_t  aSegment) const
inline

Definition at line 784 of file shape_line_chain.h.

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

References m_shapes, and SHAPE_IS_PT.

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

◆ IsClosed()

bool SHAPE_LINE_CHAIN::IsClosed ( ) const
inline

◆ IsSolid()

bool SHAPE_LINE_CHAIN::IsSolid ( ) const
inlineoverridevirtual

Implements SHAPE.

Definition at line 757 of file shape_line_chain.h.

758  {
759  return false;
760  }

◆ Length()

long long int SHAPE_LINE_CHAIN::Length ( ) const

◆ Mirror()

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

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

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

Definition at line 186 of file shape_line_chain.cpp.

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

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

◆ Move()

void SHAPE_LINE_CHAIN::Move ( const VECTOR2I aVector)
inlineoverridevirtual

Implements SHAPE.

Definition at line 732 of file shape_line_chain.h.

733  {
734  for( auto& pt : m_points )
735  pt += aVector;
736 
737  for( auto& arc : m_arcs )
738  arc.Move( aVector );
739  }
std::vector< SHAPE_ARC > m_arcs
std::vector< VECTOR2I > m_points
array of vertices

References m_arcs, and m_points.

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

◆ NearestPoint() [1/2]

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

Function NearestPoint()

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

Returns
the nearest point.

Definition at line 841 of file shape_line_chain.cpp.

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

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

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

◆ NearestPoint() [2/2]

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

Function NearestPoint()

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

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

Definition at line 861 of file shape_line_chain.cpp.

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

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

◆ NearestSegment()

int SHAPE_LINE_CHAIN::NearestSegment ( const VECTOR2I aP) const

Find the segment nearest the given point.

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

Definition at line 881 of file shape_line_chain.cpp.

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

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

Referenced by SCH_SHEET_PIN::ConstrainOnEdge().

◆ NewFacet()

FACET * SHAPE::NewFacet ( )
inherited

Definition at line 705 of file wrlfacet.cpp.

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

References SHAPE::facets.

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

◆ operator!=()

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

Definition at line 716 of file shape_line_chain.h.

717  {
718  if( PointCount() != aRhs.PointCount() )
719  return true;
720 
721  for( int i = 0; i < PointCount(); i++ )
722  {
723  if( CPoint( i ) != aRhs.CPoint( i ) )
724  return true;
725  }
726 
727  return false;
728  }
int PointCount() const
Function PointCount()
const VECTOR2I & CPoint(int aIndex) const
Function Point()

References CPoint(), and PointCount().

◆ operator=()

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

◆ Parse()

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

Reimplemented from SHAPE.

Definition at line 947 of file shape_line_chain.cpp.

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

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

◆ PathLength()

int SHAPE_LINE_CHAIN::PathLength ( const VECTOR2I aP) const

Function PathLength()

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

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

Definition at line 582 of file shape_line_chain.cpp.

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

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

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

◆ PointAlong()

const VECTOR2I SHAPE_LINE_CHAIN::PointAlong ( int  aPathLength) const

Definition at line 995 of file shape_line_chain.cpp.

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

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

◆ PointCount()

int SHAPE_LINE_CHAIN::PointCount ( ) const
inline

Function PointCount()

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

Returns
number of points

Definition at line 249 of file shape_line_chain.h.

250  {
251  return m_points.size();
252  }
std::vector< VECTOR2I > m_points
array of vertices

References m_points.

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

◆ PointInside()

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

Function PointInside()

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

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

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

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

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

Definition at line 604 of file shape_line_chain.cpp.

605 {
606  /*
607  * Don't check the bounding box unless it's cached. Building it is about the same speed as
608  * the rigorous test below and so just slows things down by doing potentially two tests.
609  */
610  if( aUseBBoxCache && !m_bbox.Contains( aPt ) )
611  return false;
612 
613  if( !m_closed || PointCount() < 3 )
614  return false;
615 
616  bool inside = false;
617 
629  const std::vector<VECTOR2I>& points = CPoints();
630  int pointCount = points.size();
631 
632  for( int i = 0; i < pointCount; )
633  {
634  const auto p1 = points[ i++ ];
635  const auto p2 = points[ i == pointCount ? 0 : i ];
636  const auto diff = p2 - p1;
637 
638  if( diff.y != 0 )
639  {
640  const int d = rescale( diff.x, ( aPt.y - p1.y ), diff.y );
641 
642  if( ( ( p1.y > aPt.y ) != ( p2.y > aPt.y ) ) && ( aPt.x - p1.x < d ) )
643  inside = !inside;
644  }
645  }
646 
647  // If accuracy is <= 1 (nm) then we skip the accuracy test for performance. Otherwise
648  // we use "OnEdge(accuracy)" as a proxy for "Inside(accuracy)".
649  if( aAccuracy <= 1 )
650  return inside;
651  else
652  return inside || PointOnEdge( aPt, aAccuracy );
653 }
BOX2I m_bbox
cached bounding box
bool PointOnEdge(const VECTOR2I &aP, int aAccuracy=0) const
Function PointOnEdge()
int PointCount() const
Function PointCount()
bool m_closed
is the line chain closed?
const std::vector< VECTOR2I > & CPoints() const
bool Contains(const Vec &aPoint) const
Function Contains.
Definition: box2.h:150
T rescale(T aNumerator, T aValue, T aDenominator)
Function rescale()
Definition: util.h:95

References BOX2< Vec >::Contains(), CPoints(), m_bbox, m_closed, PointCount(), PointOnEdge(), rescale(), VECTOR2< T >::x, and VECTOR2< T >::y.

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

◆ PointOnEdge()

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

Function PointOnEdge()

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

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

Definition at line 656 of file shape_line_chain.cpp.

657 {
658  return EdgeContainingPoint( aPt, aAccuracy ) >= 0;
659 }
int EdgeContainingPoint(const VECTOR2I &aP, int aAccuracy=0) const
Function EdgeContainingPoint()

References EdgeContainingPoint().

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

◆ Remove() [1/2]

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

Function Remove()

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

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

Definition at line 258 of file shape_line_chain.cpp.

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

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

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

◆ Remove() [2/2]

void SHAPE_LINE_CHAIN::Remove ( int  aIndex)
inline

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

Parameters
aIndexis the index of the point to be removed.

Definition at line 521 of file shape_line_chain.h.

522  {
523  Remove( aIndex, aIndex );
524  }
void Remove(int aStartIndex, int aEndIndex)
Function Remove()

References Remove().

◆ Replace() [1/2]

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

Function Replace()

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

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

Definition at line 202 of file shape_line_chain.cpp.

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

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

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

◆ Replace() [2/2]

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

Function Replace()

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

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

Definition at line 233 of file shape_line_chain.cpp.

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

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

◆ Reverse()

const SHAPE_LINE_CHAIN SHAPE_LINE_CHAIN::Reverse ( ) const

Function Reverse()

Reverses point order in the line chain.

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

Definition at line 154 of file shape_line_chain.cpp.

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

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

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

◆ Rotate()

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

Function Rotate rotates all vertices by a given angle.

Parameters
aCenteris the rotation center
aAnglerotation angle in radians

Implements SHAPE.

Definition at line 114 of file shape_line_chain.cpp.

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

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

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

◆ Segment()

SEG SHAPE_LINE_CHAIN::Segment ( int  aIndex)
inline

Function Segment()

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

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

Definition at line 262 of file shape_line_chain.h.

263  {
264  if( aIndex < 0 )
265  aIndex += SegmentCount();
266 
267  if( aIndex == (int)( m_points.size() - 1 ) && m_closed )
268  return SEG( m_points[aIndex], m_points[0], aIndex );
269  else
270  return SEG( m_points[aIndex], m_points[aIndex + 1], aIndex );
271  }
bool m_closed
is the line chain closed?
std::vector< VECTOR2I > m_points
array of vertices
int SegmentCount() const
Function SegmentCount()
Definition: seg.h:39

References m_closed, m_points, and SegmentCount().

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

◆ SegmentCount()

int SHAPE_LINE_CHAIN::SegmentCount ( ) const
inline

Function SegmentCount()

Returns number of segments in this line chain.

Returns
number of segments

Definition at line 234 of file shape_line_chain.h.

235  {
236  int c = m_points.size() - 1;
237  if( m_closed )
238  c++;
239 
240  return std::max( 0, c );
241  }
bool m_closed
is the line chain closed?
std::vector< VECTOR2I > m_points
array of vertices

References m_closed, and m_points.

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

◆ SelfIntersecting()

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

Function SelfIntersecting()

Checks if the line chain is self-intersecting.

Returns
(optional) first found self-intersection point.

Definition at line 710 of file shape_line_chain.cpp.

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

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

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

◆ SetClosed()

void SHAPE_LINE_CHAIN::SetClosed ( bool  aClosed)
inline

Function SetClosed()

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

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

Definition at line 195 of file shape_line_chain.h.

196  {
197  m_closed = aClosed;
198  }
bool m_closed
is the line chain closed?

References m_closed.

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

◆ SetPoint()

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

Accessor Function to move a point to a specific location.

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

Definition at line 299 of file shape_line_chain.h.

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

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

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

◆ SetWidth()

void SHAPE_LINE_CHAIN::SetWidth ( int  aWidth)
inline

Sets the width of all segments in the chain.

Parameters
aWidthwidth in internal units

Definition at line 214 of file shape_line_chain.h.

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

References m_width.

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

◆ Simplify()

SHAPE_LINE_CHAIN & SHAPE_LINE_CHAIN::Simplify ( )

Function Simplify()

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

Returns
reference to self.

Definition at line 758 of file shape_line_chain.cpp.

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

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

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

◆ Slice()

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

Function Slice()

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

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

Definition at line 368 of file shape_line_chain.cpp.

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

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

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

◆ Split()

int SHAPE_LINE_CHAIN::Split ( const VECTOR2I aP)

Function Split()

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

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

Definition at line 309 of file shape_line_chain.cpp.

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

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

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

◆ SquaredDistance()

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

Definition at line 295 of file shape_line_chain.cpp.

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

References CSegment(), VECTOR2< T >::ECOORD_MAX, IsClosed(), PointInside(), SegmentCount(), and SEG::SquaredDistance().

Referenced by Collide(), and Distance().

◆ Type()

SHAPE_TYPE SHAPE::Type ( ) const
inlineinherited

Function Type()

Returns the type of the shape.

Return values
thetype

Definition at line 99 of file shape.h.

100  {
101  return m_type;
102  }
SHAPE_TYPE m_type
type of our shape
Definition: shape.h:195

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

◆ Width()

int SHAPE_LINE_CHAIN::Width ( ) const
inline

Gets the current width of the segments in the chain.

Returns
width in internal units

Definition at line 223 of file shape_line_chain.h.

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

References m_width.

Member Data Documentation

◆ m_arcs

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

◆ m_bbox

BOX2I SHAPE_LINE_CHAIN::m_bbox
private

cached bounding box

Definition at line 815 of file shape_line_chain.h.

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

◆ m_closed

bool SHAPE_LINE_CHAIN::m_closed
private

is the line chain closed?

Definition at line 806 of file shape_line_chain.h.

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

◆ m_points

◆ m_shapes

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

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

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

Definition at line 801 of file shape_line_chain.h.

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

◆ m_type

SHAPE_TYPE SHAPE::m_type
protectedinherited

type of our shape

Definition at line 195 of file shape.h.

Referenced by SHAPE::Type().

◆ m_width

int SHAPE_LINE_CHAIN::m_width
private

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

Not sure yet on the correct path.

Definition at line 812 of file shape_line_chain.h.

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

◆ SHAPE_IS_PT

constexpr ssize_t SHAPE_LINE_CHAIN::SHAPE_IS_PT = -1
staticprivate

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