aboutsummaryrefslogtreecommitdiff
path: root/quadtree.h
diff options
context:
space:
mode:
authorSamuel Fadel <samuel@nihil.ws>2023-05-23 11:22:33 +0200
committerSamuel Fadel <samuel@nihil.ws>2023-05-23 11:22:33 +0200
commit0f34fd437efb936ef29ac91186321aa7251fbfb1 (patch)
tree271e994828f4bb19c35b2630f2705cb64b8d4552 /quadtree.h
parentbedf6936885694688ddb8bd3452f6bd68ef8d29c (diff)
Massive changes in initial port away from Qt.
Diffstat (limited to 'quadtree.h')
-rw-r--r--quadtree.h23
1 files changed, 23 insertions, 0 deletions
diff --git a/quadtree.h b/quadtree.h
new file mode 100644
index 0000000..0a9b79b
--- /dev/null
+++ b/quadtree.h
@@ -0,0 +1,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;
+};