-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSquare.java
More file actions
47 lines (32 loc) · 954 Bytes
/
Square.java
File metadata and controls
47 lines (32 loc) · 954 Bytes
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
/*
Brendan DeMilt Chris Pan
Period: 8
Object that represents a quadrant of space
*/
public class Square {
private double x,y,len;
public Square(double bottomX, double bottomY, double length){
x = bottomX;
y = bottomY;
len = length;
}
//returns bottom left corner of the square, plus the length
public double[] getBottom(){
double[] pos = {this.x,this.y};
return pos;
}
public double getLen(){
return this.len;
}
//determines if a planet object is inside of a square
public boolean contains(Planet b){
return x <= b.getPos()[0] && b.getPos()[0] <= (x+len) && y <= b.getPos()[1] && b.getPos()[1] <= (y+len);
}
//draws the current square for debugging purposes
public void draw(){
StdDraw.setPenRadius(.0001);
StdDraw.setPenColor(StdDraw.WHITE);
StdDraw.square(this.x+this.len/2,this.y+this.len/2, this.len/2);
StdDraw.setPenRadius(.002);
}
}