9#include <unordered_map>
22 QuadTree(
float minX,
float minY,
float maxX,
float maxY,
int maxDepth = 8,
33 bool insert(
int id,
float minX,
float minY,
float maxX,
float maxY);
37 bool update(
int id,
float minX,
float minY,
float maxX,
float maxY);
39 bool contains(
int id)
const;
41 int getCount()
const {
return static_cast<int>(items_.size()); }
44 int queryPoint(
float x,
float y);
46 int queryRect(
float minX,
float minY,
float maxX,
float maxY);
48 int queryCircle(
float cx,
float cy,
float radius);
56 float getMinX()
const {
return rootBounds_.minX; }
58 float getMinY()
const {
return rootBounds_.minY; }
60 float getMaxX()
const {
return rootBounds_.maxX; }
62 float getMaxY()
const {
return rootBounds_.maxY; }
72 std::vector<int> itemIds;
74 bool isLeaf()
const {
return children[0] ==
nullptr; }
78 bool insertInto(Node &
node,
int id,
const AABB2 &
bounds);
80 void collect(Node &
node,
const AABB2 *rect,
float cx,
float cy,
float radius,
87 std::unique_ptr<Node> root_;
88 std::unordered_map<int, AABB2> items_;
#define EVENGINE_API_FOUNDATION
每个链接组(link group)各自的导出宏。
Region quadtree for 2D AABB broad-phase / map culling. Items are stored in the smallest node that ful...
QuadTree & operator=(const QuadTree &)=delete
float getMaxY() const
Root/world maximum Y.
int getCount() const
Number of stored ids.
int getResultId(int index) const
Hit id at dense index from the last query*, or -1.
int getMaxPerNode() const
Item capacity before a node splits.
float getMinY() const
Root/world minimum Y.
float getMaxX() const
Root/world maximum X.
~QuadTree()=default
Releases tree nodes.
QuadTree(const QuadTree &)=delete
int getResultCount() const
Number of hits from the last query*.
float getMinX() const
Root/world minimum X.
int getMaxDepth() const
Maximum subdivision depth.
Axis-aligned 2D bounding box (min/max inclusive).