KiCad PCB EDA Suite
PNS::LINE Class Reference

#include <pns_line.h>

Inheritance diagram for PNS::LINE:
PNS::ITEM

Public Types

typedef std::vector< LINKED_ITEM * > SEGMENT_REFS
 
enum  PnsKind {
  SOLID_T = 1, LINE_T = 2, JOINT_T = 4, SEGMENT_T = 8,
  ARC_T = 16, VIA_T = 32, DIFF_PAIR_T = 64, ANY_T = 0xff
}
 

Supported item types

More...
 

Public Member Functions

 LINE ()
 Constructor Makes an empty line. More...
 
 LINE (const LINE &aOther)
 
 LINE (const LINE &aBase, const SHAPE_LINE_CHAIN &aLine)
 Constructor Copies properties (net, layers, etc.) from a base line and replaces the shape by another. More...
 
 LINE (const VIA &aVia)
 Constructor Constructs a LINE for a lone VIA (ie a stitching via). More...
 
 ~LINE ()
 
virtual LINEClone () const override
 Function Clone() More...
 
LINEoperator= (const LINE &aOther)
 
void SetShape (const SHAPE_LINE_CHAIN &aLine)
 

Assigns a shape to the line (a polyline/line chain)

More...
 
const SHAPEShape () const override
 

Returns the shape of the line

More...
 
SHAPE_LINE_CHAINLine ()
 

Modifiable accessor to the underlying shape

More...
 
const SHAPE_LINE_CHAINCLine () const
 

Const accessor to the underlying shape

More...
 
int SegmentCount () const
 

Returns the number of segments in the line

More...
 
int PointCount () const
 

Returns the number of points in the line

More...
 
int ArcCount () const
 

Returns the number of arcs in the line

More...
 
const VECTOR2ICPoint (int aIdx) const
 

Returns the aIdx-th point of the line

More...
 
const SEG CSegment (int aIdx) const
 

Returns the aIdx-th segment of the line

More...
 
void SetWidth (int aWidth)
 

Sets line width

More...
 
int Width () const
 

Returns line width

More...
 
bool CompareGeometry (const LINE &aOther)
 

Returns true if the line is geometrically identical as line aOther

More...
 
void Reverse ()
 

Reverses the point/vertex order

More...
 
void LinkSegment (LINKED_ITEM *aSeg)
 

Adds a reference to a segment registered in a NODE that is a part of this line.

More...
 
SEGMENT_REFSLinkedSegments ()
 

Returns the list of segments from the owning node that constitute this line (or NULL if the line is not linked)

More...
 
bool IsLinked () const
 
bool IsLinkedChecked () const
 
bool ContainsSegment (LINKED_ITEM *aSeg) const
 

Checks if the segment aSeg is a part of the line.

More...
 
LINKED_ITEMGetLink (int aIndex) const
 
void ClearSegmentLinks ()
 

Erases the linking information. Used to detach the line from the owning node.

More...
 
int LinkCount () const
 

Returns the number of segments that were assembled together to form this line.

More...
 
const LINE ClipToNearestObstacle (NODE *aNode) const
 

Clips the line to the nearest obstacle, traversing from the line's start vertex (0).

More...
 
void ClipVertexRange (int aStart, int aEnd)
 

Clips the line to a given range of vertices.

More...
 
int CountCorners (int aAngles) const
 

Returns the number of corners of angles specified by mask aAngles.

More...
 
bool Walkaround (SHAPE_LINE_CHAIN aObstacle, SHAPE_LINE_CHAIN &aPre, SHAPE_LINE_CHAIN &aWalk, SHAPE_LINE_CHAIN &aPost, bool aCw) const
 

Calculates a line thightly wrapping a convex hull of an obstacle object (aObstacle).

More...
 
bool Walkaround (const SHAPE_LINE_CHAIN &aObstacle, SHAPE_LINE_CHAIN &aPath, bool aCw) const
 
bool Is45Degree () const
 
void ShowLinks () const
 

Prints out all linked segments

More...
 
bool EndsWithVia () const
 
void AppendVia (const VIA &aVia)
 
void RemoveVia ()
 
const VIAVia () const
 
virtual void Mark (int aMarker) override
 
virtual void Unmark (int aMarker=-1) override
 
virtual int Marker () const override
 
void DragSegment (const VECTOR2I &aP, int aIndex, bool aFreeAngle=false)
 
void DragCorner (const VECTOR2I &aP, int aIndex, bool aFreeAngle=false)
 
void SetRank (int aRank) override
 
int Rank () const override
 
bool HasLoops () const
 
bool HasLockedSegments () const
 
void Clear ()
 
void Merge (const LINE &aOther)
 
OPT_BOX2I ChangedArea (const LINE *aOther) const
 
void SetSnapThreshhold (int aThreshhold)
 
int GetSnapThreshhold () const
 
virtual const SHAPE_LINE_CHAIN Hull (int aClearance=0, int aWalkaroundThickness=0) const
 
PnsKind Kind () const
 Function Kind() More...
 
bool OfKind (int aKindMask) const
 Function OfKind() More...
 
std::string KindStr () const
 Function KindStr() More...
 
void SetParent (BOARD_CONNECTED_ITEM *aParent)
 
BOARD_CONNECTED_ITEMParent () const
 
void SetNet (int aNet)
 
int Net () const
 
const LAYER_RANGELayers () const
 
void SetLayers (const LAYER_RANGE &aLayers)
 
void SetLayer (int aLayer)
 
virtual int Layer () const
 
bool LayersOverlap (const ITEM *aOther) const
 Function LayersOverlap() More...
 
NODEOwner () const
 Function Owner() More...
 
void SetOwner (NODE *aOwner)
 Functon SetOwner() More...
 
bool BelongsTo (NODE *aNode) const
 Function BelongsTo() More...
 
virtual bool Collide (const ITEM *aOther, int aClearance, bool aNeedMTV, VECTOR2I *aMTV, const NODE *aParentNode, bool aDifferentNetsOnly=true) const
 Function Collide() More...
 
virtual VECTOR2I Anchor (int n) const
 
virtual int AnchorCount () const
 
bool IsLocked () const
 
void SetRoutable (bool aRoutable)
 
bool IsRoutable () const
 

Static Public Member Functions

static bool ClassOf (const ITEM *aItem)
 

Static Public Attributes

static const int UnusedNet = INT_MAX
 

Protected Attributes

PnsKind m_kind
 
BOARD_CONNECTED_ITEMm_parent
 
NODEm_owner
 
LAYER_RANGE m_layers
 
bool m_movable
 
int m_net
 
int m_marker
 
int m_rank
 
bool m_routable
 

Private Member Functions

void dragSegment45 (const VECTOR2I &aP, int aIndex)
 
void dragCorner45 (const VECTOR2I &aP, int aIndex)
 
void dragSegmentFree (const VECTOR2I &aP, int aIndex)
 
void dragCornerFree (const VECTOR2I &aP, int aIndex)
 
VECTOR2I snapToNeighbourSegments (const SHAPE_LINE_CHAIN &aPath, const VECTOR2I &aP, int aIndex) const
 
VECTOR2I snapDraggedCorner (const SHAPE_LINE_CHAIN &aPath, const VECTOR2I &aP, int aIndex) const
 
void copyLinks (const LINE *aParent)
 

Copies m_segmentRefs from the line aParent.

More...
 

Private Attributes

SEGMENT_REFS m_segmentRefs
 

List of segments in the owning NODE (ITEM::m_owner) that constitute this line, or NULL if the line is not a part of any node.

More...
 
SHAPE_LINE_CHAIN m_line
 

The actual shape of the line

More...
 
int m_width
 

our width

More...
 
bool m_hasVia
 

If true, the line ends with a via

More...
 
int m_snapThreshhold
 

Width to smooth out jagged segments

More...
 
VIA m_via
 

Via at the end point, if m_hasVia == true

More...
 

Detailed Description

Definition at line 61 of file pns_line.h.

Member Typedef Documentation

◆ SEGMENT_REFS

typedef std::vector<LINKED_ITEM*> PNS::LINE::SEGMENT_REFS

Definition at line 64 of file pns_line.h.

Member Enumeration Documentation

◆ PnsKind

enum PNS::ITEM::PnsKind
inherited

Supported item types

Enumerator
SOLID_T 
LINE_T 
JOINT_T 
SEGMENT_T 
ARC_T 
VIA_T 
DIFF_PAIR_T 
ANY_T 

Definition at line 59 of file pns_item.h.

60  {
61  SOLID_T = 1,
62  LINE_T = 2,
63  JOINT_T = 4,
64  SEGMENT_T = 8,
65  ARC_T = 16,
66  VIA_T = 32,
67  DIFF_PAIR_T = 64,
68  ANY_T = 0xff
69  };

Constructor & Destructor Documentation

◆ LINE() [1/4]

PNS::LINE::LINE ( )
inline

Constructor Makes an empty line.

Definition at line 70 of file pns_line.h.

70  : ITEM( LINE_T )
71  {
72  m_hasVia = false;
73  m_width = 1; // Dummy value
74  m_snapThreshhold = 0;
75  }
ITEM(PnsKind aKind)
Definition: pns_item.h:71
bool m_hasVia
If true, the line ends with a via
Definition: pns_line.h:337
int m_snapThreshhold
Width to smooth out jagged segments
Definition: pns_line.h:340
int m_width
our width
Definition: pns_line.h:334

References m_hasVia, m_snapThreshhold, and m_width.

Referenced by Clone().

◆ LINE() [2/4]

PNS::LINE::LINE ( const LINE aOther)

Definition at line 37 of file pns_line.cpp.

38  : ITEM( aOther ),
39  m_line( aOther.m_line ),
40  m_width( aOther.m_width ),
41  m_snapThreshhold( aOther.m_snapThreshhold )
42 {
43  m_net = aOther.m_net;
44  m_movable = aOther.m_movable;
45  m_layers = aOther.m_layers;
46  m_via = aOther.m_via;
47  m_hasVia = aOther.m_hasVia;
48  m_marker = aOther.m_marker;
49  m_rank = aOther.m_rank;
50 
51  copyLinks( &aOther );
52 }
VIA m_via
Via at the end point, if m_hasVia == true
Definition: pns_line.h:343
LAYER_RANGE m_layers
Definition: pns_item.h:253
int m_rank
Definition: pns_item.h:258
bool m_movable
Definition: pns_item.h:255
ITEM(PnsKind aKind)
Definition: pns_item.h:71
int m_marker
Definition: pns_item.h:257
SHAPE_LINE_CHAIN m_line
The actual shape of the line
Definition: pns_line.h:331
void copyLinks(const LINE *aParent)
Copies m_segmentRefs from the line aParent.
Definition: pns_line.cpp:120
bool m_hasVia
If true, the line ends with a via
Definition: pns_line.h:337
int m_net
Definition: pns_item.h:256
int m_snapThreshhold
Width to smooth out jagged segments
Definition: pns_line.h:340
int m_width
our width
Definition: pns_line.h:334

