2013-07-16 17:58:02 +10:00
|
|
|
package codechicken.lib.vec;
|
|
|
|
|
|
|
|
|
|
public class Rectangle4i
|
|
|
|
|
{
|
|
|
|
|
public int x;
|
|
|
|
|
public int y;
|
|
|
|
|
public int w;
|
|
|
|
|
public int h;
|
|
|
|
|
|
|
|
|
|
public Rectangle4i()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Rectangle4i(int x, int y, int w, int h)
|
|
|
|
|
{
|
|
|
|
|
this.x = x;
|
|
|
|
|
this.y = y;
|
|
|
|
|
this.w = w;
|
|
|
|
|
this.h = h;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Rectangle4i offset(int dx, int dy)
|
|
|
|
|
{
|
|
|
|
|
x+=dx;
|
|
|
|
|
y+=dy;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Rectangle4i with(int px, int py)
|
|
|
|
|
{
|
|
|
|
|
if(x > px) x = px;
|
|
|
|
|
if(y > py) y = py;
|
|
|
|
|
if(x + w <= px) w = px-x+1;
|
|
|
|
|
if(y + h <= py) h = py-y+1;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean contains(int px, int py)
|
|
|
|
|
{
|
|
|
|
|
return x <= px && px < x+w && y <= py && py < y+h;
|
|
|
|
|
}
|
2013-12-11 17:34:04 +10:00
|
|
|
|
|
|
|
|
public boolean intersects(Rectangle4i r)
|
|
|
|
|
{
|
|
|
|
|
return x <= r.x+r.w && r.x <= x+w &&
|
|
|
|
|
y <= r.y+r.h && r.y <= y+h;
|
|
|
|
|
}
|
2013-07-16 17:58:02 +10:00
|
|
|
}
|