@Test public void testIntersects() throws Exception { final Region r1 = new Region(0, 0, 20, 20); final Region r2 = new Region(5, 5, 10, 10); Assert.assertTrue(r1.intersects(r2)); Assert.assertTrue(r2.intersects(r1)); Assert.assertEquals(new Region(5, 5, 10, 10), r2.intersection(r1)); final Region r3 = new Region(0, 0, 20, 20); Assert.assertEquals(new Region(5, 5, 10, 10), r3.intersection(r2)); }
public boolean intersects(final Region r) { int tw = width; int th = height; int rw = r.width; int rh = r.height; if (rw <= 0 || rh <= 0 || tw <= 0 || th <= 0) { return false; } final int tx = x; final int ty = y; final int rx = r.x; final int ry = r.y; rw += rx; rh += ry; tw += tx; th += ty; return (rw < rx || rw > tx) && (rh < ry || rh > ty) && (tw < tx || tw > rx) && (th < ty || th > ry); }
Region { public boolean intersects(final Region r) { int tw = width; int th = height; int rw = r.width; int rh = r.height; if (rw <= 0 || rh <= 0 || tw <= 0 || th <= 0) { return false; } final int tx = x; final int ty = y; final int rx = r.x; final int ry = r.y; rw += rx; rh += ry; tw += tx; th += ty; return (rw < rx || rw > tx) && (rh < ry || rh > ty) && (tw < tx || tw > rx) && (th < ty || th > ry); } }
Region { public boolean intersects(final Region r) { int tw = width; int th = height; int rw = r.width; int rh = r.height; if (rw <= 0 || rh <= 0 || tw <= 0 || th <= 0) { return false; } final int tx = x; final int ty = y; final int rx = r.x; final int ry = r.y; rw += rx; rh += ry; tw += tx; th += ty; return (rw < rx || rw > tx) && (rh < ry || rh > ty) && (tw < tx || tw > rx) && (th < ty || th > ry); } Region(final int x, final int y, final int width, final int height);  Region(final int level, final int x, final int y, final int width, final int height); }
Region { public boolean intersects(final Region r) { int tw = width; int th = height; int rw = r.width; int rh = r.height; if (rw <= 0 || rh <= 0 || tw <= 0 || th <= 0) { return false; } final int tx = x; final int ty = y; final int rx = r.x; final int ry = r.y; rw += rx; rh += ry; tw += tx; th += ty; return (rw < rx || rw > tx) && (rh < ry || rh > ty) && (tw < tx || tw > rx) && (th < ty || th > ry); } Region(final int x, final int y, final int width, final int height);  Region(final int level, final int x, final int y, final int width, final int height); int getX(); int getY(); void setX(final int x); void setY(final int y); void setWidth(final int width); void setHeight(final int height); int getLeft(); int getRight(); int getTop(); int getBottom(); int getWidth(); int getHeight(); boolean intersects(final Region r); Region intersection(final Region r); int getLevel(); @Override int hashCode(); @Override boolean equals(final Object obj); @Override String toString(); }
Region { public boolean intersects(final Region r) { int tw = width; int th = height; int rw = r.width; int rh = r.height; if (rw <= 0 || rh <= 0 || tw <= 0 || th <= 0) { return false; } final int tx = x; final int ty = y; final int rx = r.x; final int ry = r.y; rw += rx; rh += ry; tw += tx; th += ty; return (rw < rx || rw > tx) && (rh < ry || rh > ty) && (tw < tx || tw > rx) && (th < ty || th > ry); } Region(final int x, final int y, final int width, final int height);  Region(final int level, final int x, final int y, final int width, final int height); int getX(); int getY(); void setX(final int x); void setY(final int y); void setWidth(final int width); void setHeight(final int height); int getLeft(); int getRight(); int getTop(); int getBottom(); int getWidth(); int getHeight(); boolean intersects(final Region r); Region intersection(final Region r); int getLevel(); @Override int hashCode(); @Override boolean equals(final Object obj); @Override String toString();  }