Rectangle implements Cloneable, Serializable { public Rectangle getIntersection(Rectangle rect) { Rectangle result = null; float llx = Math.max(x, rect.x); float lly = Math.max(y, rect.y); float urx = Math.min(getRight(), rect.getRight()); float ury = Math.min(getTop(), rect.getTop()); float width = urx - llx; if (Math.abs(width) < EPS) { width = 0; } float height = ury - lly; if (Math.abs(height) < EPS) { height = 0; } if (Float.compare(width, 0) >= 0 && Float.compare(height, 0) >= 0) { if (Float.compare(width, 0) < 0) width = 0; if (Float.compare(height, 0) < 0) height = 0; result = new Rectangle(llx, lly, width, height); } return result; } Rectangle(float x, float y, float width, float height);  Rectangle(float width, float height);  Rectangle(Rectangle rect); static Rectangle getCommonRectangle(Rectangle... rectangles); static Rectangle getRectangleOnRotatedPage(Rectangle rect, PdfPage page); static Rectangle calculateBBox(List<Point> points); Point[] toPointsArray(); Rectangle getIntersection(Rectangle rect); boolean contains(Rectangle rect); boolean overlaps(final Rectangle rect); boolean overlaps(final Rectangle rect, final float epsilon); Rectangle setBbox(float llx, float lly, float urx, float ury); float getX(); Rectangle setX(float x); float getY(); Rectangle setY(float y); float getWidth(); Rectangle setWidth(float width); float getHeight(); Rectangle setHeight(float height); Rectangle increaseHeight(float extra); Rectangle decreaseHeight(float extra); Rectangle increaseWidth(float extra); Rectangle decreaseWidth(float extra); float getLeft(); float getRight(); float getTop(); float getBottom(); Rectangle moveDown(float move); Rectangle moveUp(float move); Rectangle moveRight(float move); Rectangle moveLeft(float move); Rectangle applyMargins(float topIndent, float rightIndent, float bottomIndent, float leftIndent, boolean reverse); boolean intersectsLine(float x1, float y1, float x2, float y2); @Override String toString(); @Override Rectangle clone(); boolean equalsWithEpsilon(Rectangle that); boolean equalsWithEpsilon(Rectangle that, float eps); static List<Rectangle> createBoundingRectanglesFromQuadPoint(PdfArray quadPoints); static Rectangle createBoundingRectangleFromQuadPoint(PdfArray quadPoints);  }
@Test public void getIntersectionTest02() { Rectangle main, second, actual; boolean noIntersection; main = new Rectangle(2, 2, 8, 8); second = new Rectangle(4, 12, 4, 4); actual = main.getIntersection(second); noIntersection = actual == null; second = new Rectangle(12, 4, 4, 4); actual = main.getIntersection(second); noIntersection = noIntersection && ((actual) == null); second = new Rectangle(4, -8, 4, 4); actual = main.getIntersection(second); noIntersection = noIntersection && ((actual) == null); second = new Rectangle(-8, 4, 4, 4); actual = main.getIntersection(second); noIntersection = noIntersection && ((actual) == null); Assert.assertTrue(noIntersection); }