This repository has been archived by the owner on Nov 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqtnode.h
69 lines (54 loc) · 1.61 KB
/
qtnode.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#ifndef QUAD_TREE_QTNODE_H
#define QUAD_TREE_QTNODE_H
namespace qt {
template<typename T, typename PairT, typename ContainerT>
class QuadTree;
template<typename T, typename PairT = std::pair<Vertex, T>, typename ContainerT = std::vector<PairT>>
class QuadTreeNode {
friend class QuadTree<T, PairT, ContainerT>;
protected:
Vertex m_center;
Vertex m_range;
QuadTreeNode *m_parent;
QuadTreeNode *m_children[4];
bool m_leaf;
ContainerT m_bucket{};
public:
QuadTreeNode<T>(const Vertex ¢er, const Vertex &range, QuadTreeNode<T> *parent = nullptr) :
m_center{center}, m_range{range}, m_leaf{true} {
this->m_parent = parent;
for (auto &c: m_children) c = nullptr;
}
~QuadTreeNode() {
for (auto &c: m_children) delete c;
}
Vertex center() const {
return m_center;
}
Vertex range() const {
return m_range;
}
QuadTreeNode *parent() const {
return m_parent;
}
QuadTreeNode *children() const {
return m_children;
}
ContainerT *&bucket() {
return m_bucket;
}
bool is_leaf() const {
return m_leaf;
}
void set_parent(QuadTreeNode *&parent_node) {
m_parent = parent_node;
}
Vertex top_right() const {
return m_center + m_range;
}
Vertex bottom_left() const {
return m_center - m_range;
}
};
}
#endif //QUAD_TREE_QTNODE_H