28#include <math/vector2d.h>
31#include "pns_segment.h"
32#include "pns_itemset.h"
63 return ( (hash<int>()( aP.pos.x )
64 ^ (hash<int>()( aP.pos.y ) << 1) ) >> 1 )
65 ^ (hash<int>()( aP.net ) << 1);
70 ITEM( JOINT_T ), m_tag(), m_locked( false ) {}
81 JOINT(
const JOINT& aB ) :
84 m_layers = aB.m_layers;
85 m_tag.pos = aB.m_tag.pos;
86 m_tag.net = aB.m_tag.net;
87 m_linkedItems = aB.m_linkedItems;
88 m_layers = aB.m_layers;
89 m_locked = aB.m_locked;
105 if( m_linkedItems.Size() != 2 || m_linkedItems.Count( SEGMENT_T | ARC_T ) != 2 )
107 if( !aAllowLockedSegs )
111 else if( m_linkedItems.Size() == 3
112 && m_linkedItems.Count( SEGMENT_T | ARC_T ) == 2
113 && m_linkedItems.Count( VIA_T ) == 1 )
115 assert(
static_cast<const ITEM*
>( m_linkedItems[2] )->
Kind() == VIA_T );
117 const VIA* via =
static_cast<const VIA*
>( m_linkedItems[2] );
119 if( !via->IsVirtual() )
128 auto seg1 =
static_cast<LINKED_ITEM*
>( m_linkedItems[0] );
129 auto seg2 =
static_cast<LINKED_ITEM*
>( m_linkedItems[1] );
132 return seg1->Width() == seg2->Width();
135 bool IsNonFanoutVia()
const
137 int vias = m_linkedItems.Count( VIA_T );
138 int segs = m_linkedItems.Count( SEGMENT_T );
139 segs += m_linkedItems.Count( ARC_T );
141 return ( m_linkedItems.Size() == 3 && vias == 1 && segs == 2 );
144 bool IsStitchingVia()
const
146 return ( m_linkedItems.Size() == 1 && m_linkedItems.Count( VIA_T ) == 1 );
151 if( m_linkedItems.Size() != 2 )
154 if( m_linkedItems.Count( SEGMENT_T ) != 2)
160 return seg1->Width() != seg2->Width();
166 if( m_linkedItems.Contains( aItem ) )
169 m_linkedItems.Add( aItem );
176 m_linkedItems.Erase( aItem );
177 return m_linkedItems.Size() == 0;
182 LINKED_ITEM* NextSegment(
ITEM* aCurrent,
bool aAllowLockedSegs =
false )
const
187 return static_cast<LINKED_ITEM*
>( m_linkedItems[m_linkedItems[0] == aCurrent ? 1 : 0] );
192 for( ITEM* item : m_linkedItems.Items() )
194 if( item->OfKind( VIA_T ) )
195 return static_cast<VIA*
>( item );
220 return m_linkedItems.CItems();
223 const ITEM_SET& CLinks()
const
225 return m_linkedItems;
230 return m_linkedItems;
233 int LinkCount(
int aMask = -1 )
const
235 return m_linkedItems.Count( aMask );
240 bool operator==(
const JOINT& rhs )
const
242 return m_tag.pos == rhs.m_tag.pos && m_tag.net == rhs.m_tag.net;
245 void Merge(
const JOINT& aJoint )
247 if( !Overlaps( aJoint ) )
250 m_layers.
Merge( aJoint.m_layers );
252 if( aJoint.IsLocked() )
255 for( ITEM* item : aJoint.LinkList() )
257 m_linkedItems.Add( item );
261 bool Overlaps(
const JOINT& rhs )
const
263 return m_tag.pos == rhs.m_tag.pos &&
264 m_tag.net == rhs.m_tag.net && m_layers.Overlaps( rhs.m_layers );
267 void Lock(
bool aLock =
true )
272 bool IsLocked()
const
282 ITEM_SET m_linkedItems;
288inline bool operator==( JOINT::HASH_TAG
const& aP1, JOINT::HASH_TAG
const& aP2 )
290 return aP1.pos == aP2.pos && aP1.net == aP2.net;
Represent a contiguous set of PCB layers.
Definition pns_layerset.h:32
void Merge(const LAYER_RANGE &aOther)
Shortcut for comparisons/overlap tests.
Definition pns_layerset.h:92
Base class for PNS router board items.
Definition pns_item.h:57
PnsKind Kind() const
Return the type (kind) of the item.
Definition pns_item.h:131
A 2D point on a given set of layers and belonging to a certain net, that links together a number of b...
Definition pns_joint.h:43
ITEM_SET::ENTRIES LINKED_ITEMS
Joints are hashed by their position, layers and net.
Definition pns_joint.h:45
bool IsLineCorner(bool aAllowLockedSegs=false) const
Checks if a joint connects two segments of the same net, layer, and width.
Definition pns_joint.h:103
const HASH_TAG & Tag() const
trivial accessors
Definition pns_joint.h:203
void Link(ITEM *aItem)
Unlink a given board item from the joint (upon its removal from a NODE)
Definition pns_joint.h:164
ITEM * Clone() const override
Return a deep copy of the item.
Definition pns_joint.h:92
bool IsTraceWidthChange() const
Link the joint to a given board item (when it's added to the NODE).
Definition pns_joint.h:149
bool Unlink(ITEM *aItem)
For trivial joints, return the segment adjacent to (aCurrent).
Definition pns_joint.h:174
Definition pns_linked_item.h:30
Definition pns_segment.h:39
Definition pns_joint.h:50
Definition pns_joint.h:56