KiCad PCB EDA Suite
Loading...
Searching...
No Matches
DRC_RTREE Class Reference

Implement an R-tree for fast spatial and layer indexing of connectable items. More...

#include <drc_rtree.h>

Classes

struct  DRC_LAYER
 The DRC_LAYER struct provides a layer-specific auto-range iterator to the RTree. More...
 
struct  ITEM_WITH_SHAPE
 
struct  PAIR_INFO
 

Public Types

typedef std::pair< PCB_LAYER_ID, PCB_LAYER_IDLAYER_PAIR
 
using iterator = typename drc_rtree::Iterator
 

Public Member Functions

 DRC_RTREE ()
 
 ~DRC_RTREE ()
 
void Insert (BOARD_ITEM *aItem, PCB_LAYER_ID aLayer, int aWorstClearance=0)
 Insert an item into the tree on a particular layer with an optional worst clearance.
 
void Insert (BOARD_ITEM *aItem, PCB_LAYER_ID aRefLayer, PCB_LAYER_ID aTargetLayer, int aWorstClearance)
 Insert an item into the tree on a particular layer with a worst clearance.
 
void clear ()
 Remove all items from the RTree.
 
bool CheckColliding (SHAPE *aRefShape, PCB_LAYER_ID aTargetLayer, int aClearance=0, std::function< bool(BOARD_ITEM *)> aFilter=nullptr) const
 
int QueryColliding (BOARD_ITEM *aRefItem, PCB_LAYER_ID aRefLayer, PCB_LAYER_ID aTargetLayer, std::function< bool(BOARD_ITEM *)> aFilter=nullptr, std::function< bool(BOARD_ITEM *)> aVisitor=nullptr, int aClearance=0) const
 This is a fast test which essentially does bounding-box overlap given a worst-case clearance.
 
bool QueryColliding (const BOX2I &aBox, SHAPE *aRefShape, PCB_LAYER_ID aLayer, int aClearance, int *aActual, VECTOR2I *aPos) const
 This one is for tessellated items.
 
bool QueryColliding (const BOX2I &aBox, SHAPE *aRefShape, PCB_LAYER_ID aLayer) const
 Quicker version of above that just reports a raw yes/no.
 
std::unordered_set< BOARD_ITEM * > GetObjectsAt (const VECTOR2I &aPt, PCB_LAYER_ID aLayer, int aClearance=0)
 Gets the BOARD_ITEMs that overlap the specified point/layer.
 
int QueryCollidingPairs (DRC_RTREE *aRefTree, std::vector< LAYER_PAIR > aLayerPairs, std::function< bool(const LAYER_PAIR &, ITEM_WITH_SHAPE *, ITEM_WITH_SHAPE *, bool *aCollision)> aVisitor, int aMaxClearance, std::function< bool(int, int)> aProgressReporter) const
 
size_t size () const
 Return the number of items in the tree.
 
bool empty () const
 
DRC_LAYER OnLayer (PCB_LAYER_ID aLayer) const
 
DRC_LAYER Overlapping (PCB_LAYER_ID aLayer, const VECTOR2I &aPoint, int aAccuracy=0) const
 
DRC_LAYER Overlapping (PCB_LAYER_ID aLayer, const BOX2I &aRect) const
 

Private Types

using drc_rtree = RTree< ITEM_WITH_SHAPE *, int, 2, double >
 

Private Attributes

std::map< int, drc_rtree * > m_tree
 
size_t m_count
 

Detailed Description

Implement an R-tree for fast spatial and layer indexing of connectable items.

Non-owning.

Definition at line 47 of file drc_rtree.h.

Member Typedef Documentation

◆ drc_rtree

using DRC_RTREE::drc_rtree = RTree<ITEM_WITH_SHAPE*, int, 2, double>
private

Definition at line 78 of file drc_rtree.h.

◆ iterator

using DRC_RTREE::iterator = typename drc_rtree::Iterator

Definition at line 548 of file drc_rtree.h.

◆ LAYER_PAIR

Definition at line 443 of file drc_rtree.h.

Constructor & Destructor Documentation

◆ DRC_RTREE()

DRC_RTREE::DRC_RTREE ( )
inline

Definition at line 82 of file drc_rtree.h.

References LSET::AllLayersMask(), m_count, and m_tree.

◆ ~DRC_RTREE()

DRC_RTREE::~DRC_RTREE ( )
inline

Definition at line 90 of file drc_rtree.h.

References _, and m_tree.

Member Function Documentation

◆ CheckColliding()

bool DRC_RTREE::CheckColliding ( SHAPE aRefShape,
PCB_LAYER_ID  aTargetLayer,
int  aClearance = 0,
std::function< bool(BOARD_ITEM *)>  aFilter = nullptr 
) const
inline

◆ clear()

void DRC_RTREE::clear ( )
inline

Remove all items from the RTree.

Definition at line 170 of file drc_rtree.h.

References _, m_count, and m_tree.

Referenced by DRC_TEST_PROVIDER_HOLE_TO_HOLE::Run(), and DRC_TEST_PROVIDER_PHYSICAL_CLEARANCE::Run().

◆ empty()

