21#ifndef GF_SPATIAL_QUAD_TREE_H
22#define GF_SPATIAL_QUAD_TREE_H
27#include "BlockAllocator.h"
31#include "SpatialTypes.h"
34#ifndef DOXYGEN_SHOULD_SKIP_THIS
99 std::size_t allocateEntry();
100 void disposeEntry(std::size_t index);
102 std::size_t allocateNode();
103 void disposeNode(std::size_t index);
105 bool doInsert(std::size_t entryIndex, std::size_t nodeIndex);
107 void doRemove(std::size_t entryIndex);
109 void subdivide(std::size_t nodeIndex);
110 void sanitize(std::size_t nodeIndex);
113 static constexpr std::size_t Size = 16;
114 static constexpr std::size_t Null =
static_cast<std::size_t
>(-1);
126 std::vector<std::size_t> entries;
128 std::size_t children[4];
131 return children[0] == Null;
135 BlockAllocator<Node> m_nodes;
140#ifndef DOXYGEN_SHOULD_SKIP_THIS
A handle to an object or an id.
Definition: Handle.h:40
An implementation of quadtree.
Definition: Spatial_Quadtree.h:45
void modify(SpatialId id, RectF bounds)
Modify the bounds of an object.
void clear()
Remove all the objects from the tree.
Handle operator[](SpatialId id)
Get the handle associated to a spatial id.
std::size_t query(const RectF &bounds, SpatialQueryCallback callback, SpatialQuery kind=SpatialQuery::Intersect)
Query objects in the tree.
Quadtree(const RectF &bounds)
Constructor.
SpatialId insert(Handle handle, const RectF &bounds)
Insert an object in the tree.
void remove(SpatialId id)
Remove an object from the tree.
SpatialQuery
A kind of spatial query.
Definition: SpatialTypes.h:73
std::function< void(Handle)> SpatialQueryCallback
A callback for spatial query.
Definition: SpatialTypes.h:82
SpatialId
A spatial id.
Definition: SpatialTypes.h:42
@ Node
The structure represents an internal node.
@ Intersect
Search for all objects that intersect the given bounds.
The namespace for gf classes.