Java Rectangle Intersect intersects(Rectangle2D r, Object o)

Here you can find the source of intersects(Rectangle2D r, Object o)

Description

Check for intersection between a rectangle and another (presumably) geometric object.

License

Open Source License

Declaration

public static boolean intersects(Rectangle2D r, Object o) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.awt.Shape;

import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;

public class Main {
    /**Check for intersection between a rectangle and another (presumably) geometric object.**/
    public static boolean intersects(Rectangle2D r, Object o) {
        if (o instanceof Point2D) {
            return intersects(r, (Point2D) o);
        }/*from   w  w  w  .j  a  va2 s.c o m*/
        if (o instanceof Shape) {
            return intersects(r, (Shape) o);
        }
        throw new IllegalArgumentException("Object passed must be either a shape or a point.");
    }

    public static boolean intersects(Rectangle2D r, Point2D p) {
        return r.contains(p);
    }

    public static boolean intersects(Rectangle2D r, Shape s) {
        return s.intersects(r);
    }
}

Related

  1. intersects(final Rectangle2D a, final Rectangle2D b)
  2. intersects(float cx, float cy, float radius, float left, float top, float right, float bottom)
  3. intersects(Point p1, Point p2, Rectangle rect)
  4. intersects(Rectangle aRectangle, Line2D aLine)
  5. intersects(Rectangle rect1, Rectangle rect2, boolean vertical)
  6. intersects(Rectangle2D rect1, Rectangle2D rect2)
  7. intersectsOutline(Rectangle2D r, Shape s)
  8. intersectsRectangle(final double checkMinX, final double checkMinY, final double checkMaxX, final double checkMaxY, final double againstMinX, final double againstMinY, final double againstMaxX, final double againstMaxY)
  9. intersectsRectangle(final double checkMinX, final double checkMinY, final double checkMaxX, final double checkMaxY, final double againstMinX, final double againstMinY, final double againstMaxX, final double againstMaxY)