-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQuadTreeNode.h
42 lines (35 loc) · 1.01 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
//
// Created by bear on 2021-10-01.
//
#ifndef UNTITLED_QUADTREENODE_H
#define UNTITLED_QUADTREENODE_H
#include <unordered_set>
#include <vector>
#include "Rectangle2D.h"
const int CAPACITY = 4;
const int MIN_WIDTH = 5;
const int MIN_HEIGHT = 5;
/**
CAPACITY / MIN_WIDTH / MIN_HEIGHT / time
4 5 5 147ms
5 5 5 153ms
6 5 5 145ms
*/
class QuadTreeNode {
private:
//how many rectangles a square contain
static const int capacity = CAPACITY;
void divideSquare();
public:
QuadTreeNode *topLeft = nullptr;
QuadTreeNode *topRight = nullptr;
QuadTreeNode *bottomLeft = nullptr;
QuadTreeNode *bottomRight = nullptr;
std::vector<Rectangle2D> rects;
Rectangle2D thisRect;
QuadTreeNode(float minX, float minY, float maxX, float maxY) : thisRect(minX, minY, maxX, maxY) {}
bool HasChildren();
void Insert(const Rectangle2D &rect);
void IntersectCount(int * count);
};
#endif //UNTITLED_QUADTREENODE_H