28#ifndef __SHAPE_INDEX_H
29#define __SHAPE_INDEX_H
33#include <geometry/rtree.h>
49 return aItem->Shape( aLayer );
78template <
class T,
class V>
96template <
class T,
class U>
97bool collide( T aObject, U aAnotherObject,
int aLayer,
int aMinDistance )
102template <
class T,
class V>
105 V* visitor = (V*) aContext;
107 acceptVisitor<T, V>( aShape, *visitor );
112template <
class T = SHAPE*>
127 void Init( RTree<T, int, 2, double>* aTree )
210 void Add( T aShape );
218 void Add( T aShape,
const BOX2I& aBbox );
265 int Query(
const SHAPE *aShape,
int aMinDistance, V& aVisitor)
const
270 int min[2] = { box.
GetX(), box.
GetY() };
273 return this->
m_tree->Search( min, max, aVisitor );
295 this->m_tree =
new RTree<T, int, 2, double>();
296 this->m_shapeLayer = aLayer;
308 int min[2] = { aBbox.
GetX(), aBbox.
GetY() };
311 this->m_tree->Insert( min, max, aShape );
318 int min[2] = { box.
GetX(), box.
GetY() };
321 this->m_tree->Insert( min, max, aShape );
328 int min[2] = { box.
GetX(), box.
GetY() };
331 this->m_tree->Remove( min, max, aShape );
337 this->m_tree->RemoveAll();
343 RTree<T, int, 2, double>* newTree;
344 newTree =
new RTree<T, int, 2, double>();
352 int min[2] = { box.
GetX(), box.
GetY() };
354 newTree->Insert( min, max, shape );
359 this->m_tree = newTree;
constexpr BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
constexpr coord_type GetY() const
constexpr coord_type GetX() const
constexpr coord_type GetRight() const
constexpr coord_type GetBottom() const
bool operator++()
Shift the iterator to the next element.
RTree< T, int, 2, double >::Iterator RTreeIterator
bool IsNotNull() const
Check if the iterator has not reached the end.
bool operator++(int)
Shift the iterator to the next element.
T Next()
Return the current element of the iterator and moves to the next position.
void Init(RTree< T, int, 2, double > *aTree)
Setup the internal tree iterator.
bool IsNull() const
Check if the iterator has reached the end.
T operator*()
Return the next data element.
Iterator(SHAPE_INDEX *aIndex)
Create an iterator for the index object.
void Remove(T aShape)
Remove a SHAPE from the index.
RTree< T, int, 2, double > * m_tree
Iterator Begin()
Create an iterator for the current index object.
void RemoveAll()
Remove all the contents of the index.
void Accept(V aVisitor)
Accept a visitor for every SHAPE object contained in this INDEX.
void Reindex()
Rebuild the index.
void Add(T aShape)
Add a SHAPE to the index.
int Query(const SHAPE *aShape, int aMinDistance, V &aVisitor) const
Run a callback on every SHAPE object contained in the bounding box of (shape).
An abstract shape on 2D plane.
virtual bool Collide(const VECTOR2I &aP, int aClearance=0, int *aActual=nullptr, VECTOR2I *aLocation=nullptr) const
Check if the boundary of shape (this) lies closer to the point aP than aClearance,...
virtual const BOX2I BBox(int aClearance=0) const =0
Compute a bounding box of the shape, with a margin of aClearance a collision.
bool collide(T aObject, U aAnotherObject, int aLayer, int aMinDistance)
Used by SHAPE_INDEX to implement Query().
bool queryCallback(T aShape, void *aContext)
static const SHAPE * shapeFunctor(T aItem, int aLayer)
Used by SHAPE_INDEX to get a SHAPE* from another type.
void acceptVisitor(T aObject, V aVisitor)
Used by SHAPE_INDEX to implement Accept().
BOX2I boundingBox(T aObject, int aLayer)
Used by SHAPE_INDEX to get the bounding box of a generic T object.