bool DRC_RTREE::empty ( ) const
inline

Definition at line 543 of file drc_rtree.h.

References m_count.

◆ GetObjectsAt()

std::unordered_set< BOARD_ITEM * > DRC_RTREE::GetObjectsAt ( const VECTOR2I aPt,
PCB_LAYER_ID  aLayer,
int  aClearance = 0 
)
inline

Gets the BOARD_ITEMs that overlap the specified point/layer.

Parameters
aPtPosition on the tree
aLayerLayer to search
Returns
vector of overlapping BOARD_ITEMS*

Definition at line 424 of file drc_rtree.h.

References m_tree, VECTOR2< T >::x, and VECTOR2< T >::y.

◆ Insert() [1/2]

void DRC_RTREE::Insert ( BOARD_ITEM aItem,
PCB_LAYER_ID  aLayer,
int  aWorstClearance = 0 
)
inline

◆ Insert() [2/2]

void DRC_RTREE::Insert ( BOARD_ITEM aItem,
PCB_LAYER_ID  aRefLayer,
PCB_LAYER_ID  aTargetLayer,
int  aWorstClearance 
)
inline

Insert an item into the tree on a particular layer with a worst clearance.

Allows the source layer to be different from the tree layer.

Definition at line 113 of file drc_rtree.h.

References BOX2< Vec >::GetBottom(), BOARD_ITEM::GetEffectiveHoleShape(), BOARD_ITEM::GetEffectiveShape(), BOX2< Vec >::GetRight(), BOX2< Vec >::GetX(), BOX2< Vec >::GetY(), BOARD_ITEM::HasHole(), BOX2< Vec >::Inflate(), EDA_TEXT::IsVisible(), m_count, m_tree, PCB_FIELD_T, PCB_PAD_T, PCB_TEXT_T, EDA_ITEM::Type(), and UNDEFINED_LAYER.

◆ OnLayer()

DRC_LAYER DRC_RTREE::OnLayer ( PCB_LAYER_ID  aLayer) const
inline

Definition at line 585 of file drc_rtree.h.

References m_tree.

Referenced by QueryCollidingPairs().

◆ Overlapping() [1/2]

DRC_LAYER DRC_RTREE::Overlapping ( PCB_LAYER_ID  aLayer,
const BOX2I aRect 
) const
inline

Definition at line 599 of file drc_rtree.h.

References m_tree.

◆ Overlapping() [2/2]

DRC_LAYER DRC_RTREE::Overlapping ( PCB_LAYER_ID  aLayer,
const VECTOR2I aPoint,
int  aAccuracy = 0 
) const
inline

Definition at line 591 of file drc_rtree.h.

References BOX2< Vec >::Inflate(), and m_tree.

◆ QueryColliding() [1/3]

int DRC_RTREE::QueryColliding ( BOARD_ITEM aRefItem,
PCB_LAYER_ID  aRefLayer,
PCB_LAYER_ID  aTargetLayer,
std::function< bool(BOARD_ITEM *)>  aFilter = nullptr,
std::function< bool(BOARD_ITEM *)>  aVisitor = nullptr,
int  aClearance = 0 
) const
inline

◆ QueryColliding() [2/3]

bool DRC_RTREE::QueryColliding ( const BOX2I aBox,
SHAPE aRefShape,
PCB_LAYER_ID  aLayer 
) const
inline

◆ QueryColliding() [3/3]

bool DRC_RTREE::QueryColliding ( const BOX2I aBox,
SHAPE aRefShape,
PCB_LAYER_ID  aLayer,
int  aClearance,
int *  aActual,
VECTOR2I aPos 
) const
inline

This one is for tessellated items.

(All shapes in the tree will be from a single BOARD_ITEM.) It checks all items in the bbox overlap to find the minimal actual distance and position.

Definition at line 292 of file drc_rtree.h.

References SHAPE::Collide(), BOX2< Vec >::GetBottom(), BOX2< Vec >::GetRight(), BOX2< Vec >::GetX(), BOX2< Vec >::GetY(), BOX2< Vec >::Inflate(), and m_tree.

◆ QueryCollidingPairs()

int DRC_RTREE::QueryCollidingPairs ( DRC_RTREE aRefTree,
std::vector< LAYER_PAIR aLayerPairs,
std::function< bool(const LAYER_PAIR &, ITEM_WITH_SHAPE *, ITEM_WITH_SHAPE *, bool *aCollision)>  aVisitor,
int  aMaxClearance,
std::function< bool(int, int)>  aProgressReporter 
) const
inline

◆ size()

size_t DRC_RTREE::size ( ) const
inline

Return the number of items in the tree.

Returns
number of elements in the tree.

Definition at line 538 of file drc_rtree.h.

References m_count.

Referenced by DRC_TEST_PROVIDER_SILK_CLEARANCE::Run().

Member Data Documentation

◆ m_count

size_t DRC_RTREE::m_count
private

Definition at line 608 of file drc_rtree.h.

Referenced by clear(), DRC_RTREE(), empty(), Insert(), and size().

◆ m_tree

std::map<int, drc_rtree*> DRC_RTREE::m_tree
private

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