-
Notifications
You must be signed in to change notification settings - Fork 0
/
QuadTreeNode.h
77 lines (52 loc) · 1.69 KB
/
QuadTreeNode.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
70
71
72
73
74
75
76
77
#ifndef QDT_QUADTREENODE_H
#define QDT_QUADTREENODE_H
#include "AABB.h"
#include "Point2i.h"
#include "QuadTreeOccupant.h"
#include <vector>
#include <unordered_set>
#include <memory>
namespace qdt
{
class QuadTreeNode
{
private:
class QuadTreeNode* m_pParent;
class QuadTree* m_pQuadTree;
// Cannot use a unique_ptr, since the vector requires copy ctor/assignment ops
std::vector<std::vector<QuadTreeNode>>* m_children;
bool m_hasChildren;
std::unordered_set<class QuadTreeOccupant*> m_pOccupants;
AABB m_region;
int m_level;
int m_numOccupantsBelow;
inline QuadTreeNode* GetChild(const Point2i position);
void GetPossibleOccupantPosition(QuadTreeOccupant* pOc, Point2i &point);
void AddToThisLevel(QuadTreeOccupant* pOc);
// Returns true if occupant was added to children
bool AddToChildren(QuadTreeOccupant* pOc);
void GetOccupants(std::unordered_set<QuadTreeOccupant*> &occupants);
void Partition();
void DestroyChildren();
void Merge();
void Update(QuadTreeOccupant* pOc);
void Remove(QuadTreeOccupant* pOc);
public:
static int minNumOccupants;
static int maxNumOccupants;
static int maxNumLevels;
static float m_oversizeMultiplier;
QuadTreeNode();
QuadTreeNode(const AABB ®ion, int level, QuadTreeNode* pParent = NULL, QuadTree* pQuadTree = NULL);
~QuadTreeNode();
// For use after using default constructor
void Create(const AABB ®ion, int level, QuadTreeNode* pParent = NULL, QuadTree* pQuadTree = NULL);
QuadTree* GetTree();
void Add(QuadTreeOccupant* pOc);
const AABB &GetRegion();
void GetAllOccupantsBelow(std::vector<QuadTreeOccupant*> &occupants);
friend class QuadTreeOccupant;
friend class QuadTree;
};
}
#endif