26 #ifndef __SHAPE_INDEX_H
27 #define __SHAPE_INDEX_H
30 #include <geometry/shape.h>
31 #include <geometry/rtree.h>
44 static const SHAPE* shapeFunctor( T aItem )
46 return aItem->Shape();
59 BOX2I boundingBox( T aObject )
61 return shapeFunctor( aObject )->
BBox();
73 template <
class T,
class V>
74 void acceptVisitor( T aObject, V aVisitor )
90 template <
class T,
class U>
91 bool collide( T aObject, U aAnotherObject,
int aMinDistance )
93 return shapeFunctor( aObject )->
Collide( aAnotherObject, aMinDistance );
96 template <
class T,
class V>
97 bool queryCallback( T aShape,
void* aContext )
99 V* visitor = (V*) aContext;
101 acceptVisitor<T, V>( aShape, *visitor );
106 template <
class T = SHAPE*>
114 RTreeIterator iterator;
136 Init( aIndex->m_tree );
177 return iterator.IsNull();
188 return iterator.IsNotNull();
200 T
object = *iterator;
217 void Add( T aShape );
248 acceptVisitor( shape, aVisitor );
270 int Query(
const SHAPE *aShape,
int aMinDistance, V& aVisitor,
bool aExact )
275 int min[2] = { box.GetX(), box.GetY() };
276 int max[2] = { box.GetRight(), box.GetBottom() };
278 return this->m_tree->
Search( min, max, aVisitor );
312 BOX2I box = boundingBox( aShape );
313 int min[2] = { box.GetX(), box.GetY() };
314 int max[2] = { box.GetRight(), box.GetBottom() };
316 this->m_tree->Insert( min, max, aShape );
322 BOX2I box = boundingBox( aShape );
323 int min[2] = { box.GetX(), box.GetY() };
324 int max[2] = { box.GetRight(), box.GetBottom() };
326 this->m_tree->Remove( min, max, aShape );
332 this->m_tree->RemoveAll();
346 BOX2I box = boundingBox( shape );
347 int min[2] = { box.GetX(), box.GetY() };
348 int max[2] = { box.GetRight(), box.GetBottom() };
349 newTree->
Insert( min, max, shape );
354 this->m_tree = newTree;
BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Function Inflate inflates the rectangle horizontally by dx and vertically by dy.
Definition: box2.h:300
Implementation of RTree, a multidimensional bounding rectangle tree.
Definition: rtree.h:77
int Search(const ELEMTYPE a_min[NUMDIMS], const ELEMTYPE a_max[NUMDIMS], std::function< bool(const DATATYPE &)> a_callback) const
Find all within search rectangle.
void Insert(const ELEMTYPE a_min[NUMDIMS], const ELEMTYPE a_max[NUMDIMS], const DATATYPE &a_dataId)
Insert entry.
void GetFirst(Iterator &a_it)
Get 'first' for iteration.
Definition: rtree.h:333
Definition: shape_index.h:111
bool operator++()
Operator ++ (prefix)
Definition: shape_index.h:154
bool IsNotNull()
Function IsNotNull()
Definition: shape_index.h:186
bool IsNull()
Function IsNull()
Definition: shape_index.h:175
bool operator++(int)
Operator ++ (postfix)
Definition: shape_index.h:164
T Next()
Function Next()
Definition: shape_index.h:198
T operator*()
Operator * (prefix)
Definition: shape_index.h:144
Iterator(SHAPE_INDEX *aIndex)
Iterator constructor.
Definition: shape_index.h:134
Definition: shape_index.h:108
int Query(const SHAPE *aShape, int aMinDistance, V &aVisitor, bool aExact)
Function Query()
Definition: shape_index.h:270
void Remove(T aShape)
Function Remove()
Definition: shape_index.h:320
Iterator Begin()
Function Begin()
Definition: shape_index.h:358
void RemoveAll()
Function RemoveAll()
Definition: shape_index.h:330
void Accept(V aVisitor)
Function Accept()
Definition: shape_index.h:241
void Reindex()
Function Reindex()
Definition: shape_index.h:336
void Add(T aShape)
Function Add()
Definition: shape_index.h:310
Class SHAPE.
Definition: shape.h:59
virtual bool Collide(const VECTOR2I &aP, int aClearance=0) const
Function Collide()
Definition: shape.h:107
virtual const BOX2I BBox(int aClearance=0) const =0
Function BBox()