aboutsummaryrefslogtreecommitdiff
#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;
};