Rectangle2 implements Cloneable, Savable, Externalizable, ReadOnlyRectangle2, Poolable { public Rectangle2 intersect(final ReadOnlyRectangle2 other, final Rectangle2 store) { Rectangle2 rVal = store; if (rVal == null) { rVal = new Rectangle2(); } final int x1 = Math.max(getX(), other.getX()); final int y1 = Math.max(getY(), other.getY()); final int x2 = Math.min(getX() + getWidth(), other.getX() + other.getWidth()); final int y2 = Math.min(getY() + getHeight(), other.getY() + other.getHeight()); rVal.set(x1, y1, x2 - x1, y2 - y1); return rVal; } Rectangle2();  Rectangle2(final int x, final int y, final int width, final int height);  Rectangle2(final ReadOnlyRectangle2 source); @Override int getX(); void setX(final int x); @Override int getY(); void setY(final int y); @Override int getWidth(); void setWidth(final int width); @Override int getHeight(); void setHeight(final int height); Rectangle2 set(final int x, final int y, final int width, final int height); Rectangle2 set(final ReadOnlyRectangle2 rect); Rectangle2 intersect(final ReadOnlyRectangle2 other, final Rectangle2 store); static Rectangle2 intersect(final ReadOnlyRectangle2 src1, final ReadOnlyRectangle2 src2,
      final Rectangle2 store); @Override String toString(); @Override int hashCode(); @Override boolean equals(final Object o); @Override Rectangle2 clone(); @Override void write(final OutputCapsule capsule); @Override void read(final InputCapsule capsule); @Override Class<? extends Rectangle2> getClassTag(); @Override void readExternal(final ObjectInput in); @Override void writeExternal(final ObjectOutput out); final static Rectangle2 fetchTempInstance(); final static void releaseTempInstance(final Rectangle2 rectangle);  }
@Test public void testIntersect() { final Rectangle2 rect1 = new Rectangle2(0, 0, 10, 10); final Rectangle2 rect2 = new Rectangle2(5, 5, 10, 10); Rectangle2 intersection = rect1.intersect(rect2, Rectangle2.fetchTempInstance()); assertTrue(5 == intersection.getX()); assertTrue(5 == intersection.getY()); assertTrue(5 == intersection.getWidth()); assertTrue(5 == intersection.getHeight()); Rectangle2.releaseTempInstance(intersection); assertNotNull(rect1.intersect(rect2, null)); intersection = Rectangle2.intersect(rect1, rect2, Rectangle2.fetchTempInstance()); assertTrue(5 == intersection.getX()); assertTrue(5 == intersection.getY()); assertTrue(5 == intersection.getWidth()); assertTrue(5 == intersection.getHeight()); Rectangle2.releaseTempInstance(intersection); assertNotNull(Rectangle2.intersect(rect1, rect2, null)); }