References copyLinks(), m_hasVia, PNS::ITEM::m_layers, PNS::ITEM::m_marker, PNS::ITEM::m_movable, PNS::ITEM::m_net, PNS::ITEM::m_rank, and m_via.

◆ LINE() [3/4]

PNS::LINE::LINE ( const LINE aBase,
const SHAPE_LINE_CHAIN aLine 
)
inline

Constructor Copies properties (net, layers, etc.) from a base line and replaces the shape by another.

Definition at line 84 of file pns_line.h.

85  : ITEM( aBase ),
86  m_line( aLine ),
87  m_width( aBase.m_width ),
88  m_snapThreshhold( aBase.m_snapThreshhold )
89  {
90  m_net = aBase.m_net;
91  m_layers = aBase.m_layers;
92  m_hasVia = false;
93  }
LAYER_RANGE m_layers
Definition: pns_item.h:253
ITEM(PnsKind aKind)
Definition: pns_item.h:71
SHAPE_LINE_CHAIN m_line
The actual shape of the line
Definition: pns_line.h:331
bool m_hasVia
If true, the line ends with a via
Definition: pns_line.h:337
int m_net
Definition: pns_item.h:256
int m_snapThreshhold
Width to smooth out jagged segments
Definition: pns_line.h:340
int m_width
our width
Definition: pns_line.h:334

References m_hasVia, PNS::ITEM::m_layers, and PNS::ITEM::m_net.

◆ LINE() [4/4]

PNS::LINE::LINE ( const VIA aVia)
inline

Constructor Constructs a LINE for a lone VIA (ie a stitching via).

Parameters
aVia

Definition at line 100 of file pns_line.h.

100  :
101  ITEM( LINE_T )
102  {
103  m_hasVia = true;
104  m_via = aVia;
105  m_width = aVia.Diameter();
106  m_net = aVia.Net();
107  m_layers = aVia.Layers();
108  m_rank = aVia.Rank();
109  m_snapThreshhold = 0;
110  }
VIA m_via
Via at the end point, if m_hasVia == true
Definition: pns_line.h:343
LAYER_RANGE m_layers
Definition: pns_item.h:253
int m_rank
Definition: pns_item.h:258
ITEM(PnsKind aKind)
Definition: pns_item.h:71
bool m_hasVia
If true, the line ends with a via
Definition: pns_line.h:337
int m_net
Definition: pns_item.h:256
int m_snapThreshhold
Width to smooth out jagged segments
Definition: pns_line.h:340
int m_width
our width
Definition: pns_line.h:334

References PNS::VIA::Diameter(), PNS::ITEM::Layers(), m_hasVia, PNS::ITEM::m_layers, PNS::ITEM::m_net, PNS::ITEM::m_rank, m_snapThreshhold, m_via, m_width, PNS::ITEM::Net(), and PNS::ITEM::Rank().

◆ ~LINE()

PNS::LINE::~LINE ( )

Definition at line 55 of file pns_line.cpp.

56 {
57 }

Member Function Documentation

◆ Anchor()

virtual VECTOR2I PNS::ITEM::Anchor ( int  n) const
inlinevirtualinherited

◆ AnchorCount()

virtual int PNS::ITEM::AnchorCount ( ) const
inlinevirtualinherited

Reimplemented in PNS::VIA, PNS::SEGMENT, PNS::ARC, and PNS::SOLID.

Definition at line 231 of file pns_item.h.

232  {
233  return 0;
234  }

◆ AppendVia()

void PNS::LINE::AppendVia ( const VIA aVia)

Definition at line 859 of file pns_line.cpp.

860 {
861  if( m_line.PointCount() > 1 && aVia.Pos() == m_line.CPoint( 0 ) )
862  {
863  Reverse();
864  }
865 
866  m_hasVia = true;
867  m_via = aVia;
868  m_via.SetNet( m_net );
869 }
VIA m_via
Via at the end point, if m_hasVia == true
Definition: pns_line.h:343
int PointCount() const
Function PointCount()
void SetNet(int aNet)
Definition: pns_item.h:148
SHAPE_LINE_CHAIN m_line
The actual shape of the line
Definition: pns_line.h:331
const VECTOR2I & CPoint(int aIndex) const
Function Point()
void Reverse()
Reverses the point/vertex order
Definition: pns_line.cpp:851
bool m_hasVia
If true, the line ends with a via
Definition: pns_line.h:337
int m_net
Definition: pns_item.h:256

References SHAPE_LINE_CHAIN::CPoint(), m_hasVia, m_line, PNS::ITEM::m_net, m_via, SHAPE_LINE_CHAIN::PointCount(), PNS::VIA::Pos(), Reverse(), and PNS::ITEM::SetNet().

Referenced by PNS::LINE_PLACER::buildInitialLine(), PNS::SHOVE::onReverseCollidingVia(), PNS::LINE_PLACER::rhShoveOnly(), PNS::LINE_PLACER::rhWalkOnly(), and PNS::DIFF_PAIR::updateLine().

◆ ArcCount()

int PNS::LINE::ArcCount ( ) const
inline

Returns the number of arcs in the line

Definition at line 162 of file pns_line.h.

163  {
164  return m_line.ArcCount();
165  }
size_t ArcCount() const
SHAPE_LINE_CHAIN m_line
The actual shape of the line
Definition: pns_line.h:331

References SHAPE_LINE_CHAIN::ArcCount(), and m_line.

◆ BelongsTo()

bool PNS::ITEM::BelongsTo ( NODE aNode) const
inlineinherited

Function BelongsTo()

Returns
true if the item is owned by the node aNode.

Definition at line 187 of file pns_item.h.

188  {
189  return m_owner == aNode;
190  }
NODE * m_owner
Definition: pns_item.h:252

References PNS::ITEM::m_owner.

Referenced by PNS::NODE::doRemove().

◆ ChangedArea()

OPT_BOX2I PNS::LINE::ChangedArea ( const LINE aOther) const

Definition at line 956 of file pns_line.cpp.

957 {
958  BOX2I area;
959  bool areaDefined = false;
960 
961  int i_start = -1;
962  int i_end_self = -1, i_end_other = -1;
963 
964  SHAPE_LINE_CHAIN self( m_line );
965  self.Simplify();
966  SHAPE_LINE_CHAIN other( aOther->m_line );
967  other.Simplify();
968 
969  int np_self = self.PointCount();
970  int np_other = other.PointCount();
971 
972  int n = std::min( np_self, np_other );
973 
974  for( int i = 0; i < n; i++ )
975  {
976  const VECTOR2I p1 = self.CPoint( i );
977  const VECTOR2I p2 = other.CPoint( i );
978 
979  if( p1 != p2 )
980  {
981  if( i != n - 1 )
982  {
983  SEG s = self.CSegment( i );
984 
985  if( !s.Contains( p2 ) )
986  {
987  i_start = i;
988  break;
989  }
990  }
991  else
992  {
993  i_start = i;
994  break;
995  }
996  }
997  }
998 
999  for( int i = 0; i < n; i++ )
1000  {
1001  const VECTOR2I p1 = self.CPoint( np_self - 1 - i );
1002  const VECTOR2I p2 = other.CPoint( np_other - 1 - i );
1003 
1004  if( p1 != p2 )
1005  {
1006  i_end_self = np_self - 1 - i;
1007  i_end_other = np_other - 1 - i;
1008  break;
1009  }
1010  }
1011 
1012  if( i_start < 0 )
1013  i_start = n;
1014 
1015  if( i_end_self < 0 )
1016  i_end_self = np_self - 1;
1017 
1018  if( i_end_other < 0 )
1019  i_end_other = np_other - 1;
1020 
1021  for( int i = i_start; i <= i_end_self; i++ )
1022  extendBox( area, areaDefined, self.CPoint( i ) );
1023 
1024  for( int i = i_start; i <= i_end_other; i++ )
1025  extendBox( area, areaDefined, other.CPoint( i ) );
1026 
1027  if( areaDefined )
1028  {
1029  area.Inflate( std::max( Width(), aOther->Width() ) );
1030  return area;
1031  }
1032 
1033  return OPT_BOX2I();
1034 }
const VECTOR2I & CPoint(int aIdx) const
Returns the aIdx-th point of the line
Definition: pns_line.h:168
SHAPE_LINE_CHAIN m_line
The actual shape of the line
Definition: pns_line.h:331
SHAPE_LINE_CHAIN & Simplify()
Function Simplify()
Definition: seg.h:39
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
SHAPE_LINE_CHAIN.
static void extendBox(BOX2I &aBox, bool &aDefined, const VECTOR2I &aP)
Definition: pns_line.cpp:942
int Width() const
Returns line width
Definition: pns_line.h:187
OPT< BOX2I > OPT_BOX2I
Definition: box2.h:524
bool Contains(const SEG &aSeg) const
Definition: seg.h:299

References SEG::Contains(), CPoint(), SHAPE_LINE_CHAIN::CPoint(), PNS::extendBox(), BOX2< Vec >::Inflate(), m_line, SHAPE_LINE_CHAIN::PointCount(), SHAPE_LINE_CHAIN::Simplify(), and Width().

Referenced by PNS::ChangedArea().

◆ ClassOf()

static bool PNS::LINE::ClassOf ( const ITEM aItem)
inlinestatic

Definition at line 114 of file pns_line.h.

115  {
116  return aItem && LINE_T == aItem->Kind();
117  }

References PNS::ITEM::Kind(), and PNS::ITEM::LINE_T.

◆ Clear()

void PNS::LINE::Clear ( )

Definition at line 1047 of file pns_line.cpp.

1048 {
1049  m_hasVia = false;
1050  m_line.Clear();
1051 }
SHAPE_LINE_CHAIN m_line
The actual shape of the line
Definition: pns_line.h:331
bool m_hasVia
If true, the line ends with a via
Definition: pns_line.h:337
void Clear()
Function Clear() Removes all points from the line chain.

References SHAPE_LINE_CHAIN::Clear(), m_hasVia, and m_line.

◆ ClearSegmentLinks()

void PNS::LINE::ClearSegmentLinks ( )

Erases the linking information. Used to detach the line from the owning node.

Definition at line 936 of file pns_line.cpp.

937 {
938  m_segmentRefs.clear();
939 }
SEGMENT_REFS m_segmentRefs
List of segments in the owning NODE (ITEM::m_owner) that constitute this line, or NULL if the line is...
Definition: pns_line.h:328

References m_segmentRefs.

Referenced by PNS::DRAGGER::dragMarkObstacles(), PNS::DRAGGER::dragShove(), PNS::DRAGGER::dragViaMarkObstacles(), PNS::DRAGGER::dragViaWalkaround(), PNS::SHOVE::onCollidingSolid(), PNS::SHOVE::onReverseCollidingVia(), PNS::DRAGGER::optimizeAndUpdateDraggedLine(), PNS::SHOVE::ProcessSingleLine(), PNS::NODE::Remove(), PNS::SHOVE::ShoveLines(), and PNS::SHOVE::ShoveMultiLines().

