| 123 | } |
| 124 | |
| 125 | public Rectangle intersection(Rectangle r, Rectangle dest) { |
| 126 | int tx1 = this.x; |
| 127 | int ty1 = this.y; |
| 128 | int rx1 = r.getX(); |
| 129 | int ry1 = r.getY(); |
| 130 | long tx2 = (long)tx1; |
| 131 | tx2 += (long)this.width; |
| 132 | long ty2 = (long)ty1; |
| 133 | ty2 += (long)this.height; |
| 134 | long rx2 = (long)rx1; |
| 135 | rx2 += (long)r.getWidth(); |
| 136 | long ry2 = (long)ry1; |
| 137 | ry2 += (long)r.getHeight(); |
| 138 | if (tx1 < rx1) { |
| 139 | tx1 = rx1; |
| 140 | } |
| 141 | |
| 142 | if (ty1 < ry1) { |
| 143 | ty1 = ry1; |
| 144 | } |
| 145 | |
| 146 | if (tx2 > rx2) { |
| 147 | tx2 = rx2; |
| 148 | } |
| 149 | |
| 150 | if (ty2 > ry2) { |
| 151 | ty2 = ry2; |
| 152 | } |
| 153 | |
| 154 | tx2 -= (long)tx1; |
| 155 | ty2 -= (long)ty1; |
| 156 | if (tx2 < -2147483648L) { |
| 157 | tx2 = -2147483648L; |
| 158 | } |
| 159 | |
| 160 | if (ty2 < -2147483648L) { |
| 161 | ty2 = -2147483648L; |
| 162 | } |
| 163 | |
| 164 | if (dest == null) { |
| 165 | dest = new Rectangle(tx1, ty1, (int)tx2, (int)ty2); |
| 166 | } else { |
| 167 | dest.setBounds(tx1, ty1, (int)tx2, (int)ty2); |
| 168 | } |
| 169 | |
| 170 | return dest; |
| 171 | } |
| 172 | |
| 173 | public void add(int newx, int newy) { |
| 174 | int x1 = Math.min(this.x, newx); |