-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPointAdder.java
88 lines (69 loc) · 2.19 KB
/
PointAdder.java
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
package quadtree;
import com.revivedstandards.input.Mouse;
import com.revivedstandards.main.StandardDraw;
import com.revivedstandards.util.StdOps;
import java.awt.Color;
import java.awt.Rectangle;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
/**
* This class is the MouseMotionListener and MouseListener companion class that
* allows for dragging the mouse across the screen to add points to the current
* QuadTree.
*
* @author Joshua Crotts
* @date 4/5/2020
*/
public class PointAdder extends Mouse {
private final QuadTree tree;
private boolean rightClicked = false;
private int oldX;
private int oldY;
public PointAdder(QuadTree tree) {
this.tree = tree;
}
@Override
public void mousePressed(MouseEvent e) {
if (e.getButton() == MouseEvent.BUTTON3) {
if (!this.rightClicked) {
this.rightClicked = true;
this.oldX = e.getX();
this.oldY = e.getY();
} else {
Rectangle queryRect = new Rectangle(oldX, oldY, Math.abs(e.getX() - oldX), Math.abs(e.getY() - oldY));
ArrayList<Point> queryPoints = this.tree.fastQuery(queryRect, new ArrayList<>());
//ArrayList<Point> queryPoints = this.tree.slowQuery(queryRect);
Color c = StandardDraw.getRandomColor();
for (Point p : queryPoints) {
p.setColor(c);
}
this.rightClicked = false;
}
} else {
for (int i = 0; i < 100000; i++) {
Point p = new Point(e.getX() + StdOps.rand(-5, 5), e.getY() + StdOps.rand(-5, 5));
this.tree.insert(p);
QuadTree.allPoints.add(p);
}
}
}
@Override
public void mouseDragged(MouseEvent e) {
this.mousePressed(e);
}
@Override
public void mouseClicked(MouseEvent e) {
}
@Override
public void mouseReleased(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
@Override
public void mouseMoved(MouseEvent e) {
}
}