◆ CLine()

const SHAPE_LINE_CHAIN& PNS::LINE::CLine ( ) const
inline

Const accessor to the underlying shape

Definition at line 144 of file pns_line.h.

145  {
146  return m_line;
147  }
SHAPE_LINE_CHAIN m_line
The actual shape of the line
Definition: pns_line.h:331

References m_line.

Referenced by PNS::COST_ESTIMATOR::Add(), PNS::DIFF_PAIR_PLACER::attemptWalk(), PNS::KEEP_TOPOLOGY_CONSTRAINT::Check(), PNS::SHOVE::checkBumpDirection(), PNS::NODE::CheckColliding(), PNS::COST_ESTIMATOR::CornerCost(), PNS::DIFF_PAIR::DIFF_PAIR(), PNS::MEANDER_PLACER::doMove(), PNS::DRAGGER::dragShove(), PNS::DRAGGER::dragViaMarkObstacles(), PNS::DRAGGER::dragViaWalkaround(), PNS::DRAGGER::dragWalkaround(), PNS::OPTIMIZER::fanoutCleanup(), PNS::NODE::FindLinesBetweenJoints(), PNS::LINE_PLACER::FixRoute(), PNS::TOPOLOGY::followTrivialPath(), PNS::LINE_PLACER::Move(), PNS::NODE::NearestObstacle(), PNS::SHOVE::onCollidingArc(), PNS::SHOVE::onCollidingSegment(), PNS::SHOVE::onReverseCollidingVia(), PNS::DRAGGER::optimizeAndUpdateDraggedLine(), PNS::LINE_PLACER::optimizeTailHeadTransition(), PNS::SHOVE::processHullSet(), PNS::LINE_PLACER::reduceToNearestObstacle(), PNS::COST_ESTIMATOR::Remove(), PNS::LINE_PLACER::removeLoops(), PNS::COST_ESTIMATOR::Replace(), PNS::LINE_PLACER::rhMarkObstacles(), PNS::LINE_PLACER::rhShoveOnly(), PNS::LINE_PLACER::rhStopAtNearestObstacle(), PNS::LINE_PLACER::rhWalkOnly(), PNS::WALKAROUND::Route(), PNS::SHOVE::runOptimizer(), PNS::TOPOLOGY::SimplifyLine(), PNS::LINE_PLACER::simplifyNewLine(), PNS::WALKAROUND::singleStep(), PNS::OPTIMIZER::smartPadsSingle(), PNS::Tighten(), PNS::LINE_PLACER::Trace(), and Walkaround().

◆ ClipToNearestObstacle()

const LINE PNS::LINE::ClipToNearestObstacle ( NODE aNode) const

Clips the line to the nearest obstacle, traversing from the line's start vertex (0).

Returns the clipped line.

Definition at line 437 of file pns_line.cpp.

438 {
439  const int IterationLimit = 5;
440  int i;
441  LINE l( *this );
442 
443  for( i = 0; i < IterationLimit; i++ )
444  {
445  NODE::OPT_OBSTACLE obs = aNode->NearestObstacle( &l );
446 
447  if( obs )
448  {
449  l.RemoveVia();
450  int p = l.Line().Split( obs->m_ipFirst );
451  l.Line().Remove( p + 1, -1 );
452  } else
453  break;
454  }
455 
456  if( i == IterationLimit )
457  l.Line().Clear();
458 
459  return l;
460 }
LINE()
Constructor Makes an empty line.
Definition: pns_line.h:70
OPT< OBSTACLE > OPT_OBSTACLE
Definition: pns_node.h:148

References SHAPE_LINE_CHAIN::Clear(), Line(), PNS::NODE::NearestObstacle(), SHAPE_LINE_CHAIN::Remove(), RemoveVia(), and SHAPE_LINE_CHAIN::Split().

Referenced by PNS::LINE_PLACER::rhShoveOnly(), PNS::LINE_PLACER::rhWalkOnly(), and PNS::WALKAROUND::singleStep().

◆ ClipVertexRange()

void PNS::LINE::ClipVertexRange ( int  aStart,
int  aEnd 
)

Clips the line to a given range of vertices.

Definition at line 901 of file pns_line.cpp.

902 {
903  m_line = m_line.Slice( aStart, aEnd );
904 
905  if( IsLinked() ) {
906  assert( m_segmentRefs.size() < INT_MAX );
907  assert( (int) m_segmentRefs.size() >= (aEnd - aStart) );
908 
909  // Note: The range includes aEnd, but we have n-1 segments.
910  std::rotate(
911  m_segmentRefs.begin(),
912  m_segmentRefs.begin() + aStart,
913  m_segmentRefs.begin() + aEnd
914  );
915 
916  m_segmentRefs.resize( aEnd - aStart );
917  }
918 }
const SHAPE_LINE_CHAIN Slice(int aStartIndex, int aEndIndex=-1) const
Function Slice()
SHAPE_LINE_CHAIN m_line
The actual shape of the line
Definition: pns_line.h:331
SEGMENT_REFS m_segmentRefs
List of segments in the owning NODE (ITEM::m_owner) that constitute this line, or NULL if the line is...
Definition: pns_line.h:328
bool IsLinked() const
Definition: pns_line.h:214

References IsLinked(), m_line, m_segmentRefs, and SHAPE_LINE_CHAIN::Slice().

Referenced by PNS::NODE::FindLinesBetweenJoints().

◆ Clone()

LINE * PNS::LINE::Clone ( ) const
overridevirtual

Function Clone()

Returns a deep copy of the item

Implements PNS::ITEM.

Definition at line 80 of file pns_line.cpp.

81 {
82  LINE* l = new LINE( *this );
83 
84  return l;
85 }
LINE()
Constructor Makes an empty line.
Definition: pns_line.h:70

References LINE().

Referenced by PNS::ITEM_SET::Add(), and PNS::ITEM_SET::Prepend().

◆ Collide()

bool PNS::ITEM::Collide ( const ITEM aOther,
int  aClearance,
bool  aNeedMTV,
VECTOR2I aMTV,
const NODE aParentNode,
bool  aDifferentNetsOnly = true 
) const
virtualinherited

Function Collide()

Checks for a collision (clearance violation) with between us and item aOther. Collision checking takes all PCB stuff into accound (layers, nets, DRC rules). Optionally returns a minimum translation vector for force propagation algorithm.

Parameters
aOtheritem to check collision against
aClearancedesired clearance
aNeedMTVwhen true, the minimum translation vector is calculated
aMTVthe minimum translation vector
Returns
true, if a collision was found.

Definition at line 48 of file pns_item.cpp.

50 {
51  if( collideSimple( aOther, aClearance, aNeedMTV, aMTV, aParentNode, aDifferentNetsOnly ) )
52  return true;
53 
54  // special case for "head" line with a via attached at the end.
55  if( aOther->m_kind == LINE_T )
56  {
57  const LINE* line = static_cast<const LINE*>( aOther );
58  int clearance = aClearance - line->Width() / 2;
59 
60  if( line->EndsWithVia() )
61  {
62  return collideSimple( &line->Via(), clearance, aNeedMTV, aMTV, aParentNode,
63  aDifferentNetsOnly );
64  }
65  }
66 
67  return false;
68 }
bool collideSimple(const ITEM *aOther, int aClearance, bool aNeedMTV, VECTOR2I *aMTV, const NODE *aParentNode, bool aDifferentNetsOnly) const
Definition: pns_item.cpp:30

References PNS::ITEM::collideSimple(), EndsWithVia(), PNS::ITEM::LINE_T, PNS::ITEM::m_kind, Via(), and Width().

Referenced by PNS::NODE::CheckColliding(), PNS::OPTIMIZER::CACHE_VISITOR::operator()(), and PNS::NODE::DEFAULT_OBSTACLE_VISITOR::operator()().

◆ CompareGeometry()

bool PNS::LINE::CompareGeometry ( const LINE aOther)

Returns true if the line is geometrically identical as line aOther

Definition at line 845 of file pns_line.cpp.

846 {
847  return m_line.CompareGeometry( aOther.m_line );
848 }
SHAPE_LINE_CHAIN m_line
The actual shape of the line
Definition: pns_line.h:331
bool CompareGeometry(const SHAPE_LINE_CHAIN &aOther) const

References SHAPE_LINE_CHAIN::CompareGeometry(), and m_line.

◆ ContainsSegment()

bool PNS::LINE::ContainsSegment ( LINKED_ITEM aSeg) const
inline

Checks if the segment aSeg is a part of the line.

Definition at line 225 of file pns_line.h.

226  {
227  return std::find( m_segmentRefs.begin(), m_segmentRefs.end(),
228  aSeg ) != m_segmentRefs.end();
229  }
SEGMENT_REFS m_segmentRefs
List of segments in the owning NODE (ITEM::m_owner) that constitute this line, or NULL if the line is...
Definition: pns_line.h:328

References m_segmentRefs.

◆ copyLinks()

void PNS::LINE::copyLinks ( const LINE aParent)
private

Copies m_segmentRefs from the line aParent.

Definition at line 120 of file pns_line.cpp.

121 {
122  m_segmentRefs = aParent->m_segmentRefs;
123 }
SEGMENT_REFS m_segmentRefs
List of segments in the owning NODE (ITEM::m_owner) that constitute this line, or NULL if the line is...
Definition: pns_line.h:328

References m_segmentRefs.

Referenced by LINE(), and operator=().

◆ CountCorners()

int PNS::LINE::CountCorners ( int  aAngles) const

Returns the number of corners of angles specified by mask aAngles.

Definition at line 140 of file pns_line.cpp.

141 {
142  int count = 0;
143 
144  for( int i = 0; i < m_line.SegmentCount() - 1; i++ )
145  {
146  const SEG seg1 = m_line.CSegment( i );
147  const SEG seg2 = m_line.CSegment( i + 1 );
148 
149  const DIRECTION_45 dir1( seg1 );
150  const DIRECTION_45 dir2( seg2 );
151 
152  DIRECTION_45::AngleType a = dir1.Angle( dir2 );
153 
154  if( a & aAngles )
155  count++;
156  }
157 
158  return count;
159 }
SHAPE_LINE_CHAIN m_line
The actual shape of the line
Definition: pns_line.h:331
DIRECTION_45.
Definition: direction45.h:37
int SegmentCount() const
Function SegmentCount()
Definition: seg.h:39
AngleType
Enum AngleType Represents kind of angle formed by vectors heading in two DIRECTION_45s.
Definition: direction45.h:64
const SEG CSegment(int aIndex) const
Function CSegment()

References DIRECTION_45::Angle(), SHAPE_LINE_CHAIN::CSegment(), m_line, and SHAPE_LINE_CHAIN::SegmentCount().

Referenced by PNS::LINE_PLACER::mergeHead(), and PNS::OPTIMIZER::smartPadsSingle().

◆ CPoint()

◆ CSegment()

const SEG PNS::LINE::CSegment ( int  aIdx) const
inline

Returns the aIdx-th segment of the line

Definition at line 174 of file pns_line.h.

