| 2 | |
| 3 | //javadoc:Rect_ |
| 4 | public class Rect { |
| 5 | |
| 6 | public int x, y, width, height; |
| 7 | |
| 8 | public Rect(int x, int y, int width, int height) { |
| 9 | this.x = x; |
| 10 | this.y = y; |
| 11 | this.width = width; |
| 12 | this.height = height; |
| 13 | } |
| 14 | |
| 15 | public Rect() { |
| 16 | this(0, 0, 0, 0); |
| 17 | } |
| 18 | |
| 19 | public Rect(Point p1, Point p2) { |
| 20 | x = (int) (p1.x < p2.x ? p1.x : p2.x); |
| 21 | y = (int) (p1.y < p2.y ? p1.y : p2.y); |
| 22 | width = (int) (p1.x > p2.x ? p1.x : p2.x) - x; |
| 23 | height = (int) (p1.y > p2.y ? p1.y : p2.y) - y; |
| 24 | } |
| 25 | |
| 26 | public Rect(Point p, Size s) { |
| 27 | this((int) p.x, (int) p.y, (int) s.width, (int) s.height); |
| 28 | } |
| 29 | |
| 30 | public Rect(double[] vals) { |
| 31 | set(vals); |
| 32 | } |
| 33 | |
| 34 | public void set(double[] vals) { |
| 35 | if (vals != null) { |
| 36 | x = vals.length > 0 ? (int) vals[0] : 0; |
| 37 | y = vals.length > 1 ? (int) vals[1] : 0; |
| 38 | width = vals.length > 2 ? (int) vals[2] : 0; |
| 39 | height = vals.length > 3 ? (int) vals[3] : 0; |
| 40 | } else { |
| 41 | x = 0; |
| 42 | y = 0; |
| 43 | width = 0; |
| 44 | height = 0; |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | public Rect clone() { |
| 49 | return new Rect(x, y, width, height); |
| 50 | } |
| 51 | |
| 52 | public Point tl() { |
| 53 | return new Point(x, y); |
| 54 | } |
| 55 | |
| 56 | public Point br() { |
| 57 | return new Point(x + width, y + height); |
| 58 | } |
| 59 | |
| 60 | public Size size() { |
| 61 | return new Size(width, height); |
no outgoing calls