-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuadTree.h
More file actions
103 lines (80 loc) · 2.26 KB
/
QuadTree.h
File metadata and controls
103 lines (80 loc) · 2.26 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#ifndef QUADTREE_H
#define QUADTREE_H
#include <vector>
#include "Point.h"
#include "BBox.h"
#include "QTQuad.h"
class QuadTree {
public:
// Nested class definition for associated iterator type
//
int num;
class iterator {
// if pointing to quadrants, should traverse in quadrant order:
// quadrant I, then II, then III, then IV, depth-first recursively;
// at grid leaf level, traverse cells in row-major form
// ([0][0], [0][1], etc.)
public:
//int num;
QTQuad * root;
QTQuad * curr;
int* currCell;
int x;
int y;
iterator();
//iterator(QuadTree *Q);
~iterator();
void printNum(QuadTree *Q);
bool operator==(const QuadTree::iterator &other);
bool operator!=(const QuadTree::iterator &other);
// Following two operators move on to next non-zero cell
iterator &operator++(); // Prefix: e.g. "++it"
iterator operator++(int dummy); // Postfix: "it++"
Point &operator*();
const iterator &operator=(const iterator &rhs);
private:
//
// YOU CAN ADD OTHER MEMBER DATA, HELPER FUNCTIONS, ETC.
// AS NEEDED HERE.
//
friend class QuadTree;
};
//
// Now, the stuff for the main class:
//
QuadTree(); // Creates a 16x16 default board
QuadTree(const BBox &bounds);
~QuadTree();
// Retrieve cell value
int get(const Point &pt);
// Set cell value
void set(const Point &pt, int data);
// Modify cell value by a signed delta amount; faster then get() + set()
int increment(const Point &pt, int delta = 1); //
// Clear all cells in tree
void clearAll();
// return iterator to first non-zero cell; == end() if qtree empty
iterator begin();
// iterator pointing beyond last cell;
iterator end();
// Print out structure of tree
void dump();
// Grading function. Do not implement!
bool inspect(QTQuad * &root, BBox &bounds, BBox &m_qBounds);
friend class QuadTree::iterator;
private:
// Root of the entire QTQuad tree; always non-NULL
QTQuad * m_root;
// Holds the actual bounds of the board requested by the user
BBox m_bounds;
// Holds the expanded power-of-2 dimensioned bounding box that defines
// the root quadrant of the tree
BBox m_qBounds;
//iterator it;
//iterator result;
//
// YOU CAN ADD ANY OTHER CONSTRUCTORS, MEMBER FUNCTIONS, MEMBER DATA, ETC.
// AS NEEDED HERE.
//
};
#endif