175  {
176  return m_line.CSegment( aIdx );
177  }
SHAPE_LINE_CHAIN m_line
The actual shape of the line
Definition: pns_line.h:331
const SEG CSegment(int aIndex) const
Function CSegment()

References SHAPE_LINE_CHAIN::CSegment(), and m_line.

Referenced by PNS::ANGLE_CONSTRAINT_45::Check(), PNS::DIFF_PAIR::EndingPrimitives(), PNS::LINE_PLACER::FixRoute(), PNS::OPTIMIZER::mergeStep(), PNS::LINE_PLACER::optimizeTailHeadTransition(), and PNS::SHOVE::ProcessSingleLine().

◆ DragCorner()

void PNS::LINE::DragCorner ( const VECTOR2I aP,
int  aIndex,
bool  aFreeAngle = false 
)

Definition at line 583 of file pns_line.cpp.

584 {
585  if( aFreeAngle )
586  {
587  dragCornerFree( aP, aIndex );
588  }
589  else
590  {
591  dragCorner45( aP, aIndex );
592  }
593 }
void dragCorner45(const VECTOR2I &aP, int aIndex)
Definition: pns_line.cpp:554
void dragCornerFree(const VECTOR2I &aP, int aIndex)
Definition: pns_line.cpp:577

References dragCorner45(), and dragCornerFree().

Referenced by PNS::DRAGGER::dragMarkObstacles(), PNS::DRAGGER::dragShove(), PNS::DRAGGER::dragViaMarkObstacles(), PNS::DRAGGER::dragViaWalkaround(), and PNS::DRAGGER::dragWalkaround().

◆ dragCorner45()

void PNS::LINE::dragCorner45 ( const VECTOR2I aP,
int  aIndex 
)
private

Definition at line 554 of file pns_line.cpp.

555 {
556  SHAPE_LINE_CHAIN path;
557 
558  VECTOR2I snapped = snapDraggedCorner( m_line, aP, aIndex );
559 
560  if( aIndex == 0 )
561  path = dragCornerInternal( m_line.Reverse(), snapped ).Reverse();
562  else if( aIndex == m_line.SegmentCount() )
563  path = dragCornerInternal( m_line, snapped );
564  else
565  {
566  // fixme: awkward behaviour for "outwards" drags
567  path = dragCornerInternal( m_line.Slice( 0, aIndex ), snapped );
568  SHAPE_LINE_CHAIN path_rev =
569  dragCornerInternal( m_line.Slice( aIndex, -1 ).Reverse(), snapped ).Reverse();
570  path.Append( path_rev );
571  }
572 
573  path.Simplify();
574  m_line = path;
575 }
const SHAPE_LINE_CHAIN Slice(int aStartIndex, int aEndIndex=-1) const
Function Slice()
const SHAPE_LINE_CHAIN Reverse() const
Function Reverse()
void Append(int aX, int aY, bool aAllowDuplication=false)
Function Append()
SHAPE_LINE_CHAIN dragCornerInternal(const SHAPE_LINE_CHAIN &aOrigin, const VECTOR2I &aP)
Definition: pns_line.cpp:478
SHAPE_LINE_CHAIN m_line
The actual shape of the line
Definition: pns_line.h:331
SHAPE_LINE_CHAIN & Simplify()
Function Simplify()
void Reverse()
Reverses the point/vertex order
Definition: pns_line.cpp:851
int SegmentCount() const
Function SegmentCount()
SHAPE_LINE_CHAIN.
VECTOR2I snapDraggedCorner(const SHAPE_LINE_CHAIN &aPath, const VECTOR2I &aP, int aIndex) const
Definition: pns_line.cpp:607

References SHAPE_LINE_CHAIN::Append(), PNS::dragCornerInternal(), m_line, Reverse(), SHAPE_LINE_CHAIN::Reverse(), SHAPE_LINE_CHAIN::SegmentCount(), SHAPE_LINE_CHAIN::Simplify(), SHAPE_LINE_CHAIN::Slice(), and snapDraggedCorner().

Referenced by DragCorner().

◆ dragCornerFree()

void PNS::LINE::dragCornerFree ( const VECTOR2I aP,
int  aIndex 
)
private

Definition at line 577 of file pns_line.cpp.

578 {
579  m_line.SetPoint( aIndex, aP );
580  m_line.Simplify();
581 }
void SetPoint(int aIndex, const VECTOR2I &aPos)
Accessor Function to move a point to a specific location.
SHAPE_LINE_CHAIN m_line
The actual shape of the line
Definition: pns_line.h:331
SHAPE_LINE_CHAIN & Simplify()
Function Simplify()

References m_line, SHAPE_LINE_CHAIN::SetPoint(), and SHAPE_LINE_CHAIN::Simplify().

Referenced by DragCorner().

◆ DragSegment()

void PNS::LINE::DragSegment ( const VECTOR2I aP,
int  aIndex,
bool  aFreeAngle = false 
)

Definition at line 595 of file pns_line.cpp.

596 {
597  if( aFreeAngle )
598  {
599  assert( false );
600  }
601  else
602  {
603  dragSegment45( aP, aIndex );
604  }
605 }
void dragSegment45(const VECTOR2I &aP, int aIndex)
Definition: pns_line.cpp:694

References dragSegment45().

Referenced by PNS::DRAGGER::dragMarkObstacles(), PNS::DRAGGER::dragShove(), and PNS::DRAGGER::dragWalkaround().

◆ dragSegment45()

void PNS::LINE::dragSegment45 ( const VECTOR2I aP,
int  aIndex 
)
private

Definition at line 694 of file pns_line.cpp.

