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;
245 while( !iter.IsNull() )
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();
341 Iterator iter = this->Begin();
343 while( !iter.IsNull() )
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;
360 return Iterator(
this );