-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQTreeNode.java
More file actions
213 lines (180 loc) · 4.31 KB
/
Copy pathQTreeNode.java
File metadata and controls
213 lines (180 loc) · 4.31 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/**
* This class represents a node in a quadrant tree, used in the class QuadrantTree.
*/
public class QTreeNode {
private int x;
private int y;
private int size;
private int color;
private QTreeNode parent;
private QTreeNode[] children;
/**
* Builds a new QTreeNode object with specific/default values.
*/
public QTreeNode() {
parent = null;
children = new QTreeNode[4];
for (int i = 0; i < 4; i++) {
children[i] = null;
}
x = 0;
y = 0;
size = 0;
color = 0;
}
/**
* Initializes every new QTreeNode with specified values.
*
* @param theChildren the child nodes
* @param xcoord the x-coordinate of the node
* @param ycoord the y-coordinate of the node
* @param theSize the size of the node
* @param theColor the color of the node
**/
public QTreeNode(QTreeNode[] theChildren, int xcoord, int ycoord, int theSize, int theColor) {
children = theChildren;
x = xcoord;
y = ycoord;
size = theSize;
color = theColor;
}
/**
* Inspects if a node contains the identified coordinate.
*
* @param xcoord - x-coordinate to verify
* @param ycoord - y-coordinate to verify
* @return true if a node contains the coordinates, false if not
**/
public boolean contains(int xcoord, int ycoord) {
if (xcoord < x || xcoord >= (x + size) || ycoord < y || ycoord >= (y + size)) {
return false;
} else {
return true;
}
}
/**
* Gets the x-coordinate of a tree node.
*
* @return the x-coordinate
*/
public int getx() {
return x;
}
/**
* Gets the y-coordinate of a tree node.
*
* @return the y-coordinate
*/
public int gety() {
return y;
}
/**
* Gets the size of a tree node.
*
* @return the size
*/
public int getSize() {
return size;
}
/**
* Gets the color of a tree node.
*
* @return the color
*/
public int getColor() {
return color;
}
/**
* Retrieves the parent node in relation to the current node.
*
* @return the parent node
*/
public QTreeNode getParent() {
return parent;
}
/**
* Gets a child node at the stated index.
*
* @param index is the index of the child node to retrieve
* @return the child node of the stated index
* @throws QTreeException if the index is out of bounds or the children array is null
*/
public QTreeNode getChild(int index) throws QTreeException {
if (index < 0 || index > 3) {
throw new QTreeException("QTreeException");
} else if (children == null) {
throw new QTreeException("children array is full");
} else {
return children[index];
}
}
/**
* Sets the x-coordinate of the treenode to a value.
*
* @param newx the new x-coordinate
*/
public void setx(int newx) {
x = newx;
}
/**
* Sets the y-coordinate of the treenode to a value.
*
* @param newy the new y-coordinate
*/
public void sety(int newy) {
y = newy;
}
/**
* Sets the size of a node to a specific value.
*
* @param newSize is the new size
*/
public void setSize(int newSize) {
size = newSize;
}
/**
* Sets the color of the treenode to the specified value.
*
* @param newColor the new color
*/
public void setColor(int newColor) {
color = newColor;
}
/**
* Sets the parent node of the current node to the specified parent node.
*
* @param newParent the new parent node
*/
public void setParent(QTreeNode newParent) {
parent = newParent;
}
/**
* Sets the child node at the given index to a specific child node.
*
* @param newChild the new child node
* @param index the index at which to set the child node
* @throws QTreeException if the index is out of bounds
*/
public void setChild(QTreeNode newChild, int index) {
if (index < 0 || index > 3) {
throw new QTreeException("QTreeNode Exception ");
}
children[index] = newChild;
}
/**
* Verifies if a node is a leaf node has no children(has no children)
*
* @return true if the node is a leaf, false otherwise
*/
public boolean isLeaf() {
if (children == null) {
return true;
}
for (QTreeNode children : children) {
if (children == null) {
return true;
}
}
return false;
}
}