KiCad PCB EDA Suite
KIGFX::VIEW_RTREE Class Reference

Implement an non-owning R-tree for fast spatial indexing of VIEW items. More...

#include <view_rtree.h>

Inheritance diagram for KIGFX::VIEW_RTREE:

Public Member Functions

void Insert (VIEW_ITEM *aItem)
 Insert an item into the tree. More...
 
void Remove (VIEW_ITEM *aItem)
 Remove an item from the tree. More...
 
template<class Visitor >
void Query (const BOX2I &aBounds, Visitor &aVisitor) const
 Execute a function object aVisitor for each item whose bounding box intersects with aBounds. More...
 

Detailed Description

Implement an non-owning R-tree for fast spatial indexing of VIEW items.

Definition at line 41 of file view_rtree.h.

Member Function Documentation

◆ Insert()

void KIGFX::VIEW_RTREE::Insert ( VIEW_ITEM aItem)
inline

Insert an item into the tree.

Item's bounding box is taken via its ViewBBox() method.

Definition at line 49 of file view_rtree.h.

50 {
51 const BOX2I& bbox = aItem->ViewBBox();
52 const int mmin[2] = { bbox.GetX(), bbox.GetY() };
53 const int mmax[2] = { bbox.GetRight(), bbox.GetBottom() };
54
55 VIEW_RTREE_BASE::Insert( mmin, mmax, aItem );
56 }
coord_type GetY() const
Definition: box2.h:174
coord_type GetX() const
Definition: box2.h:173
coord_type GetRight() const
Definition: box2.h:182
coord_type GetBottom() const
Definition: box2.h:183

References BOX2< Vec >::GetBottom(), BOX2< Vec >::GetRight(), BOX2< Vec >::GetX(), BOX2< Vec >::GetY(), and KIGFX::VIEW_ITEM::ViewBBox().

◆ Query()

template<class Visitor >
void KIGFX::VIEW_RTREE::Query ( const BOX2I aBounds,
Visitor &  aVisitor 
) const
inline

Execute a function object aVisitor for each item whose bounding box intersects with aBounds.

Definition at line 79 of file view_rtree.h.

80 {
81 int mmin[2] = { aBounds.GetX(), aBounds.GetY() };
82 int mmax[2] = { aBounds.GetRight(), aBounds.GetBottom() };
83
84 // We frequently use the maximum bounding box to recache all items
85 // or for any item that overflows the integer width limits of BBOX2I
86 // in this case, we search the full rtree whose bounds are absolute
87 // coordinates rather than relative
88 BOX2I max_box;
89 max_box.SetMaximum();
90
91 if( aBounds == max_box )
92 {
93 mmin[0] = mmin[1] = INT_MIN;
94 mmax[0] = mmax[1] = INT_MAX;
95 }
96
97 VIEW_RTREE_BASE::Search( mmin, mmax, aVisitor );
98 }
void SetMaximum()
Definition: box2.h:57

References BOX2< Vec >::GetBottom(), BOX2< Vec >::GetRight(), BOX2< Vec >::GetX(), BOX2< Vec >::GetY(), and BOX2< Vec >::SetMaximum().

◆ Remove()

void KIGFX::VIEW_RTREE::Remove ( VIEW_ITEM aItem)
inline

Remove an item from the tree.

Removal is done by comparing pointers, attempting to remove a copy of the item will fail.

Definition at line 63 of file view_rtree.h.

64 {
65 // const BOX2I& bbox = aItem->ViewBBox();
66
67 // FIXME: use cached bbox or ptr_map to speed up pointer <-> node lookups.
68 const int mmin[2] = { INT_MIN, INT_MIN };
69 const int mmax[2] = { INT_MAX, INT_MAX };
70
71 VIEW_RTREE_BASE::Remove( mmin, mmax, aItem );
72 }

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