App

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

Rect.java
Go to the documentation of this file.
1 package mhr.appcore.utils;
2
8 public class Rect {
9 public int tlx;
10 public int tly;
11 public int brx;
12 public int bry;
13
17 public Rect() {
18 tlx = 0;
19 tly = 0;
20 brx = 0;
21 bry = 0;
22 }
23
31 public Rect(int tlx, int tly, int brx, int bry) {
32 this.tlx = tlx;
33 this.tly = tly;
34 this.brx = brx;
35 this.bry = bry;
36 }
37
43 public Rect(int width, int height) {
44 tlx = 0;
45 tly = 0;
46 brx = width;
47 bry = height;
48 }
49
54 public Rect(Rect other) {
55 this.tlx = other.tlx;
56 this.tly = other.tly;
57 this.brx = other.brx;
58 this.bry = other.bry;
59 }
60
65 public int getWidth() {
66 return brx - tlx;
67 }
68
73 public int getHeight() {
74 return bry - tly;
75 }
76
83 public Rect moveBy(int offsetX, int offsetY) {
84 tlx += offsetX;
85 tly += offsetY;
86 brx += offsetX;
87 bry += offsetY;
88 return this;
89 }
90
96 public Rect cover(Rect other) {
97 tlx = (tlx < other.tlx) ? tlx : other.tlx;
98 tly = (tly < other.tly) ? tly : other.tly;
99 brx = (brx > other.brx) ? brx : other.brx;
100 bry = (bry > other.bry) ? bry : other.bry;
101 return this;
102 }
103
109 public Rect cropBy(Rect other) {
110 tlx = (tlx > other.tlx) ? tlx : other.tlx;
111 tly = (tly > other.tly) ? tly : other.tly;
112 brx = (brx < other.brx) ? brx : other.brx;
113 bry = (bry < other.bry) ? bry : other.bry;
114 return this;
115 }
116
122 public Rect growBy(int dim) {
123 tlx -= dim;
124 tly -= dim;
125 brx += dim;
126 bry += dim;
127 return this;
128 }
129
134 public long getArea() {
135 return getWidth() * getHeight();
136 }
137 }