-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQTreeNode.java
More file actions
101 lines (85 loc) · 2.65 KB
/
QTreeNode.java
File metadata and controls
101 lines (85 loc) · 2.65 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
public class QTreeNode {
private int x, y; // Coordinates of the upper left corner of the quadrant
private int size; // Size of the quadrant
private int color; // Average color of the pixels in the quadrant
private QTreeNode parent; // Parent node
private QTreeNode[] children; // Children nodes
// Default constructor
public QTreeNode() {
this.x = 0;
this.y = 0;
this.size = 0;
this.color = 0;
this.parent = null;
this.children = new QTreeNode[4]; // Initialize with 4 null children
}
// Parameterized constructor
public QTreeNode(QTreeNode[] theChildren, int xcoord, int ycoord, int theSize, int theColor) {
this.x = xcoord;
this.y = ycoord;
this.size = theSize;
this.color = theColor;
this.parent = null; // Parent is initially null; it can be set later using setParent method
this.children = theChildren; // Set the children directly from the parameter
}
// Check if the point is within the quadrant
public boolean contains(int xcoord, int ycoord) {
return xcoord >= x && xcoord < x + size && ycoord >= y && ycoord < y + size;
}
// Getters
public int getx() {
return x;
}
public int gety() {
return y;
}
public int getSize() {
return size;
}
public int getColor() {
return color;
}
public QTreeNode getParent() {
return parent;
}
public QTreeNode getChild(int index) throws QTreeException {
if (index < 0 || index > 3 || children == null) {
throw new QTreeException("Child index is out of bounds or children are null");
}
return children[index];
}
// Setters
public void setX(int newx) {
this.x = newx;
}
public void setY(int newy) {
this.y = newy;
}
public void setSize(int newSize) {
this.size = newSize;
}
public void setColor(int newColor) {
this.color = newColor;
}
public void setParent(QTreeNode newParent) {
this.parent = newParent;
}
public void setChild(QTreeNode newChild,int index) throws QTreeException {
if (index < 0 || index > 3 || children == null) {
throw new QTreeException("Child index is out of bounds or children are null");
}
this.children[index] = newChild;
}
// Check if this node is a leaf
public boolean isLeaf() {
if (children == null) {
return true;
}
for (QTreeNode child : children) {
if (child != null) {
return false;
}
}
return true;
}
}