-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPointQuadtree.java
More file actions
102 lines (87 loc) · 2.34 KB
/
PointQuadtree.java
File metadata and controls
102 lines (87 loc) · 2.34 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
import java.util.ArrayList;
import java.util.List;
/**
* A point quadtree: stores an element at a 2D position,
* with children at the subdivided quadrants
*
* @author Chris Bailey-Kellogg, Dartmouth CS 10, Spring 2015
* @author CBK, Spring 2016, explicit rectangle
* @author CBK, Fall 2016, generic with Point2D interface
*
*/
public class PointQuadtree<E extends Point2D> {
private E point; // the point anchoring this node
private int x1, y1; // upper-left corner of the region
private int x2, y2; // bottom-right corner of the region
private PointQuadtree<E> c1, c2, c3, c4; // children
/**
* Initializes a leaf quadtree, holding the point in the rectangle
*/
public PointQuadtree(E point, int x1, int y1, int x2, int y2) {
this.point = point;
this.x1 = x1; this.y1 = y1; this.x2 = x2; this.y2 = y2;
}
// Getters
public E getPoint() {
return point;
}
public int getX1() {
return x1;
}
public int getY1() {
return y1;
}
public int getX2() {
return x2;
}
public int getY2() {
return y2;
}
/**
* Returns the child (if any) at the given quadrant, 1-4
* @param quadrant 1 through 4
*/
public PointQuadtree<E> getChild(int quadrant) {
if (quadrant==1) return c1;
if (quadrant==2) return c2;
if (quadrant==3) return c3;
if (quadrant==4) return c4;
return null;
}
/**
* Returns whether or not there is a child at the given quadrant, 1-4
* @param quadrant 1 through 4
*/
public boolean hasChild(int quadrant) {
return (quadrant==1 && c1!=null) || (quadrant==2 && c2!=null) || (quadrant==3 && c3!=null) || (quadrant==4 && c4!=null);
}
/**
* Inserts the point into the tree
*/
public void insert(E p2) {
// TODO: YOUR CODE HERE
}
/**
* Finds the number of points in the quadtree (including its descendants)
*/
public int size() {
// TODO: YOUR CODE HERE
}
/**
* Builds a list of all the points in the quadtree (including its descendants)
*/
public List<E> allPoints() {
// TODO: YOUR CODE HERE
}
/**
* Uses the quadtree to find all points within the circle
* @param cx circle center x
* @param cy circle center y
* @param cr circle radius
* @return the points in the circle (and the qt's rectangle)
*/
public List<E> findInCircle(double cx, double cy, double cr) {
// TODO: YOUR CODE HERE
}
// TODO: YOUR CODE HERE for any helper methods
}