695 {
696  SHAPE_LINE_CHAIN path( m_line );
697  VECTOR2I target( aP );
698 
699  SEG guideA[2], guideB[2];
700  int index = aIndex;
701 
702  target = snapToNeighbourSegments( path, aP, aIndex );
703 
704  if( index == 0 )
705  {
706  path.Insert( 0, path.CPoint( 0 ) );
707  index++;
708  }
709 
710  if( index == path.SegmentCount() - 1 )
711  {
712  path.Insert( path.PointCount() - 1, path.CPoint( -1 ) );
713  }
714 
715  SEG dragged = path.CSegment( index );
716  DIRECTION_45 drag_dir( dragged );
717 
718  SEG s_prev = path.CSegment( index - 1 );
719  SEG s_next = path.CSegment( index + 1 );
720 
721  DIRECTION_45 dir_prev( s_prev );
722  DIRECTION_45 dir_next( s_next );
723 
724  if( dir_prev == drag_dir )
725  {
726  dir_prev = dir_prev.Left();
727  path.Insert( index, path.CPoint( index ) );
728  index++;
729  }
730 
731  if( dir_next == drag_dir )
732  {
733  dir_next = dir_next.Right();
734  path.Insert( index + 1, path.CPoint( index + 1 ) );
735  }
736 
737  s_prev = path.CSegment( index - 1 );
738  s_next = path.CSegment( index + 1 );
739  dragged = path.CSegment( index );
740 
741  if( aIndex == 0 )
742  {
743  guideA[0] = SEG( dragged.A, dragged.A + drag_dir.Right().ToVector() );
744  guideA[1] = SEG( dragged.A, dragged.A + drag_dir.Left().ToVector() );
745  }
746  else
747  {
748  if( dir_prev.Angle( drag_dir )
750  {
751  guideA[0] = SEG( s_prev.A, s_prev.A + drag_dir.Left().ToVector() );
752  guideA[1] = SEG( s_prev.A, s_prev.A + drag_dir.Right().ToVector() );
753  }
754  else
755  guideA[0] = guideA[1] = SEG( dragged.A, dragged.A + dir_prev.ToVector() );
756  }
757 
758  if( aIndex == m_line.SegmentCount() - 1 )
759  {
760  guideB[0] = SEG( dragged.B, dragged.B + drag_dir.Right().ToVector() );
761  guideB[1] = SEG( dragged.B, dragged.B + drag_dir.Left().ToVector() );
762  }
763  else
764  {
765  if( dir_next.Angle( drag_dir )
767  {
768  guideB[0] = SEG( s_next.B, s_next.B + drag_dir.Left().ToVector() );
769  guideB[1] = SEG( s_next.B, s_next.B + drag_dir.Right().ToVector() );
770  }
771  else
772  guideB[0] = guideB[1] = SEG( dragged.B, dragged.B + dir_next.ToVector() );
773  }
774 
775  SEG s_current( target, target + drag_dir.ToVector() );
776 
777  int best_len = INT_MAX;
778  SHAPE_LINE_CHAIN best;
779 
780  for( int i = 0; i < 2; i++ )
781  {
782  for( int j = 0; j < 2; j++ )
783  {
784  OPT_VECTOR2I ip1 = s_current.IntersectLines( guideA[i] );
785  OPT_VECTOR2I ip2 = s_current.IntersectLines( guideB[j] );
786 
787  SHAPE_LINE_CHAIN np;
788 
789  if( !ip1 || !ip2 )
790  continue;
791 
792  SEG s1( s_prev.A, *ip1 );
793  SEG s2( *ip1, *ip2 );
794  SEG s3( *ip2, s_next.B );
795 
796  OPT_VECTOR2I ip;
797 
798  if( ( ip = s1.Intersect( s_next ) ) )
799  {
800  np.Append( s1.A );
801  np.Append( *ip );
802  np.Append( s_next.B );
803  }
804  else if( ( ip = s3.Intersect( s_prev ) ) )
805  {
806  np.Append( s_prev.A );
807  np.Append( *ip );
808  np.Append( s3.B );
809  }
810  else if( ( ip = s1.Intersect( s3 ) ) )
811  {
812  np.Append( s_prev.A );
813  np.Append( *ip );
814  np.Append( s_next.B );
815  }
816  else
817  {
818  np.Append( s_prev.A );
819  np.Append( *ip1 );
820  np.Append( *ip2 );
821  np.Append( s_next.B );
822  }
823 
824  if( np.Length() < best_len )
825  {
826  best_len = np.Length();
827  best = np;
828  }
829  }
830  }
831 
832  if( m_line.PointCount() == 1 )
833  m_line = best;
834  else if( aIndex == 0 )
835  m_line.Replace( 0, 1, best );
836  else if( aIndex == m_line.SegmentCount() - 1 )
837  m_line.Replace( -2, -1, best );
838  else
839  m_line.Replace( aIndex, aIndex + 1, best );
840 
841  m_line.Simplify();
842 }
long long int Length() const
Function Length()
VECTOR2I snapToNeighbourSegments(const SHAPE_LINE_CHAIN &aPath, const VECTOR2I &aP, int aIndex) const
Definition: pns_line.cpp:649
int PointCount() const
Function PointCount()
void Append(int aX, int aY, bool aAllowDuplication=false)
Function Append()
SHAPE_LINE_CHAIN m_line
The actual shape of the line
Definition: pns_line.h:331
SHAPE_LINE_CHAIN & Simplify()
Function Simplify()
OPT< VECTOR2I > OPT_VECTOR2I
Definition: seg.h:37
DIRECTION_45.
Definition: direction45.h:37
int SegmentCount() const
Function SegmentCount()
Definition: seg.h:39
SHAPE_LINE_CHAIN.
VECTOR2I A
Definition: seg.h:47
void Replace(int aStartIndex, int aEndIndex, const VECTOR2I &aP)
Function Replace()
VECTOR2I B
Definition: seg.h:48

References SEG::A, DIRECTION_45::ANG_HALF_FULL, DIRECTION_45::ANG_OBTUSE, DIRECTION_45::Angle(), SHAPE_LINE_CHAIN::Append(), SEG::B, SHAPE_LINE_CHAIN::CPoint(), SHAPE_LINE_CHAIN::CSegment(), SHAPE_LINE_CHAIN::Insert(), SEG::Intersect(), DIRECTION_45::Left(), SHAPE_LINE_CHAIN::Length(), m_line, SHAPE_LINE_CHAIN::PointCount(), SHAPE_LINE_CHAIN::Replace(), DIRECTION_45::Right(), SHAPE_LINE_CHAIN::SegmentCount(), SHAPE_LINE_CHAIN::Simplify(), snapToNeighbourSegments(), and DIRECTION_45::ToVector().

Referenced by DragSegment().

◆ dragSegmentFree()

void PNS::LINE::dragSegmentFree ( const VECTOR2I aP,
int  aIndex 
)
private

◆ EndsWithVia()

◆ GetLink()

LINKED_ITEM* PNS::LINE::GetLink ( int  aIndex) const
inline

Definition at line 231 of file pns_line.h.

232  {
233  return m_segmentRefs[aIndex];
234  }
SEGMENT_REFS m_segmentRefs
List of segments in the owning NODE (ITEM::m_owner) that constitute this line, or NULL if the line is...
Definition: pns_line.h:328

References m_segmentRefs.

Referenced by PNS::LINE_PLACER::removeLoops(), PNS::TOPOLOGY::SimplifyLine(), PNS::MEANDER_SKEW_PLACER::Start(), and PNS::DP_MEANDER_PLACER::Start().

◆ GetSnapThreshhold()

int PNS::LINE::GetSnapThreshhold ( ) const
inline

Definition at line 306 of file pns_line.h.

307  {
308  return m_snapThreshhold;
309  }
int m_snapThreshhold
Width to smooth out jagged segments
Definition: pns_line.h:340

References m_snapThreshhold.

◆ HasLockedSegments()

bool PNS::LINE::HasLockedSegments ( ) const

Definition at line 1037 of file pns_line.cpp.

1038 {
1039  for( const auto seg : m_segmentRefs )
1040  {
1041  if( seg->Marker() & MK_LOCKED )
1042  return true;
1043  }
1044  return false;
1045 }
SEGMENT_REFS m_segmentRefs
List of segments in the owning NODE (ITEM::m_owner) that constitute this line, or NULL if the line is...
Definition: pns_line.h:328

References m_segmentRefs, and PNS::MK_LOCKED.

Referenced by PNS::SHOVE::onCollidingArc(), and PNS::SHOVE::onCollidingSegment().

◆ HasLoops()

bool PNS::LINE::HasLoops ( ) const

Definition at line 921 of file pns_line.cpp.

922 {
923  for( int i = 0; i < PointCount(); i++ )
924  {
925  for( int j = i + 2; j < PointCount(); j++ )
926  {
927  if( CPoint( i ) == CPoint( j ) )
928  return true;
929  }
930  }
931 
932  return false;
933 }
int PointCount() const
Returns the number of points in the line
Definition: pns_line.h:156
const VECTOR2I & CPoint(int aIdx) const
Returns the aIdx-th point of the line
Definition: pns_line.h:168

References CPoint(), and PointCount().

Referenced by PNS::SHOVE::onCollidingSolid(), and PNS::LINE_PLACER::rhShoveOnly().

◆ Hull()

virtual const SHAPE_LINE_CHAIN PNS::ITEM::Hull ( int  aClearance = 0,
int  aWalkaroundThickness = 0 
) const
inlinevirtualinherited

Reimplemented in PNS::VIA, PNS::SEGMENT, PNS::ARC, and PNS::SOLID.

Definition at line 113 of file pns_item.h.

114  {
115  return SHAPE_LINE_CHAIN();
116  }
SHAPE_LINE_CHAIN.

◆ Is45Degree()

bool PNS::LINE::Is45Degree ( ) const

Definition at line 408 of file pns_line.cpp.

409 {
410  for( int i = 0; i < m_line.SegmentCount(); i++ )
411  {
412  const SEG& s = m_line.CSegment( i );
413 
414  if( m_line.isArc( i ) )
415  continue;
416 
417  if( s.Length() < 10 )
418  continue;
419 
420  double angle = 180.0 / M_PI *
421  atan2( (double) s.B.y - (double) s.A.y,
422  (double) s.B.x - (double) s.A.x );
423 
424  if( angle < 0 )
425  angle += 360.0;
426 
427  double angle_a = fabs( fmod( angle, 45.0 ) );
428 
429  if( angle_a > 1.0 && angle_a < 44.0 )
430  return false;
431  }
432 
433  return true;
434 }
int Length() const
Function Length()
Definition: seg.h:319
bool isArc(size_t aSegment) const
SHAPE_LINE_CHAIN m_line
The actual shape of the line
Definition: pns_line.h:331
int SegmentCount() const
Function SegmentCount()
Definition: seg.h:39
const SEG CSegment(int aIndex) const
Function CSegment()
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
VECTOR2I A
Definition: seg.h:47
VECTOR2I B
Definition: seg.h:48

References SEG::A, PNS::angle(), SEG::B, SHAPE_LINE_CHAIN::CSegment(), SHAPE_LINE_CHAIN::isArc(), SEG::Length(), m_line, SHAPE_LINE_CHAIN::SegmentCount(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by PNS::LINE_PLACER::routeStep().

◆ IsLinked()

bool PNS::LINE::IsLinked ( ) const
inline

Definition at line 214 of file pns_line.h.

215  {
216  return m_segmentRefs.size() != 0;
217  }
SEGMENT_REFS m_segmentRefs
List of segments in the owning NODE (ITEM::m_owner) that constitute this line, or NULL if the line is...
Definition: pns_line.h:328

References m_segmentRefs.

Referenced by PNS::NODE::Add(), ClipVertexRange(), PNS::TOPOLOGY::followTrivialPath(), IsLinkedChecked(), PNS::DIFF_PAIR::NLine(), PNS::DIFF_PAIR::PLine(), Rank(), PNS::OPTIMIZER::removeCachedSegments(), ShowLinks(), and PNS::TOPOLOGY::SimplifyLine().

◆ IsLinkedChecked()

bool PNS::LINE::IsLinkedChecked ( ) const
inline

Definition at line 219 of file pns_line.h.

220  {
221  return IsLinked() && LinkCount() == SegmentCount();
222  }
int SegmentCount() const
Returns the number of segments in the line
Definition: pns_line.h:150
bool IsLinked() const
Definition: pns_line.h:214
int LinkCount() const
Returns the number of segments that were assembled together to form this line.
Definition: pns_line.h:240

References IsLinked(), LinkCount(), and SegmentCount().

Referenced by PNS::SHOVE::pushLineStack().

◆ IsLocked()

bool PNS::ITEM::IsLocked ( ) const
inlineinherited

Definition at line 236 of file pns_item.h.

237  {
238  return Marker() & MK_LOCKED;
239  }
virtual int Marker() const
Definition: pns_item.h:221

References PNS::ITEM::Marker(), and PNS::MK_LOCKED.

Referenced by ROUTER_TOOL::InlineBreakTrack(), ROUTER_TOOL::InlineDrag(), ROUTER_TOOL::performDragging(), and PNS::SHOVE::pushOrShoveVia().

◆ IsRoutable()

bool PNS::ITEM::IsRoutable ( ) const
inlineinherited

Definition at line 242 of file pns_item.h.

242 { return m_routable; }
bool m_routable
Definition: pns_item.h:259

References PNS::ITEM::m_routable.

Referenced by PNS::NODE::addSolid().

◆ Kind()

◆ KindStr()

std::string PNS::ITEM::KindStr ( ) const
inherited

Function KindStr()

Returns the kind of the item, as string

Definition at line 71 of file pns_item.cpp.

72 {
73  switch( m_kind )
74  {
75  case ARC_T: return "arc";
76  case LINE_T: return "line";
77  case SEGMENT_T: return "segment";
78  case VIA_T: return "via";
79  case JOINT_T: return "joint";
80  case SOLID_T: return "solid";
81  default: return "unknown";
82  }
83 }
PnsKind m_kind
Definition: pns_item.h:249

References PNS::ITEM::ARC_T, PNS::ITEM::JOINT_T, PNS::ITEM::LINE_T, PNS::ITEM::m_kind, PNS::ITEM::SEGMENT_T, PNS::ITEM::SOLID_T, and PNS::ITEM::VIA_T.

Referenced by PNS::TOOL_BASE::pickSingleItem(), and PNS::TOOL_BASE::updateEndItem().

◆ Layer()

virtual int PNS::ITEM::Layer ( ) const
inlinevirtualinherited

Definition at line 155 of file pns_item.h.

155 { return Layers().Start(); }
int Start() const
Definition: pns_layerset.h:83
const LAYER_RANGE & Layers() const
Definition: pns_item.h:151

References PNS::ITEM::Layers(), and LAYER_RANGE::Start().

Referenced by PNS::OPTIMIZER::fanoutCleanup(), and PNS::OPTIMIZER::runSmartPads().

◆ Layers()

◆ LayersOverlap()

bool PNS::ITEM::LayersOverlap ( const ITEM aOther) const
inlineinherited

Function LayersOverlap()

Returns true if the set of layers spanned by aOther overlaps our layers.

Definition at line 163 of file pns_item.h.

164  {
165  return Layers().Overlaps( aOther->Layers() );
166  }
bool Overlaps(const LAYER_RANGE &aOther) const
Definition: pns_layerset.h:68
const LAYER_RANGE & Layers() const
Definition: pns_item.h:151

References PNS::ITEM::Layers(), and LAYER_RANGE::Overlaps().

Referenced by PNS::SHOVE::onCollidingArc(), PNS::SHOVE::onCollidingSegment(), PNS::SHOVE::ProcessSingleLine(), and PNS::NODE::rebuildJoint().

◆ Line()

◆ LinkCount()

int PNS::LINE::LinkCount ( ) const
inline

Returns the number of segments that were assembled together to form this line.

Definition at line 240 of file pns_line.h.

241  {
242  return m_segmentRefs.size();
243  }
SEGMENT_REFS m_segmentRefs
List of segments in the owning NODE (ITEM::m_owner) that constitute this line, or NULL if the line is...
Definition: pns_line.h:328

References m_segmentRefs.

Referenced by IsLinkedChecked(), and PNS::LINE_PLACER::removeLoops().

◆ LinkedSegments()

SEGMENT_REFS& PNS::LINE::LinkedSegments ( )
inline

Returns the list of segments from the owning node that constitute this line (or NULL if the line is not linked)

Definition at line 209 of file pns_line.h.

210  {
211  return m_segmentRefs;
212  }
SEGMENT_REFS m_segmentRefs
List of segments in the owning NODE (ITEM::m_owner) that constitute this line, or NULL if the line is...
Definition: pns_line.h:328

References m_segmentRefs.

Referenced by PNS::NODE::Dump(), PNS::TOPOLOGY::followTrivialPath(), PNS::SHOVE::popLineStack(), PNS::SHOVE::ProcessSingleLine(), PNS::NODE::Remove(), PNS::OPTIMIZER::removeCachedSegments(), and PNS::SHOVE::unwindLineStack().

◆ LinkSegment()

void PNS::LINE::LinkSegment ( LINKED_ITEM aSeg)
inline

Adds a reference to a segment registered in a NODE that is a part of this line.

Definition at line 202 of file pns_line.h.

203  {
204  m_segmentRefs.push_back( aSeg );
205  }
SEGMENT_REFS m_segmentRefs
List of segments in the owning NODE (ITEM::m_owner) that constitute this line, or NULL if the line is...
Definition: pns_line.h:328

References m_segmentRefs.

Referenced by PNS::NODE::Add(), and PNS::NODE::AssembleLine().

◆ Mark()

void PNS::LINE::Mark ( int  aMarker)
overridevirtual

Reimplemented from PNS::ITEM.

Definition at line 88 of file pns_line.cpp.

89 {
90  m_marker = aMarker;
91 
92  for( auto s : m_segmentRefs )
93  s->Mark( aMarker );
94 
95 }
int m_marker
Definition: pns_item.h:257
SEGMENT_REFS m_segmentRefs
List of segments in the owning NODE (ITEM::m_owner) that constitute this line, or NULL if the line is...
Definition: pns_line.h:328

References PNS::ITEM::m_marker, and m_segmentRefs.

Referenced by PNS::SHOVE::onCollidingSolid(), PNS::SHOVE::ProcessSingleLine(), PNS::SHOVE::ShoveLines(), and PNS::SHOVE::ShoveMultiLines().

◆ Marker()

int PNS::LINE::Marker ( ) const
overridevirtual

Reimplemented from PNS::ITEM.

Definition at line 107 of file pns_line.cpp.

108 {
109  int marker = m_marker;
110 
111  for( auto s : m_segmentRefs )
112  {
113  marker |= s->Marker();
114  }
115 
116  return marker;
117 }
int m_marker
Definition: pns_item.h:257
SEGMENT_REFS m_segmentRefs
List of segments in the owning NODE (ITEM::m_owner) that constitute this line, or NULL if the line is...
Definition: pns_line.h:328

References PNS::ITEM::m_marker, and m_segmentRefs.

Referenced by PNS::ARC::ARC(), PNS::SHOVE::onCollidingArc(), PNS::SHOVE::onCollidingLine(), PNS::SHOVE::onCollidingSegment(), PNS::SHOVE::onCollidingSolid(), PNS::SHOVE::processHullSet(), PNS::SHOVE::ProcessSingleLine(), and PNS::SEGMENT::SEGMENT().

◆ Merge()

void PNS::LINE::Merge ( const LINE aOther)

◆ Net()

◆ OfKind()

◆ operator=()

LINE & PNS::LINE::operator= ( const LINE aOther)

Definition at line 60 of file pns_line.cpp.

61 {
62  m_line = aOther.m_line;
63  m_width = aOther.m_width;
64  m_net = aOther.m_net;
65  m_movable = aOther.m_movable;
66  m_layers = aOther.m_layers;
67  m_via = aOther.m_via;
68  m_hasVia = aOther.m_hasVia;
69  m_marker = aOther.m_marker;
70  m_rank = aOther.m_rank;
71  m_owner = aOther.m_owner;
72  m_snapThreshhold = aOther.m_snapThreshhold;
73 
74  copyLinks( &aOther );
75 
76  return *this;
77 }
VIA m_via
Via at the end point, if m_hasVia == true
Definition: pns_line.h:343
NODE * m_owner
Definition: pns_item.h:252
LAYER_RANGE m_layers
Definition: pns_item.h:253
int m_rank
Definition: pns_item.h:258
bool m_movable
Definition: pns_item.h:255
int m_marker
Definition: pns_item.h:257
SHAPE_LINE_CHAIN m_line
The actual shape of the line
Definition: pns_line.h:331
void copyLinks(const LINE *aParent)
Copies m_segmentRefs from the line aParent.
Definition: pns_line.cpp:120
bool m_hasVia
If true, the line ends with a via
Definition: pns_line.h:337
int m_net
Definition: pns_item.h:256
int m_snapThreshhold
Width to smooth out jagged segments
Definition: pns_line.h:340
int m_width
our width
Definition: pns_line.h:334

References copyLinks(), m_hasVia, PNS::ITEM::m_layers, m_line, PNS::ITEM::m_marker, PNS::ITEM::m_movable, PNS::ITEM::m_net, PNS::ITEM::m_owner, PNS::ITEM::m_rank, m_snapThreshhold, m_via, and m_width.

◆ Owner()

NODE* PNS::ITEM::Owner ( ) const
inlineinherited

Function Owner()

Returns the owner of this item, or NULL if there's none.

Definition at line 173 of file pns_item.h.

173 { return m_owner; }
NODE * m_owner
Definition: pns_item.h:252

References PNS::ITEM::m_owner.

Referenced by PNS::SIZES_SETTINGS::inheritTrackWidth(), and PNS::LINE_PLACER::Move().

◆ Parent()

◆ PointCount()

int PNS::LINE::PointCount ( ) const
inline

◆ Rank()

int PNS::LINE::Rank ( ) const
overridevirtual

Reimplemented from PNS::ITEM.

Definition at line 882 of file pns_line.cpp.

883 {
884  int min_rank = INT_MAX;
885 
886  if( IsLinked() ) {
887  for( auto s : m_segmentRefs )
888  {
889  min_rank = std::min( min_rank, s->Rank() );
890  }
891  } else {
892  min_rank = m_rank;
893  }
894 
895  int rank = ( min_rank == INT_MAX ) ? -1 : min_rank;
896 
897  return rank;
898 }
int m_rank
Definition: pns_item.h:258
SEGMENT_REFS m_segmentRefs
List of segments in the owning NODE (ITEM::m_owner) that constitute this line, or NULL if the line is...
Definition: pns_line.h:328
bool IsLinked() const
Definition: pns_line.h:214

References IsLinked(), PNS::ITEM::m_rank, and m_segmentRefs.

Referenced by PNS::ARC::ARC(), PNS::SHOVE::onCollidingArc(), PNS::SHOVE::onCollidingLine(), PNS::SHOVE::onCollidingSegment(), PNS::SHOVE::onCollidingSolid(), PNS::SHOVE::onCollidingVia(), PNS::SHOVE::onReverseCollidingVia(), PNS::SEGMENT::SEGMENT(), and PNS::SHOVE::shoveIteration().

◆ RemoveVia()

void PNS::LINE::RemoveVia ( )
inline

◆ Reverse()

void PNS::LINE::Reverse ( )

Reverses the point/vertex order

Definition at line 851 of file pns_line.cpp.

852 {
853  m_line = m_line.Reverse();
854 
855  std::reverse( m_segmentRefs.begin(), m_segmentRefs.end() );
856 }
const SHAPE_LINE_CHAIN Reverse() const
Function Reverse()
SHAPE_LINE_CHAIN m_line
The actual shape of the line
Definition: pns_line.h:331
SEGMENT_REFS m_segmentRefs
List of segments in the owning NODE (ITEM::m_owner) that constitute this line, or NULL if the line is...
Definition: pns_line.h:328

References m_line, m_segmentRefs, and SHAPE_LINE_CHAIN::Reverse().

Referenced by AppendVia(), dragCorner45(), PNS::DRAGGER::findViaFanoutByHandle(), and PNS::TOPOLOGY::followTrivialPath().

◆ SegmentCount()

◆ SetLayer()

◆ SetLayers()

void PNS::ITEM::SetLayers ( const LAYER_RANGE aLayers)
inlineinherited

Definition at line 152 of file pns_item.h.

152 { m_layers = aLayers; }
LAYER_RANGE m_layers
Definition: pns_item.h:253

References PNS::ITEM::m_layers.

Referenced by PNS::TOPOLOGY::AssembleDiffPair(), PNS::NODE::AssembleLine(), PNS::VIA::Clone(), and PNS::VIA::VIA().

◆ SetNet()

◆ SetOwner()

void PNS::ITEM::SetOwner ( NODE aOwner)
inlineinherited

Functon SetOwner()

Sets the node that owns this item. An item can belong to a single NODE or be unowned.

Definition at line 180 of file pns_item.h.

180 { m_owner = aOwner; }
NODE * m_owner
Definition: pns_item.h:252

References PNS::ITEM::m_owner.

Referenced by PNS::NODE::AssembleLine(), PNS::NODE::doRemove(), and PNS::NODE::Remove().

◆ SetParent()

void PNS::ITEM::SetParent ( BOARD_CONNECTED_ITEM aParent)
inlineinherited

Definition at line 145 of file pns_item.h.

145 { m_parent = aParent; }
BOARD_CONNECTED_ITEM * m_parent
Definition: pns_item.h:251

References PNS::ITEM::m_parent.

Referenced by PNS_KICAD_IFACE::AddItem().

◆ SetRank()

void PNS::LINE::SetRank ( int  aRank)
overridevirtual

Reimplemented from PNS::ITEM.

Definition at line 872 of file pns_line.cpp.

873 {
874  m_rank = aRank;
875 
876  for( auto s : m_segmentRefs )
877  s->SetRank( aRank );
878 
879 }
int m_rank
Definition: pns_item.h:258
SEGMENT_REFS m_segmentRefs
List of segments in the owning NODE (ITEM::m_owner) that constitute this line, or NULL if the line is...
Definition: pns_line.h:328

References PNS::ITEM::m_rank, and m_segmentRefs.

Referenced by PNS::SHOVE::onCollidingArc(), PNS::SHOVE::onCollidingLine(), PNS::SHOVE::onCollidingSegment(), PNS::SHOVE::onCollidingSolid(), PNS::SHOVE::onReverseCollidingVia(), PNS::SHOVE::ShoveLines(), and PNS::SHOVE::ShoveMultiLines().

◆ SetRoutable()

void PNS::ITEM::SetRoutable ( bool  aRoutable)
inlineinherited

Definition at line 241 of file pns_item.h.

241 { m_routable = aRoutable; }
bool m_routable
Definition: pns_item.h:259

References PNS::ITEM::m_routable.

◆ SetShape()

◆ SetSnapThreshhold()

void PNS::LINE::SetSnapThreshhold ( int  aThreshhold)
inline

Definition at line 301 of file pns_line.h.

302  {
303  m_snapThreshhold = aThreshhold;
304  }
int m_snapThreshhold
Width to smooth out jagged segments
Definition: pns_line.h:340

References m_snapThreshhold.

Referenced by PNS::DRAGGER::dragMarkObstacles(), and PNS::DRAGGER::dragShove().

◆ SetWidth()

void PNS::LINE::SetWidth ( int  aWidth)
inline

Sets line width

Definition at line 180 of file pns_line.h.

181  {
182  m_width = aWidth;
183  m_line.SetWidth( aWidth );
184  }
SHAPE_LINE_CHAIN m_line
The actual shape of the line
Definition: pns_line.h:331
void SetWidth(int aWidth)
Sets the width of all segments in the chain.
int m_width
our width
Definition: pns_line.h:334

References m_line, m_width, and SHAPE_LINE_CHAIN::SetWidth().

Referenced by PNS::NODE::AssembleLine(), PNS::LINE_PLACER::initPlacement(), and PNS::DIFF_PAIR::updateLine().

◆ Shape()

const SHAPE* PNS::LINE::Shape ( ) const
inlineoverridevirtual

Returns the shape of the line

Reimplemented from PNS::ITEM.

Definition at line 132 of file pns_line.h.

133  {
134  return &m_line;
135  }
SHAPE_LINE_CHAIN m_line
The actual shape of the line
Definition: pns_line.h:331

References m_line.

Referenced by PNS::LOGGER::Log(), and PNS::SHOVE::onCollidingVia().

◆ ShowLinks()

void PNS::LINE::ShowLinks ( ) const

Prints out all linked segments

Definition at line 463 of file pns_line.cpp.

464 {
465  if( !IsLinked() )
466  {
467  wxLogTrace( "PNS", "line %p: no links", this );
468  return;
469  }
470 
471  wxLogTrace( "PNS", "line %p: %d linked segs", this, (int) m_segmentRefs.size() );
472 
473  for( int i = 0; i < (int) m_segmentRefs.size(); i++ )
474  wxLogTrace( "PNS", "seg %d: %p\n", i, m_segmentRefs[i] );
475 }
SEGMENT_REFS m_segmentRefs
List of segments in the owning NODE (ITEM::m_owner) that constitute this line, or NULL if the line is...
Definition: pns_line.h:328
bool IsLinked() const
Definition: pns_line.h:214

References IsLinked(), and m_segmentRefs.

◆ snapDraggedCorner()

VECTOR2I PNS::LINE::snapDraggedCorner ( const SHAPE_LINE_CHAIN aPath,
const VECTOR2I aP,
int  aIndex 
) const
private

Definition at line 607 of file pns_line.cpp.

609 {
610  int s_start = std::max( aIndex - 2, 0 );
611  int s_end = std::min( aIndex + 2, aPath.SegmentCount() - 1 );
612 
613  int i, j;
614  int best_dist = INT_MAX;
615  VECTOR2I best_snap = aP;
616 
617  if( m_snapThreshhold <= 0 )
618  return aP;
619 
620  for( i = s_start; i <= s_end; i++ )
621  {
622  const SEG& a = aPath.CSegment( i );
623 
624  for( j = s_start; j < i; j++ )
625  {
626  const SEG& b = aPath.CSegment( j );
627 
628  if( !( DIRECTION_45( a ).IsObtuse( DIRECTION_45( b ) ) ) )
629  continue;
630 
631  OPT_VECTOR2I ip = a.IntersectLines( b );
632 
633  if( ip )
634  {
635  int dist = ( *ip - aP ).EuclideanNorm();
636 
637  if( dist < m_snapThreshhold && dist < best_dist )
638  {
639  best_dist = dist;
640  best_snap = *ip;
641  }
642  }
643  }
644  }
645 
646  return best_snap;
647 }
double EuclideanNorm(const wxPoint &vector)
Euclidean norm of a 2D vector.
Definition: trigo.h:128
OPT_VECTOR2I IntersectLines(const SEG &aSeg) const
Function IntersectLines()
Definition: seg.h:191
double dist(const double ax, const double ay, const double bx, const double by)
Definition: delauney.h:168
OPT< VECTOR2I > OPT_VECTOR2I
Definition: seg.h:37
DIRECTION_45.
Definition: direction45.h:37
int SegmentCount() const
Function SegmentCount()
Definition: seg.h:39
const SEG CSegment(int aIndex) const
Function CSegment()
int m_snapThreshhold
Width to smooth out jagged segments
Definition: pns_line.h:340

References SHAPE_LINE_CHAIN::CSegment(), dist(), EuclideanNorm(), SEG::IntersectLines(), m_snapThreshhold, and SHAPE_LINE_CHAIN::SegmentCount().

Referenced by dragCorner45().

◆ snapToNeighbourSegments()

VECTOR2I PNS::LINE::snapToNeighbourSegments ( const SHAPE_LINE_CHAIN aPath,
const VECTOR2I aP,
int  aIndex 
) const
private

Definition at line 649 of file pns_line.cpp.

651 {
652  VECTOR2I snap_p[2];
653  DIRECTION_45 dragDir( aPath.CSegment( aIndex ) );
654  int snap_d[2] = { -1, -1 };
655 
656  if( m_snapThreshhold == 0 )
657  return aP;
658 
659  if( aIndex >= 2 )
660  {
661  SEG s = aPath.CSegment( aIndex - 2 );
662 
663  if( DIRECTION_45( s ) == dragDir )
664  snap_d[0] = s.LineDistance( aP );
665 
666  snap_p[0] = s.A;
667  }
668 
669  if( aIndex < aPath.SegmentCount() - 2 )
670  {
671  SEG s = aPath.CSegment( aIndex + 2 );
672 
673  if( DIRECTION_45( s ) == dragDir )
674  snap_d[1] = s.LineDistance( aP );
675 
676  snap_p[1] = s.A;
677  }
678 
679  VECTOR2I best = aP;
680  int minDist = INT_MAX;
681 
682  for( int i = 0; i < 2; i++ )
683  {
684  if( snap_d[i] >= 0 && snap_d[i] < minDist && snap_d[i] <= m_snapThreshhold )
685  {
686  minDist = snap_d[i];
687  best = snap_p[i];
688  }
689  }
690 
691  return best;
692 }
int LineDistance(const VECTOR2I &aP, bool aDetermineSide=false) const
Function LineDistance()
Definition: seg.h:378
DIRECTION_45.
Definition: direction45.h:37
int SegmentCount() const
Function SegmentCount()
Definition: seg.h:39
const SEG CSegment(int aIndex) const
Function CSegment()
int m_snapThreshhold
Width to smooth out jagged segments
Definition: pns_line.h:340
VECTOR2I A
Definition: seg.h:47

References SEG::A, SHAPE_LINE_CHAIN::CSegment(), SEG::LineDistance(), m_snapThreshhold, and SHAPE_LINE_CHAIN::SegmentCount().

Referenced by dragSegment45().

◆ Unmark()

void PNS::LINE::Unmark ( int  aMarker = -1)
overridevirtual

Reimplemented from PNS::ITEM.

Definition at line 98 of file pns_line.cpp.

99 {
100  for( auto s : m_segmentRefs )
101  s->Unmark( aMarker );
102 
103  m_marker = 0;
104 }
int m_marker
Definition: pns_item.h:257
SEGMENT_REFS m_segmentRefs
List of segments in the owning NODE (ITEM::m_owner) that constitute this line, or NULL if the line is...
Definition: pns_line.h:328

References PNS::ITEM::m_marker, and m_segmentRefs.

Referenced by PNS::DRAGGER::dragShove(), PNS::SHOVE::onCollidingSolid(), and PNS::DRAGGER::optimizeAndUpdateDraggedLine().

◆ Via()

◆ Walkaround() [1/2]

bool PNS::LINE::Walkaround ( SHAPE_LINE_CHAIN  aObstacle,
SHAPE_LINE_CHAIN aPre,
SHAPE_LINE_CHAIN aWalk,
SHAPE_LINE_CHAIN aPost,
bool  aCw 
) const

Calculates a line thightly wrapping a convex hull of an obstacle object (aObstacle).

aPrePath = path from origin to the obstacle aWalkaroundPath = path around the obstacle aPostPath = past from obstacle till the end aCW = whether to walk around in clockwise or counter-clockwise direction.

Definition at line 162 of file pns_line.cpp.

164 {
165  const SHAPE_LINE_CHAIN& line( CLine() );
166 
167  if( line.SegmentCount() < 1 )
168  return false;
169 
170  const auto pFirst = line.CPoint(0);
171  const auto pLast = line.CPoint(-1);
172 
173  if( aObstacle.PointInside( line.CPoint( 0 ) ) || aObstacle.PointInside( line.CPoint( -1 ) ) )
174  {
175  return false;
176  }
177 
179 
180  line.Intersect( aObstacle, ips );
181 
182 
183  /* for( auto p : ips )
184  {
185  printf("gif %d %d our %d their %d\n", p.p.x, p.p.y, p.our.Index(), p.their.Index() );
186  }*/
187 
188  for( int i = 0; i < line.SegmentCount(); i++ )
189  {
190  const SEG& a = line.CSegment(i);
191  bool over = false;
192 
193 
194  for( int j = 0; j < aObstacle.SegmentCount(); j++ )
195  {
196  const SEG& so = aObstacle.CSegment(j);
197  if( so.Contains( a ) )
198  {
199  // printf("discard seg %d\n", i );
200  over = true;
201  break;
202  }
203  }
204 
205  if(over)
206  continue;
207 
208 
209  bool a_in = aObstacle.PointInside( a.A );// && !aObstacle.PointOnEdge( a.A );
210  bool b_in = aObstacle.PointInside( a.B );// && !aObstacle.PointOnEdge( a.B );
211 
212 // printf("i %d a %d %d %d %d [%d %d] a_in %d b_in %d\n", i, a.A.x, a.A.y, a.B.x, a.B.y, a.A.x- a.B.x, a.A.y - a.B.y, !!a_in, !!b_in );
213 
214 
215  if( a_in ^ b_in ) // segment crosses hull boundary
216  {
217  for( int j = 0; j < aObstacle.SegmentCount(); j++ )
218  {
219  OPT_VECTOR2I p;
220 
221  bool cont_a = aObstacle.CSegment(j).Contains( a.A );
222  bool cont_b = aObstacle.CSegment(j).Contains( a.B );
223 
224  if(cont_a)
225  p = a.A;
226  else if (cont_b)
227  p = a.B;
228  else
229  p = aObstacle.CSegment(j).Intersect( a );
230 
231  //printf("- cont_a %d cont_b %d p %d\n", !!cont_a, !!cont_b, p ? 1 : 0 );
232 
233 
234  if ( p )
235  {
237  ip.our = a;
238  ip.their = aObstacle.CSegment(j);
239  ip.p = *p;
240  ips.push_back(ip);
241  //printf("chb %d %d\n", p->x, p->y);
242  }
243  }
244  }
245  else if ( !a_in && !b_in )
246  {
247  int min_idx = INT_MAX;
248  int max_idx = INT_MIN;
249 
250  for( int j = 0; j < aObstacle.SegmentCount(); j++ )
251  {
252  const SEG& os = aObstacle.CSegment(j);
253 
254  if (os.Intersect(a))
255  {
256  min_idx = std::min(min_idx, j);
257  max_idx = std::max(max_idx, j);
258  }
259 
260  }
261 
262  if (min_idx != max_idx && min_idx != INT_MAX )
263  {
264  // genuine interesection found
265  for( int j = 0; j < aObstacle.SegmentCount(); j++ )
266  {
267  const SEG& os = aObstacle.CSegment(j);
268 
269  auto p = os.Intersect(a);
270  if(p)
271  {
273  ip.our = a;
274  ip.their = aObstacle.CSegment(j);
275  ip.p = *p;
276  ips.push_back(ip);
277  // printf("gif %d %d\n", p->x, p->y);
278  }
279 
280  }
281  }
282  }
283  }
284 
285  auto eFirst = aObstacle.EdgeContainingPoint( pFirst );
286  auto eLast = aObstacle.EdgeContainingPoint( pLast );
287 
288  aWalk.Clear();
289  aPost.Clear();
290 
291  int nearest_dist = INT_MAX;
292  int farthest_dist = 0;
293 
294  SHAPE_LINE_CHAIN::INTERSECTION nearest, farthest;
296 
297  if( eFirst >= 0 )
298  {
299  is.our = line.CSegment(0);
300  is.their = aObstacle.CSegment( eFirst );
301  is.p = pFirst;
302  ips.push_back(is);
303  }
304 
305  if ( eLast >= 0 )
306  {
307  is.our = line.CSegment(-1);
308  is.their = aObstacle.CSegment( eLast );
309  is.p = pLast;
310  ips.push_back(is);
311  }
312 
313  for( int i = 0; i < (int) ips.size(); i++ )
314  {
315  const VECTOR2I p = ips[i].p;
316  int dist = line.PathLength( p );
317 
318  if( dist < 0 )
319  return false;
320 
321  if( dist <= nearest_dist )
322  {
323  nearest_dist = dist;
324  nearest = ips[i];
325  }
326 
327  if( dist >= farthest_dist )
328  {
329  farthest_dist = dist;
330  farthest = ips[i];
331  }
332  }
333 
334  if( ips.size() <= 1 || nearest.p == farthest.p )
335  {
336  aPre = line;
337  return true;
338  }
339 
340  aPre = line.Slice( 0, nearest.our.Index() );
341  aPre.Append( nearest.p );
342  aPre.Simplify();
343 
344  aWalk.Clear();
345  aWalk.SetClosed( false );
346  aWalk.Append( nearest.p );
347 
348  assert( nearest.their.Index() >= 0 );
349  assert( farthest.their.Index() >= 0 );
350 
351  assert( nearest_dist <= farthest_dist );
352 
353  aObstacle.Split( nearest.p );
354  aObstacle.Split( farthest.p );
355 
356  int i_first = aObstacle.Find( nearest.p );
357  int i_last = aObstacle.Find( farthest.p );
358 
359  int i = i_first;
360 
361  if( i_first < 0 || i_last < 0 )
362  return false;
363 
364  while( i != i_last )
365  {
366  aWalk.Append( aObstacle.CPoint( i ) );
367  i += ( aCw ? 1 : -1 );
368 
369  if( i < 0 )
370  i = aObstacle.PointCount() - 1;
371  else if( i == aObstacle.PointCount() )
372  i = 0;
373  }
374 
375  aWalk.Append( farthest.p );
376  aWalk.Simplify();
377 
378  aPost.Clear();
379  aPost.Append( farthest.p );
380  aPost.Append( line.Slice( farthest.our.Index() + 1, -1 ) );
381  aPost.Simplify();
382 
383  return true;
384 }
int Find(const VECTOR2I &aP) const
Function Find()
const SHAPE_LINE_CHAIN & CLine() const
Const accessor to the underlying shape
Definition: pns_line.h:144
int Index() const
Function Index()
Definition: seg.h:337
int Split(const VECTOR2I &aP)
Function Split()
int EdgeContainingPoint(const VECTOR2I &aP, int aAccuracy=0) const
Function EdgeContainingPoint()
std::vector< INTERSECTION > INTERSECTIONS
OPT_VECTOR2I Intersect(const SEG &aSeg, bool aIgnoreEndpoints=false, bool aLines=false) const
Function Intersect()
Definition: seg.cpp:93
const SHAPE_LINE_CHAIN Slice(int aStartIndex, int aEndIndex=-1) const
Function Slice()
VECTOR2I p
point of intersection between our and their.
int PointCount() const
Function PointCount()
void Append(int aX, int aY, bool aAllowDuplication=false)
Function Append()
double dist(const double ax, const double ay, const double bx, const double by)
Definition: delauney.h:168
SHAPE_LINE_CHAIN & Simplify()
Function Simplify()
const VECTOR2I & CPoint(int aIndex) const
Function Point()
void SetClosed(bool aClosed)
Function SetClosed()
SEG their
segment belonging from the aOther argument of Intersect()
OPT< VECTOR2I > OPT_VECTOR2I
Definition: seg.h:37
int SegmentCount() const
Function SegmentCount()
Definition: seg.h:39
const SEG CSegment(int aIndex) const
Function CSegment()
SHAPE_LINE_CHAIN.
VECTOR2I A
Definition: seg.h:47
void Clear()
Function Clear() Removes all points from the line chain.
bool PointInside(const VECTOR2I &aPt, int aAccuracy=0, bool aUseBBoxCache=false) const
Function PointInside()
SEG our
segment belonging from the (this) argument of Intersect()
bool Contains(const SEG &aSeg) const
Definition: seg.h:299
VECTOR2I B
Definition: seg.h:48

References SEG::A, SHAPE_LINE_CHAIN::Append(), SEG::B, SHAPE_LINE_CHAIN::Clear(), CLine(), SEG::Contains(), SHAPE_LINE_CHAIN::CPoint(), SHAPE_LINE_CHAIN::CSegment(), dist(), SHAPE_LINE_CHAIN::EdgeContainingPoint(), SHAPE_LINE_CHAIN::Find(), SEG::Index(), SEG::Intersect(), SHAPE_LINE_CHAIN::Intersect(), SHAPE_LINE_CHAIN::INTERSECTION::our, SHAPE_LINE_CHAIN::INTERSECTION::p, SHAPE_LINE_CHAIN::PathLength(), SHAPE_LINE_CHAIN::PointCount(), SHAPE_LINE_CHAIN::PointInside(), SHAPE_LINE_CHAIN::SegmentCount(), SHAPE_LINE_CHAIN::SetClosed(), SHAPE_LINE_CHAIN::Simplify(), SHAPE_LINE_CHAIN::Slice(), SHAPE_LINE_CHAIN::Split(), and SHAPE_LINE_CHAIN::INTERSECTION::their.

Referenced by PNS::SHOVE::processHullSet(), PNS::WALKAROUND::singleStep(), Walkaround(), and PNS::SHOVE::walkaroundLoneVia().

◆ Walkaround() [2/2]

bool PNS::LINE::Walkaround ( const SHAPE_LINE_CHAIN aObstacle,
SHAPE_LINE_CHAIN aPath,
bool  aCw 
) const

Definition at line 387 of file pns_line.cpp.

388 {
389  SHAPE_LINE_CHAIN walk, post;
390 
391  if( ! Walkaround( aObstacle, aPath, walk, post, aCw ) )
392  return false;
393 
394  aPath.Append( walk );
395  aPath.Append( post );
396  aPath.Simplify();
397 
398  return true;
399 }
bool Walkaround(SHAPE_LINE_CHAIN aObstacle, SHAPE_LINE_CHAIN &aPre, SHAPE_LINE_CHAIN &aWalk, SHAPE_LINE_CHAIN &aPost, bool aCw) const
Calculates a line thightly wrapping a convex hull of an obstacle object (aObstacle).
Definition: pns_line.cpp:162
void Append(int aX, int aY, bool aAllowDuplication=false)
Function Append()
SHAPE_LINE_CHAIN & Simplify()
Function Simplify()
SHAPE_LINE_CHAIN.

References SHAPE_LINE_CHAIN::Append(), SHAPE_LINE_CHAIN::Simplify(), and Walkaround().

◆ Width()

Member Data Documentation

◆ m_hasVia

bool PNS::LINE::m_hasVia
private

If true, the line ends with a via

Definition at line 337 of file pns_line.h.

Referenced by AppendVia(), Clear(), EndsWithVia(), LINE(), operator=(), and RemoveVia().

◆ m_kind

PnsKind PNS::ITEM::m_kind
protectedinherited

◆ m_layers

◆ m_line

◆ m_marker

◆ m_movable

bool PNS::ITEM::m_movable
protectedinherited

Definition at line 255 of file pns_item.h.

Referenced by PNS::ITEM::ITEM(), LINE(), operator=(), and PNS::SOLID::SOLID().

◆ m_net

◆ m_owner

NODE* PNS::ITEM::m_owner
protectedinherited

◆ m_parent

BOARD_CONNECTED_ITEM* PNS::ITEM::m_parent
protectedinherited

◆ m_rank

◆ m_routable

bool PNS::ITEM::m_routable
protectedinherited

Definition at line 259 of file pns_item.h.

Referenced by PNS::ITEM::IsRoutable(), PNS::ITEM::ITEM(), and PNS::ITEM::SetRoutable().

◆ m_segmentRefs

SEGMENT_REFS PNS::LINE::m_segmentRefs
private

List of segments in the owning NODE (ITEM::m_owner) that constitute this line, or NULL if the line is not a part of any node.

Definition at line 328 of file pns_line.h.

Referenced by ClearSegmentLinks(), ClipVertexRange(), ContainsSegment(), copyLinks(), GetLink(), HasLockedSegments(), IsLinked(), LinkCount(), LinkedSegments(), LinkSegment(), Mark(), Marker(), Rank(), Reverse(), SetRank(), ShowLinks(), and Unmark().

◆ m_snapThreshhold

int PNS::LINE::m_snapThreshhold
private

Width to smooth out jagged segments

Definition at line 340 of file pns_line.h.

Referenced by GetSnapThreshhold(), LINE(), operator=(), SetSnapThreshhold(), snapDraggedCorner(), and snapToNeighbourSegments().

◆ m_via

VIA PNS::LINE::m_via
private

Via at the end point, if m_hasVia == true

Definition at line 343 of file pns_line.h.

Referenced by AppendVia(), LINE(), operator=(), and Via().

◆ m_width

int PNS::LINE::m_width
private

our width

Definition at line 334 of file pns_line.h.

Referenced by LINE(), operator=(), SetShape(), SetWidth(), and Width().

◆ UnusedNet

const int PNS::ITEM::UnusedNet = INT_MAX
staticinherited

Definition at line 56 of file pns_item.h.

Referenced by PNS::ITEM::ITEM().


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