Files
CodeChickenCore/codechicken/lib/vec/Rectangle4i.java
T
Chicken-Bomes 8a777b265e Add intersects method to Rectangle4i
Added compare methods to MathHelper
2013-12-11 17:34:04 +10:00

49 lines
910 B
Java

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;
}
public boolean intersects(Rectangle4i r)
{
return x <= r.x+r.w && r.x <= x+w &&
y <= r.y+r.h && r.y <= y+h;
}
}