blob: 0a9b79b7461045f94b303d09371854205b0be2a2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
#include <memory>
#include <vector>
#include "geometry.h"
class QuadTree
{
public:
QuadTree(const RectF &bounds);
bool insert(float x, float y, int value);
int query(float x, float y) const;
void query(const RectF &rect, std::vector<int> &result) const;
int nearestTo(float x, float y) const;
private:
bool subdivide();
void nearestTo(float x, float y, int &nearest, float &dist) const;
RectF m_bounds;
float m_x, m_y;
int m_value;
std::unique_ptr<QuadTree> m_nw, m_ne, m_sw, m_se;
};
|