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
 

Public Member Functions

 DRC_RTREE ()
 
 ~DRC_RTREE ()
 
void Insert (BOARD_ITEM *aItem, PCB_LAYER_ID aLayer, int aWorstClearance=0, bool aAtomicTables=false)
 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, bool aAtomicTables=false)
 Insert an item into the tree on a particular layer with a worst clearance.
 
void Build ()
 Finalize all pending inserts by bulk-building packed R-trees from the staged items.
 
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 = KIRTREE::PACKED_RTREE<ITEM_WITH_SHAPE*, int, 2>
 
using drc_rtree_builder = typename drc_rtree::Builder
 

Private Attributes

std::map< int, drc_rtreem_tree
 
std::map< int, drc_rtree_builderm_builders
 
std::vector< ITEM_WITH_SHAPE * > m_owned
 
size_t m_count = 0
 

Detailed Description

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

Non-owning.

Definition at line 49 of file drc_rtree.h.

Member Typedef Documentation

◆ drc_rtree

Definition at line 77 of file drc_rtree.h.

◆ drc_rtree_builder

using DRC_RTREE::drc_rtree_builder = typename drc_rtree::Builder
private

Definition at line 78 of file drc_rtree.h.

◆ LAYER_PAIR

Definition at line 459 of file drc_rtree.h.

Constructor & Destructor Documentation

◆ DRC_RTREE()

DRC_RTREE::DRC_RTREE ( )
inline

Definition at line 81 of file drc_rtree.h.

References m_count.

Referenced by QueryCollidingPairs().

◆ ~DRC_RTREE()

DRC_RTREE::~DRC_RTREE ( )
inline

Definition at line 86 of file drc_rtree.h.

References m_owned.

Member Function Documentation

◆ Build()

void DRC_RTREE::Build ( )
inline

Finalize all pending inserts by bulk-building packed R-trees from the staged items.

Must be called after all Insert() calls and before any queries.

Definition at line 168 of file drc_rtree.h.

References m_builders, and m_tree.

Referenced by TRACKS_CLEANER::cleanup(), and DRC_TEST_PROVIDER_SILK_CLEARANCE::Run().

◆ 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 179 of file drc_rtree.h.

References m_builders, m_count, m_owned, and m_tree.

◆ empty()

bool DRC_RTREE::empty ( ) const
inline

Definition at line 559 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 437 of file drc_rtree.h.

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

Referenced by DRC_TEST_PROVIDER_CONNECTION_WIDTH::Run().

◆ Insert() [1/2]

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

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

Items are staged into per-layer builders; call Build() to finalize.

Definition at line 96 of file drc_rtree.h.

References Insert().

Referenced by TRACKS_CLEANER::cleanup(), Insert(), and DRC_TEST_PROVIDER_SILK_CLEARANCE::Run().

◆ Insert() [2/2]

void DRC_RTREE::Insert ( BOARD_ITEM * aItem,
PCB_LAYER_ID aRefLayer,
PCB_LAYER_ID aTargetLayer,
int aWorstClearance,
bool aAtomicTables = false )
inline

◆ OnLayer()

DRC_LAYER DRC_RTREE::OnLayer ( PCB_LAYER_ID aLayer) const
inline

Definition at line 602 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 616 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 608 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 304 of file drc_rtree.h.

References actual, 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 554 of file drc_rtree.h.

References m_count.

Referenced by DRC_TEST_PROVIDER_SILK_CLEARANCE::Run().

Member Data Documentation

◆ m_builders

std::map<int, drc_rtree_builder> DRC_RTREE::m_builders
private

Definition at line 625 of file drc_rtree.h.

Referenced by Build(), clear(), and Insert().

◆ m_count

size_t DRC_RTREE::m_count = 0
private

Definition at line 627 of file drc_rtree.h.

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

◆ m_owned

std::vector<ITEM_WITH_SHAPE*> DRC_RTREE::m_owned
private

Definition at line 626 of file drc_rtree.h.

Referenced by clear(), Insert(), and ~DRC_RTREE().

◆ m_tree


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