JAL-3130 adapted getdown src. attempt 2. first attempt failed due to cp'ed .git files
[jalview.git] / getdown / src / getdown / core / src / main / java / com / threerings / getdown / util / Rectangle.java
1 //
2 // Getdown - application installer, patcher and launcher
3 // Copyright (C) 2004-2018 Getdown authors
4 // https://github.com/threerings/getdown/blob/master/LICENSE
5
6 package com.threerings.getdown.util;
7
8 /**
9  * An immutable rectangle.
10  */
11 public class Rectangle
12 {
13     public final int x;
14     public final int y;
15     public final int width;
16     public final int height;
17
18     public Rectangle (int x, int y, int width, int height)
19     {
20         this.x = x;
21         this.y = y;
22         this.width = width;
23         this.height = height;
24     }
25
26     public Rectangle union (Rectangle other) {
27         int x1 = Math.min(x, other.x);
28         int x2 = Math.max(x + width, other.x + other.width);
29         int y1 = Math.min(y, other.y);
30         int y2 = Math.max(y + height, other.y + other.height);
31         return new Rectangle(x1, y1, x2 - x1, y2 - y1);
32     }
33
34     /** {@inheritDoc} */
35     public String toString ()
36     {
37         return getClass().getName() + "[x=" + x + ", y=" + y +
38             ", width=" + width + ", height=" + height + "]";
39     }
40 }