KiCad PCB EDA Suite
KIGFX::VIEW_RTREE Class Reference

VIEW_RTREE - Implements an 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)
 Function Insert() Inserts an item into the tree. More...
 
void Remove (VIEW_ITEM *aItem)
 Function Remove() Removes an item from the tree. More...
 
template<class Visitor >
void Query (const BOX2I &aBounds, Visitor &aVisitor)
 Function Query() Executes a function object aVisitor for each item whose bounding box intersects with aBounds. More...
 

Detailed Description

VIEW_RTREE - Implements an R-tree for fast spatial indexing of VIEW items.

Non-owning.

Definition at line 41 of file view_rtree.h.

Member Function Documentation

◆ Insert()

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

Function Insert() Inserts 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 GetX() const
Definition: box2.h:190
coord_type GetRight() const
Definition: box2.h:199
coord_type GetBottom() const
Definition: box2.h:200
coord_type GetY() const
Definition: box2.h:191

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 
)
inline

Function Query() Executes a function object aVisitor for each item whose bounding box intersects with aBounds.

Definition at line 80 of file view_rtree.h.

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

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

Function Remove() Removes an item from the tree.

Removal is done by comparing pointers, attepmting 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: