forked from emblaser/HW6
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRectangle.java
More file actions
31 lines (27 loc) · 1.04 KB
/
Rectangle.java
File metadata and controls
31 lines (27 loc) · 1.04 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
// A class to represent a Rectangle
// You do not have to use this, but it's quite convenient
public class Rectangle {
// invariant: right >= left and top >= bottom (i.e., numbers get bigger as you move up/right)
// note in our census data longitude "West" is a negative number which nicely matches bigger-to-the-right
public float left;
public float right;
public float top;
public float bottom;
public Rectangle(float l, float r, float t, float b) {
left = l;
right = r;
top = t;
bottom = b;
}
// a functional operation: returns a new Rectangle that is the smallest rectangle
// containing this and that
public Rectangle encompass(Rectangle that) {
return new Rectangle(Math.min(this.left, that.left),
Math.max(this.right, that.right),
Math.max(this.top, that.top),
Math.min(this.bottom, that.bottom));
}
public String toString() {
return "[left=" + left + " right=" + right + " top=" + top + " bottom=" + bottom + "]";
}
}