28#ifndef __SHAPE_INDEX_H
29#define __SHAPE_INDEX_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;
112template <
class T = SHAPE*>
220 int min[2] = { box.
GetX(), box.
GetY() };
223 m_tree.Insert( min, max, aShape );
234 int min[2] = { aBbox.
GetX(), aBbox.
GetY() };
237 m_tree.Insert( min, max, aShape );
248 int min[2] = { box.
GetX(), box.
GetY() };
251 m_tree.Remove( min, max, aShape );
278 void BulkLoad( std::vector<std::pair<T, BOX2I>>& aItems )
281 std::vector<BULK_ENTRY> entries;
282 entries.reserve( aItems.size() );
284 for(
const auto& [item, box] : aItems )
287 e.min[0] = box.GetX();
288 e.min[1] = box.GetY();
289 e.max[0] = box.GetRight();
290 e.max[1] = box.GetBottom();
292 entries.push_back( e );
295 m_tree.BulkLoad( entries );
305 std::vector<T> items;
306 items.reserve(
m_tree.size() );
309 items.push_back( item );
313 for(
T& item : items )
325 int Query(
const SHAPE *aShape,
int aMinDistance, V& aVisitor)
const
330 int min[2] = { box.
GetX(), box.
GetY() };
333 return m_tree.Search( min, max, aVisitor );
343 return Iterator(
m_tree );
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
Iterator for traversing all data items.
Copy-on-Write wrapper for DYNAMIC_RTREE.
typename DYNAMIC_RTREE< DATATYPE, ELEMTYPE, NUMDIMS, TMAXNODES >::BULK_ENTRY BULK_ENTRY
Bulk load entries using Hilbert curve sorting and bottom-up packing.
bool operator++()
Shift the iterator to the next element.
bool IsNotNull() const
Check if the iterator has not reached the end.
bool operator++(int)
Shift the iterator to the next element.
typename TREE_TYPE::Iterator TreeIterator
T Next()
Return the current element of the iterator and moves to the next position.
bool IsNull() const
Check if the iterator has reached the end.
Iterator(const TREE_TYPE &aTree)
Iterator Begin() const
Create an iterator for the current index object.
TREE_TYPE::Iterator begin() const
SHAPE_INDEX(SHAPE_INDEX &&aOther) noexcept=default
void Remove(T aShape)
Remove a SHAPE from the index.
void BulkLoad(std::vector< std::pair< T, BOX2I > > &aItems)
Build from a batch of items using Hilbert-curve bulk loading.
SHAPE_INDEX & operator=(const SHAPE_INDEX &)=delete
TREE_TYPE::Iterator end() const
SHAPE_INDEX & operator=(SHAPE_INDEX &&aOther) noexcept=default
KIRTREE::COW_RTREE< T, int, 2 > TREE_TYPE
SHAPE_INDEX(const SHAPE_INDEX &)=delete
SHAPE_INDEX Clone() const
Create a CoW clone that shares tree structure with this index.
void Add(T aShape, const BOX2I &aBbox)
Add a shape with alternate BBox.
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.